-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
512 lines (423 loc) · 11.4 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# policies first
if(COMMAND cmake_policy)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0020 NEW)
cmake_policy(SET CMP0003 NEW)
endif()
# use ccache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message("== Using CCache ! ==")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}")
endif()
# default configuration
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Qt
)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
#############
## STARTUP ##
#############
# pre-startup
cmake_minimum_required(VERSION 3.10.2)
message(STATUS "Using toolchain file: [${CMAKE_TOOLCHAIN_FILE}].")
# project setup
project(RPGRPZ
VERSION 1.0.28
DESCRIPTION "Simple Tabletop RPG experience"
HOMEPAGE_URL "https://github.com/Amphaal/rpgrpz"
LANGUAGES CXX
)
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) #lowered project name
########################
## VERSION.H HANDLING ##
########################
SET(APP_PUBLISHER "LVWL")
SET(APP_PATCHNOTE_URL "https://github.com/Amphaal/rpgrpz/releases")
SET(SENTRY_ENDPOINT "https://[email protected]/5517405")
SET(APP_MAINTENANCETOOL_PATH "../maintenancetool")
# configure header with basic app informations
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/templates/_version.h
${CMAKE_CURRENT_SOURCE_DIR}/src/version.h
)
################################
## CPP Compiler Configuration ##
################################
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_C_STANDARD 11)
# Qt
include(XCQt)
SET(CMAKE_AUTOMOC ON)
SET(CMAKE_AUTORCC ON)
SET(CMAKE_AUTOUIC ON)
SET(CMAKE_INCLUDE_CURRENT_DIR ON) #for moc auto
# make sure _WIN32 preprocessor is used even while cross compiling
IF(MINGW)
add_compile_definitions(_WIN32)
endif()
#################################
## define bundle configuration ##
#################################
# define build type if any
IF(NOT DEFINED APP_BUNDLE_TYPE)
IF(CMAKE_SYSTEM_NAME STREQUAL "Windows")
SET(APP_BUNDLE_TYPE WIN32)
ELSEIF(APPLE)
SET(APP_BUNDLE_TYPE MACOSX_BUNDLE)
endif()
endif()
######################################
## define executables and libraries ##
######################################
# define app executable
add_executable(appExec ${APP_BUNDLE_TYPE})
set_target_properties(appExec PROPERTIES OUTPUT_NAME "${PROJECT_NAME}") #define executable name
target_compile_definitions(appExec PRIVATE $<$<CONFIG:Debug>:_DEBUG>) #define _DEBUG markup if in DEBUG config
# warnings for debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_options(appExec PRIVATE
-Wall
-Wextra
-Wpedantic
-Wno-unused-parameter
)
endif()
# optimise for release
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set_target_properties(appExec PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) #enable LTO
endif()
#################
## install app ##
#################
# app
SET(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "App")
install(TARGETS appExec
COMPONENT "App"
)
# spdlog
if(MINGW)
find_file(MINGW_SPDLOG libspdlog.dll REQUIRED)
install(FILES ${MINGW_SPDLOG}
TYPE BIN
COMPONENT "Runtime"
)
endif()
# runtime
if(MINGW)
find_file(MINGW_STDLIB libstdc++-6.dll REQUIRED)
find_file(MINGW_GCC_SEH libgcc_s_seh-1.dll REQUIRED)
find_file(MINGW_WINPTHREAD libwinpthread-1.dll REQUIRED)
install(
FILES
${MINGW_STDLIB}
${MINGW_GCC_SEH}
${MINGW_WINPTHREAD}
TYPE BIN
COMPONENT "Runtime"
)
list(APPEND PEUTIL_WHITELIST_EXTENSIONS
"libstdc++-6.dll"
"libgcc_s_seh-1.dll"
"libwinpthread-1.dll"
)
endif()
#########################
## ressources handling ##
#########################
# default QT ressources
target_sources(appExec PRIVATE "resources/resources.qrc")
IF(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(appExec PRIVATE "resources/icons/resources.rc") #add Windows ressources (icons)
ELSEIF(APPLE)
target_sources(appExec PRIVATE "resources/icons/app.icns") #add MacOS icons in output package
set_source_files_properties("resources/icons/app.icns"
PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
set_target_properties(appExec PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/templates/_Info.plist"
MACOSX_BUNDLE_ICON_FILE "app.icns"
)
endif()
####################################
# pkgConfig and find_library setup #
####################################
# fetch content handling
include(FetchContent)
# using pkgConfig, set PKG_CONFIG_EXECUTABLE if not found
find_package(PkgConfig REQUIRED)
###########
# OpenSSL #
###########
# find
find_package(OpenSSL REQUIRED)
# link
target_link_libraries(appExec PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
)
# install
if(MINGW)
find_file(MINGW_OPENSSL_SSL libssl-1_1-x64.dll REQUIRED)
find_file(MINGW_OPENSSL_CRYPTO libcrypto-1_1-x64.dll REQUIRED)
install(
FILES
${MINGW_OPENSSL_SSL}
${MINGW_OPENSSL_CRYPTO}
TYPE BIN
COMPONENT "OpenSSL"
)
endif()
########
# QT 5 #
########
find_package(Qt5 REQUIRED COMPONENTS
Core
Gui
Widgets
Network
Svg
OpenGL
LinguistTools
Multimedia
)
target_link_libraries(appExec PRIVATE
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Network
Qt5::Svg
Qt5::OpenGL
Qt5::Multimedia
)
# QT LIBRARIES COPY
include(DeployQt)
DeployQt(appExec)
#############
# snowflake #
#############
add_subdirectory(deps/snowflake)
target_link_libraries(appExec PRIVATE snowflake)
###########
# clipper #
###########
add_subdirectory(deps/clipper)
target_link_libraries(appExec PRIVATE clipper)
############################
# autoupdatercore (for Qt) #
############################
add_subdirectory(deps/autoupdatercore)
target_link_libraries(appExec PRIVATE autoupdatercore)
#################
# Sentry-native #
#################
SET(SENTRY_BUILD_SHARED_LIBS ON CACHE INTERNAL "")
add_subdirectory(deps/sentry-native EXCLUDE_FROM_ALL)
# get version
get_directory_property(SENTRY_NATIVE_PROJECT_VERSION
DIRECTORY deps/sentry-native
DEFINITION PROJECT_VERSION
)
# link
target_link_libraries(appExec PRIVATE sentry)
# track version into file
execute_process(
COMMAND printf "${CMAKE_PROJECT_VERSION}"
OUTPUT_FILE ${CMAKE_BINARY_DIR}/version
)
# install
install(FILES
$<TARGET_FILE:sentry>
TYPE BIN
COMPONENT "SentryNative"
)
# add crashpad_handler next to app, and to install process
set_target_properties(crashpad_handler PROPERTIES
RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:appExec>
)
install(TARGETS crashpad_handler
COMPONENT "SentryNative"
)
# generate pdb
IF(MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_link_options(appExec PRIVATE -Wl,-pdb=) # generate pdb files
target_compile_options(appExec PRIVATE -gcodeview) #use codeview for pdbs
# add .pdb to install
install(
FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/$<TARGET_FILE_BASE_NAME:appExec>.pdb
TYPE BIN
COMPONENT "App"
)
endif()
################
# NetworkCandy #
################
add_subdirectory(deps/NetworkCandy)
target_link_libraries(appExec PRIVATE nw-candy)
# install
if(MINGW)
find_file(MINGW_MINIUPNPC libminiupnpc.dll REQUIRED)
install(FILES ${MINGW_MINIUPNPC}
TYPE BIN
COMPONENT "Runtime"
)
endif()
#############
# AudioTube #
#############
# add as shared lib
SET(AUDIOTUBE_SHARED ON CACHE INTERNAL "")
add_subdirectory(deps/AudioTube)
get_directory_property(AUDIOTUBE_PROJECT_VERSION
DIRECTORY deps/AudioTube
DEFINITION PROJECT_VERSION
)
# link
target_link_libraries(appExec PRIVATE audiotube)
# install
install(FILES $<TARGET_FILE:audiotube>
TYPE BIN
COMPONENT "AudioTube"
)
#########
# Dicer #
#########
add_subdirectory(deps/Dicer)
target_link_libraries(appExec PRIVATE dicer)
####################
# Gstreamer - base #
####################
# find Gstreamer
pkg_check_modules(Gst REQUIRED IMPORTED_TARGET gstreamer-1.0)
message("GStreamer found at : [${Gst_LIBRARY_DIRS}]") # helps if pkfconf uses the wrong search path
# link
target_link_libraries(appExec PRIVATE PkgConfig::Gst)
######################
# Gstreamer - GnuTLS #
######################
# find module
find_file(giognutls_LIB
NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}giognutls${CMAKE_SHARED_LIBRARY_SUFFIX}
PATH_SUFFIXES "lib/gio/modules"
REQUIRED
)
# copy file
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gio)
file(COPY ${giognutls_LIB} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gio)
# install
install(
DIRECTORY $<TARGET_FILE_DIR:appExec>/gio
TYPE BIN
COMPONENT "GStreamer"
)
#######################
# Gstreamer - plugins #
#######################
# get plugin shared libraries location
pkg_get_variable(GSTREAMER_PLUGINS_LIB_LOCATION gstreamer-1.0
pluginsdir
)
# define gstreamer plugins to use
# core
LIST(APPEND REQUIRED_GST_PLUGINS
playback
autodetect
coreelements
)
# opus stream read
LIST(APPEND REQUIRED_GST_PLUGINS
soup
typefindfunctions
matroska
opus
volume
audioconvert
audioresample
)
# windows specific ?
LIST(APPEND REQUIRED_GST_PLUGINS
waveform
)
# copy gstreamer plugins into output
foreach(_gstPluginLib IN ITEMS ${REQUIRED_GST_PLUGINS})
# using find_file because find_library is kinda broken with .dll on MinGW
find_file(${_gstPluginLib}_LIBRARY
NAMES ${CMAKE_SHARED_LIBRARY_PREFIX}gst${_gstPluginLib}${CMAKE_SHARED_LIBRARY_SUFFIX}
PATHS ${GSTREAMER_PLUGINS_LIB_LOCATION}
NO_DEFAULT_PATH
REQUIRED
)
list(APPEND GST_ALL_USED_PLUGINS
${${_gstPluginLib}_LIBRARY}
)
endforeach()
# install
include(GNUInstallDirs)
install(FILES ${GST_ALL_USED_PLUGINS}
DESTINATION ${CMAKE_INSTALL_BINDIR}/gst-plugins
COMPONENT "GStreamer"
)
#####################
# list source files #
#####################
file(GLOB_RECURSE APP_CPP_FILES "src/*.cpp")
file(GLOB_RECURSE APP_HPP_FILES "src/*.hpp")
file(GLOB_RECURSE APP_H_FILES "src/*.h")
# defined as public for tests
target_sources(appExec PUBLIC
${APP_CPP_FILES}
${APP_HPP_FILES}
)
################
# translations #
################
include(QtTranslation)
# app sources
list(APPEND TS_SOURCE_FILES
${APP_CPP_FILES}
${APP_HPP_FILES}
${APP_H_FILES}
)
list(APPEND TS_FILES
"src/_i18n/fr.ts"
)
HandleQtTranslation(appExec
"App"
"${TS_SOURCE_FILES}"
${TS_FILES}
)
# IFW sources
list(APPEND TS_INSTALL_SOURCE_FILES
"src/_ifw/EndInstallerForm.ui"
)
list(APPEND TS_INSTALL_FILES
"src/_i18n/EndInstallerForm_fr.ts"
)
HandleQtTranslation(appExec
OFF
"${TS_INSTALL_SOURCE_FILES}"
${TS_INSTALL_FILES}
)
########################
# Runtime dependencies #
########################
include(CMakeDependencies)
# QT
DeployPEDependencies(appExec "Qt"
${CMAKE_BINARY_DIR}/QtRuntime/**/*.dll
)
# GST
DeployPEDependencies(appExec "GStreamer"
${PEDeps_Qt_DIR}/*.dll
${giognutls_LIB}
${GST_ALL_USED_PLUGINS}
)
######################
# add Publish target #
######################
# publish script
include(CMakePublish)