-
Notifications
You must be signed in to change notification settings - Fork 202
/
CMakeLists.txt
312 lines (266 loc) · 10.1 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
cmake_minimum_required(VERSION 3.19.0)
project(xca
DESCRIPTION "X Certificate and Key management"
HOMEPAGE_URL http://xca.hohnstaedt.de
LANGUAGES CXX
)
file(READ VERSION.txt ver)
string(REGEX MATCH "([0-9\.]*)" _ ${ver})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
cmake_host_system_information(RESULT OS_DATA_LIST QUERY
OS_NAME OS_RELEASE OS_VERSION OS_PLATFORM)
list(JOIN OS_DATA_LIST " -- " OS_DATA)
message(STATUS ${OS_DATA})
string(REGEX MATCH "([0-9]+\.[0-9]+\.[0-9]+)" OSX_SDK_MINIMUM
${CMAKE_OSX_DEPLOYMENT_TARGET} ".0.0.0")
include(GNUInstallDirs)
include(CTest)
##### Git command to tweak the version and commit hash
include(cmake/git_version.cmake)
file(WRITE ${PROJECT_BINARY_DIR}/PKGVERSION.txt ${PROJECT_VERSION}\n)
##### Build specifications
find_program(CCACHE_EXECUTABLE ccache)
mark_as_advanced(CCACHE_EXECUTABLE)
if(CCACHE_EXECUTABLE)
if(NOT DEFINED CMAKE_CXX_COMPILER_LAUNCHER AND NOT
CMAKE_CXX_COMPILER MATCHES ".*/ccache")
message(STATUS "Enabling ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "")
endif()
endif()
set(ADDRESS_SANITIZER OFF CACHE BOOL "Enable Address sanitizing")
set(APPSTORE_COMPLIANT OFF CACHE BOOL "Create an Appstore compliant, sanboxed app")
set(PROVISIONPROFILE "" CACHE STRING "Location of the embedded.provisionprofile")
if (APPSTORE_COMPLIANT)
set(APPLE_DEVELOPER_CERT "3rd Party Mac Developer Application")
set(APPSTORE -appstore-compliant)
else()
set(APPLE_DEVELOPER_CERT "Developer ID Application")
endif()
if(APPLE)
execute_process(COMMAND security find-identity -v
ERROR_QUIET OUTPUT_VARIABLE IDCHECK)
string(FIND "${IDCHECK}" "${APPLE_DEVELOPER_CERT}" matchres)
if(matchres EQUAL -1)
unset(APPLE_DEVELOPER_CERT)
endif()
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/ui")
set(CMAKE_AUTOUIC ON)
add_compile_definitions(OPENSSL_SUPPRESS_DEPRECATED QT_MESSAGELOGCONTEXT)
add_compile_options(-Wall -Wextra -Wno-unknown-pragmas)
if (ADDRESS_SANITIZER)
add_compile_options(-fsanitize=address -O1 -fno-omit-frame-pointer -g)
set(ASAN_LIB -fsanitize=address)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES Clang|GNU)
add_compile_options(-fmacro-prefix-map=${PROJECT_SOURCE_DIR}=.)
endif()
file(GLOB UI_FILES ${CMAKE_AUTOUIC_SEARCH_PATHS}/*.ui)
configure_file(local.h.in local.h)
##### Libraries and executables
add_library(xcalib STATIC)
add_executable(${CMAKE_PROJECT_NAME} img/imgres.qrc lib/main.cpp
${UI_FILES} ${PROJECT_BINARY_DIR}/local.h)
add_executable(xcadoc ${PROJECT_BINARY_DIR}/local.h)
add_executable(xcaexport ${PROJECT_BINARY_DIR}/local.h)
include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR})
if (NOT OPENSSL_VERSION)
# Educated guess
set(OPENSSL_VERSION 3.0.0)
endif()
if (APPLE)
execute_process(COMMAND brew --prefix OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE BREW_PREFIX ERROR_QUIET)
# Preset the default brew paths....
if (NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH ${BREW_PREFIX}/opt/qt@6/ ${BREW_PREFIX}/opt/openssl@3)
endif()
elseif(WIN32)
if (NOT CMAKE_PREFIX_PATH)
set(CMAKE_PREFIX_PATH $ENV{UserProfile} $ENV{PROGRAMFILES}/OpenSSL-Win64)
endif()
if (OPENSSL_VERSION VERSION_GREATER_EQUAL 3.0.0)
set(OPENSSL_LIBRARY_MAJOR "3")
else()
set(OPENSSL_LIBRARY_MAJOR "1_1")
endif()
file(TO_CMAKE_PATH $ENV{WINDIR}/system32 SYSTEM32)
endif()
set(QTFIXEDVERSION Qt6 Qt5 CACHE STRING "Force a specific QT version 'Qt5' or 'Qt6'")
find_package(OpenSSL REQUIRED)
find_package(QT NAMES ${QTFIXEDVERSION} REQUIRED COMPONENTS Core)
set(QT Qt${QT_VERSION_MAJOR})
find_package(${QT} REQUIRED COMPONENTS Core Widgets Sql Help LinguistTools)
find_package(${QT} QUIET COMPONENTS Test)
message(STATUS "Using ${QT} with version ${QT_VERSION}")
get_target_property(qmake_executable ${QT}::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${qmake_executable}" DIRECTORY)
if (NOT OPENSSL_ROOT_DIR)
get_filename_component(OPENSSL_ROOT_DIR ${OPENSSL_INCLUDE_DIR} DIRECTORY)
endif()
file(TO_CMAKE_PATH ${OPENSSL_ROOT_DIR} OPENSSL_ROOT_DIR)
target_link_libraries(xcalib
OpenSSL::Crypto
${QT}::Widgets ${QT}::Core ${QT}::Sql ${QT}::Help
${ASAN_LIB}
)
target_link_libraries(xcadoc
OpenSSL::Crypto ${QT}::Core ${ASAN_LIB}
)
target_link_libraries(xcaexport ${QT}::Core ${ASAN_LIB})
target_link_libraries(${CMAKE_PROJECT_NAME} ${ASAN_LIB} xcalib)
if (APPLE)
find_library(IOKIT_LIBRARY IOKit)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
target_link_libraries(${CMAKE_PROJECT_NAME}
${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY}
)
set(CMAKE_MACOSX_BUNDLE ON)
# Avoid bin/ sub-directory in DMG
set(RUNTIME_DEST .)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
elseif(WIN32)
set(RUNTIME_DEST ${CMAKE_PROJECT_NAME}-portable-${PROJECT_VERSION})
else()
set(RUNTIME_DEST ${CMAKE_INSTALL_BINDIR})
endif()
macro(guid content)
string(
UUID GUID NAMESPACE f243d4ea-d51d-42fc-a3c0-4eb186c55d34
NAME ${content} TYPE SHA1
)
endmacro()
macro(WixFile filename content)
file(WRITE ${filename} "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Wix xmlns=\"http://schemas.microsoft.com/wix/2006/wi\">\n<Fragment>\n"
${content}
"\n</Fragment>\n</Wix>")
endmacro()
add_custom_target(tests)
##### Sub directories
add_subdirectory(lib)
add_subdirectory(widgets)
include(lang/CMakeLists.txt)
include(misc/CMakeLists.txt)
include(doc/CMakeLists.txt)
include(img/CMakeLists.txt)
include(test/CMakeLists.txt)
install(TARGETS ${CMAKE_PROJECT_NAME}
RESOURCE DESTINATION Resources
BUNDLE DESTINATION .
RUNTIME DESTINATION ${RUNTIME_DEST}
)
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")
###############################################
##### Host specific settings
if(APPLE)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE TRUE
XCODE_ATTRIBUTE_INSTALL_PATH /Applications
XCODE_ATTRIBUTE_SKIP_INSTALL No
RESOURCE "${APP_RESOURCES}"
)
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS ${_qt_bin_dir})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${MACDEPLOYQT_EXECUTABLE} $<TARGET_FILE_DIR:${PROJECT_NAME}>/../..
-always-overwrite ${APPSTORE}
COMMENT "Running macdeployqt..."
)
if (OPENSSL_VERSION VERSION_GREATER_EQUAL 3.0.0)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cmake -E copy ${OPENSSL_ROOT_DIR}/lib/ossl-modules/legacy.dylib
$<TARGET_FILE_DIR:${PROJECT_NAME}>/../PlugIns/
COMMENT "Install OpenSSL legacy provider"
)
endif()
if (PROVISIONPROFILE)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND cmake -E copy ${PROVISIONPROFILE}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/../embedded.provisionprofile)
endif()
if (DEFINED APPLE_DEVELOPER_CERT)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND codesign --deep --signature-size=96000
--options=runtime --timestamp
--entitlements ${PROJECT_SOURCE_DIR}/misc/entitlement${APPSTORE}.plist
--force -s ${APPLE_DEVELOPER_CERT}
$<TARGET_FILE_DIR:${PROJECT_NAME}>/../..
COMMENT "Running codesign for ${APPLE_DEVELOPER_CERT} ..."
DEPENDS ${PROJECT_SOURCE_DIR}/misc/entitlement${APPSTORE}.plist
)
endif()
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_GENERATOR "DragNDrop") #;productbuild")
elseif(WIN32)
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS ${_qt_bin_dir})
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:${PROJECT_NAME}>
--dir ${CMAKE_BINARY_DIR} --compiler-runtime --no-translations
COMMENT "Running windeployqt on ${CMAKE_PROJECT_NAME} ..."
)
add_custom_command(TARGET xcadoc POST_BUILD
COMMAND ${WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:xcadoc>
--dir ${CMAKE_BINARY_DIR} --no-translations
COMMENT "Running windeployqt on xcadoc ..."
)
add_custom_command(TARGET xcaexport POST_BUILD
COMMAND ${WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:xcaexport>
--dir ${CMAKE_BINARY_DIR} --no-translations
COMMENT "Running windeployqt on xcaexport ..."
)
set(QT_USE_QTMAIN TRUE)
set(CPACK_GENERATOR WIX)
set(CPACK_PACKAGE_VENDOR "Christian Hohnstädt")
set(CPACK_WIX_TEMPLATE "${PROJECT_SOURCE_DIR}/misc/xca.wxs")
set(CPACK_WIX_UPGRADE_GUID "23fdacfe-3ef8-45b4-81e8-b0c90244c217")
set(CPACK_WIX_UI_BANNER "${PROJECT_SOURCE_DIR}/img/banner.bmp")
set(CPACK_WIX_UI_DIALOG "${PROJECT_SOURCE_DIR}/img/dialog.bmp")
set(CPACK_WIX_LICENSE_RTF "${PROJECT_SOURCE_DIR}/misc/copyright.rtf")
set(CPACK_WIX_EXTRA_SOURCES
${CMAKE_BINARY_DIR}/language.wxs
${CMAKE_BINARY_DIR}/doc/documentation.wxs
${CMAKE_BINARY_DIR}/misc/misc.wxs
${CMAKE_BINARY_DIR}/misc/dynamic.wxs
)
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -mwindows -MD)
install(DIRECTORY
${CMAKE_BINARY_DIR}/platforms
${CMAKE_BINARY_DIR}/sqldrivers
${CMAKE_BINARY_DIR}/styles
DESTINATION ${RUNTIME_DEST}
)
install(FILES ${CMAKE_BINARY_DIR}/${QT}Core.dll
${CMAKE_BINARY_DIR}/${QT}Gui.dll
${CMAKE_BINARY_DIR}/${QT}Help.dll
${CMAKE_BINARY_DIR}/${QT}Sql.dll
${CMAKE_BINARY_DIR}/${QT}Widgets.dll
${CMAKE_BINARY_DIR}/libgcc_s_seh-1.dll
${CMAKE_BINARY_DIR}/libstdc++-6.dll
${CMAKE_BINARY_DIR}/libwinpthread-1.dll
${SYSTEM32}/vcruntime140.dll
${OPENSSL_ROOT_DIR}/bin/libcrypto-${OPENSSL_LIBRARY_MAJOR}-x64.dll
DESTINATION ${RUNTIME_DEST}
)
if (OPENSSL_VERSION VERSION_GREATER_EQUAL 3.0.0)
install(FILES ${OPENSSL_ROOT_DIR}/lib/ossl-modules/legacy.dll
DESTINATION ${RUNTIME_DEST})
endif()
install(CODE "execute_process(COMMAND cmake -E chdir \${CMAKE_INSTALL_PREFIX} tar cvf ${RUNTIME_DEST}.zip --format=zip -- ${RUNTIME_DEST})")
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
else()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr/local CACHE PATH
"Default installation directory" FORCE)
endif()
message(STATUS "PREFIX: " ${CMAKE_INSTALL_PREFIX})
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES \\.git/ build/ ".*~$")
set(CPACK_VERBATIM_VARIABLES YES)
endif()
include(CPack)