-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
338 lines (284 loc) · 9.34 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#####################################################################
# This file is part of the IC reverse engineering tool Degate.
#
# Copyright 2008, 2009, 2010 by Martin Schobert
# Copyright 2019-2020 Dorian Bachelot
#
# Degate is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# Degate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with degate. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################
cmake_minimum_required(VERSION 3.12.0)
#
# Custom triplets used by Degate (e.g. this allow mixing dynamic/static linking for dependencies)
#
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/etc/vcpkg-triplets")
#
# Use specific triplet for windows, that'll use static build for everything except qt
#
if (WIN32)
set(VCPKG_DEFAULT_TRIPLET "x64-windows-degate")
set(VCPKG_TARGET_TRIPLET "x64-windows-degate" CACHE STRING "target triplet" FORCE)
endif()
#
# Use vcpkg
#
set(VCPKG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg)
set(CMAKE_TOOLCHAIN_FILE ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
#
# Configure tests
#
option(BUILD_TESTS "Build tests" OFF)
if(BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
endif()
#
# Configure vcpkg-qt
#
option(VCPKG_QT "Use vcpkg's Qt dependency. WARNING: this will not provide OpenGL software renderer fallback for Windows (mesa llvmpipe)" OFF)
if(VCPKG_QT)
message(STATUS "Using vcpkg's Qt dependency")
list(APPEND VCPKG_MANIFEST_FEATURES "vcpkg-qt")
endif()
#
# Tell vcpkg to export dll to build folder (windows only)
#
if (WIN32)
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
endif()
project(Degate)
#
# Use ccache if available
#
set(DISABLE_CCACHE OFF CACHE BOOL "Do not use ccache even if it is available")
if (NOT DISABLE_CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
if (CCACHE_EXECUTABLE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_EXECUTABLE})
endif()
endif()
#
# Cpp version
#
set(CMAKE_CXX_STANDARD 11)
message(STATUS "Using compiler: ${CMAKE_CXX_COMPILER}")
set(CMAKE_VERBOSE_MAKEFILE true)
#
# Set flags
#
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -fno-inline")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
add_definitions(-DBOOST_NO_CXX11_SCOPED_ENUMS)
#
# Property for folders
#
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#
# Export compile_commands.json file
#
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
############################################################################
############################ Dependencies ##################################
############################################################################
#
# Turn on automatic invocation of the MOC, UIC & RCC
#
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
#
# Group Qt files
#
source_group("qt" REGULAR_EXPRESSION "(translations.qrc|style.qrc|resources.qrc)")
source_group("qt\\moc" REGULAR_EXPRESSION "(moc.*.cpp|qrc_resources.cpp|Degate.version|qrc_.*.cpp)")
source_group("qt\\languages" REGULAR_EXPRESSION "(.*.qm|degate_.*.ts)")
source_group("res" REGULAR_EXPRESSION "(resource.rc)")
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER "Moc")
set_property(GLOBAL PROPERTY AUTOGEN_SOURCE_GROUP "qt\\moc")
############# Boost
if (NOT DEFINED Boost_USE_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif()
message(STATUS "Boost static libs: ${Boost_USE_STATIC_LIBS}")
if (NOT DEFINED Boost_USE_MULTITHREADED)
set(Boost_USE_MULTITHREADED ON)
endif()
message(STATUS "Boost multithreaded libs: ${Boost_USE_MULTITHREADED}")
find_package(Boost COMPONENTS filesystem system thread REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${Boost_LIBRARIES})
message(STATUS "Boost installation dir: ${Boost_DIR}")
############# Qt
find_package(Qt6 COMPONENTS Core Widgets Gui Xml OpenGL OpenGLWidgets Concurrent LinguistTools CONFIG REQUIRED)
set(LIBS ${LIBS} Qt6::Widgets Qt6::Gui Qt6::Core Qt6::Xml Qt6::OpenGL Qt6::OpenGLWidgets Qt6::Concurrent)
# qt_standard_project_setup()
message(STATUS "Qt installation dir: ${Qt6_DIR}")
############################################################################
################################ Main ######################################
############################################################################
#
# Configuration
#
if (CMAKE_SIZEOF_VOID_P MATCHES 8) # if 64-bits
message(STATUS "64 bits configuration")
set(CONFIGURATION "x64")
else() # if 32-bits
message(STATUS "32 bits configuration")
set(CONFIGURATION "x86")
endif()
#
# Version
#
include(${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake/ConfigureFiles.cmake)
#
# Version command
#
add_custom_command(
OUTPUT "Degate version" # Not an error, we need a dummy output to force command execution for every build
COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR="${PROJECT_SOURCE_DIR}"
-DCMAKE_SYSTEM_NAME="${CMAKE_SYSTEM_NAME}"
-DCONFIGURATION="${CONFIGURATION}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake/ConfigureFiles.cmake"
DEPENDS "${PROJECT_SOURCE_DIR}/VERSION"
)
#
# The source files
#
file(GLOB_RECURSE SRC_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" LIST_DIRECTORIES false
"src/*.cc"
"src/*.cpp"
"src/*.h"
"src/*.hpp"
)
#
# Translation
#
SET(TRANSLATION_FILES
degate_en.ts
degate_fr.ts
degate_de.ts
degate_ru.ts
degate_es.ts
degate_it.ts
degate_ko.ts
degate_zhcn.ts
)
list(TRANSFORM TRANSLATION_FILES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/res/languages/)
# Redefine "qt6_create_translation" function because of a bug (it originally parse all boost files, and make the build VERY slow)
include(${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake/Qt6LinguistToolsMacros.cmake)
# TODO: Figure out why this is needed.
if (WIN32)
qt6_create_translation(QM_FILES ${SRC_FILES} ${TRANSLATION_FILES})
else ()
qt6_create_translation(QM_FILES ${SRC_FILES} ${TRANSLATION_FILES} OPTIONS "-no-obsolete")
endif ()
configure_file(res/languages/translations.qrc ${CMAKE_BINARY_DIR} COPYONLY)
#
# Include directories
#
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
#
# Defines groups (to respect folders hierarchy)
#
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "src" FILES ${SRC_FILES})
#
# Remove Main.cpp file
#
list(REMOVE_ITEM SRC_FILES "src/Main.cc")
#
# MacOS set icns icon.
#
set(MACOSX_BUNDLE_ICON_FILE "degate.icns")
#
# MacOS copy icns icon.
#
if (APPLE)
file(COPY ${PROJECT_SOURCE_DIR}/etc/icons/logo/degate.icns DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/out/bin/Degate.app/Contents/Resources/)
endif ()
#
# Link DegateCore
#
qt_add_library(DegateCore STATIC ${SRC_FILES} res/resources.qrc res/qdarkstyle/style.qrc ${CMAKE_BINARY_DIR}/translations.qrc ${TRANSLATION_FILES} ${QM_FILES} "Degate version")
target_link_libraries(DegateCore PRIVATE ${LIBS})
#
# Link main (Degate)
#
qt_add_executable(Degate "src/Main.cc" res/resources.qrc res/qdarkstyle/style.qrc ${CMAKE_BINARY_DIR}/translations.qrc ${TRANSLATION_FILES} ${QM_FILES} "res/resource.rc")
target_link_libraries(Degate PRIVATE ${LIBS} DegateCore)
#
# Activate bundle for MacOS.
#
set_target_properties(Degate PROPERTIES MACOSX_BUNDLE TRUE)
#
# Installation specifications
#
install (TARGETS Degate DESTINATION out/bin)
#
# Automatic Qt deploy (doesn't deploy everything...)
#
# qt_generate_deploy_app_script(
# TARGET Degate
# OUTPUT_SCRIPT deploy_script
# NO_UNSUPPORTED_PLATFORM_ERROR
# )
# install(SCRIPT ${deploy_script})
#
# Output specifications
#
set_target_properties(Degate
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "out/lib"
LIBRARY_OUTPUT_DIRECTORY "out/lib"
RUNTIME_OUTPUT_DIRECTORY "out/bin"
)
set_target_properties(DegateCore
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "out/lib"
LIBRARY_OUTPUT_DIRECTORY "out/lib"
RUNTIME_OUTPUT_DIRECTORY "out/bin"
)
#
# No console on Windows when release.
#
if(MSVC) # If using the VS compiler...
set_target_properties(Degate PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Degate)
endif()
#
# Tests
#
include(CTest)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
############################################################################
################################ Doc #######################################
############################################################################
option(BUILD_DOCS "Build docs" OFF)
if(BUILD_DOCS)
find_package(Doxygen QUIET)
if(DOXYGEN_FOUND)
message(STATUS "Doxygen found")
add_custom_target(Documentation ALL
COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/doc/config/DoxyFile"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating documentation with Doxygen."
SOURCES "Degate version")
else()
message(STATUS "Doxygen not found")
endif()
endif()