forked from veyon/veyon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
354 lines (310 loc) · 10.3 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
cmake_minimum_required(VERSION 3.10.0)
message("Using CMake ${CMAKE_VERSION}")
project(veyon)
option(WITH_CORE_ONLY "Build core library only" OFF)
option(WITH_ADDONS "Build add-ons" OFF)
option(WITH_TRANSLATIONS "Build translation files" ON)
option(WITH_TESTS "Build tests and integrate runtime test extensions" OFF)
option(WITH_LTO "Build with link-time optimization" ON)
option(WITH_PCH "Reduce compile time by using precompiled headers (requires CMake >= 3.16)" ON)
option(WITH_UNITY_BUILD "Reduce compile time by using cmake unity builds (requires CMake >= 3.16)" ON)
option(WITH_ADDRESS_SANITIZER "Build with address sanitizer" OFF)
option(WITH_THREAD_SANITIZER "Build with thread sanitizer" OFF)
option(WITH_UB_SANITIZER "Build with undefined behavior sanitizer" OFF)
option(WITH_FUZZERS "Build LLVM fuzzer tests (implies WITH_TESTS=ON)" OFF)
option(WITH_BUILTIN_LIBVNC "Build with built-in LibVNCServer/Client" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(VEYON_DEBUG TRUE)
elseif(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "None")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
if(VEYON_DEBUG)
add_definitions(-DVEYON_DEBUG)
else()
add_definitions(-D_FORTIFY_SOURCE=2)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0009 NEW)
cmake_policy(SET CMP0022 NEW)
cmake_policy(SET CMP0058 NEW)
cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0069 NEW)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12.0")
cmake_policy(SET CMP0075 NEW)
endif()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14.0")
cmake_policy(SET CMP0083 NEW)
include(CheckPIESupported)
check_pie_supported(LANGUAGES CXX)
if(CMAKE_CXX_LINK_PIE_SUPPORTED)
set(CMAKE_COMPILE_OPTIONS_PIE "-fPIE")
set(CMAKE_LINK_OPTIONS_PIE "-pie;-fPIE;-fPIC")
else()
set(CMAKE_COMPILE_OPTIONS_PIE "-fPIC")
set(CMAKE_LINK_OPTIONS_PIE "-fPIC")
endif()
endif()
endif()
include(AddFileDependencies)
include(CheckCSourceCompiles)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckTypeSize)
include(GNUInstallDirs)
include(ConfigureFiles)
include(PchHelpers)
include(SetDefaultTargetProperties)
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE VERSION_STRING)
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION_STRING}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION_STRING}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION_STRING}")
# determine build number to use in NSIS installer and resource files
execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags
COMMAND cut -d "-" -f2
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE VERSION_BUILD)
if(NOT VERSION_BUILD GREATER 0)
set(VERSION_BUILD 0)
endif()
# Get list of all committers from git history, ordered by number of commits.
# The CONTRIBUTORS file is used by AboutDialog. This information can be provided
# with -DCONTRIBUTORS=/path/to/CONTRIBUTORS instead. For instance, to generate
# this file for version 3.0.2, the command is:
# git shortlog -sne v3.0.2 | cut -c8-
set(CONTRIBUTORS "${CMAKE_BINARY_DIR}/CONTRIBUTORS")
if(NOT EXISTS "${CONTRIBUTORS}")
execute_process(COMMAND "${GIT_EXECUTABLE}" shortlog -s d160d147165271516589c304cb1b8f5e48f8527d..HEAD
COMMAND cut -c8-
COMMAND sort -f
OUTPUT_FILE "${CONTRIBUTORS}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
TIMEOUT 10)
endif()
endif()
# can't retrieve version information as not building from Git repository?
if(NOT VERSION_STRING)
set(VERSION_MAJOR 4)
set(VERSION_MINOR 99)
set(VERSION_PATCH 0)
set(VERSION_BUILD 0)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
else()
# remove leading character from tag name
string(REPLACE "v" "" VERSION_STRING "${VERSION_STRING}")
endif()
# set up basic platform variables
if(WIN32)
set(VEYON_BUILD_WINDOWS 1)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(VEYON_BUILD_WIN64 1)
set(VEYON_WINDOWS_ARCH "win64")
else()
set(VEYON_BUILD_WIN32 1)
set(VEYON_WINDOWS_ARCH "win32")
endif()
add_definitions(-DUNICODE -D_UNICODE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-attributes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes")
endif()
if(APPLE)
set(VEYON_BUILD_APPLE 1)
endif()
if(UNIX AND NOT ANDROID)
set(VEYON_BUILD_LINUX 1)
endif()
if(ANDROID)
set(VEYON_BUILD_ANDROID 1)
endif()
# set up library and plugin path variables
if(VEYON_BUILD_ANDROID)
set(CMAKE_INSTALL_PREFIX "/")
set(VEYON_LIB_DIR "lib")
set(VEYON_INSTALL_PLUGIN_DIR "${VEYON_LIB_DIR}/veyon")
set(VEYON_INSTALL_DATA_DIR "${CMAKE_INSTALL_DATADIR}/veyon")
set(VEYON_PLUGIN_DIR "")
set(VEYON_TRANSLATIONS_DIR "/translations")
else()
if(CMAKE_INSTALL_LIBDIR)
set(VEYON_LIB_DIR "${CMAKE_INSTALL_LIBDIR}/veyon" CACHE INTERNAL "Veyon library directory")
else()
set(VEYON_LIB_DIR lib/veyon CACHE INTERNAL "Veyon library directory")
endif()
set(VEYON_INSTALL_PLUGIN_DIR "${VEYON_LIB_DIR}")
set(VEYON_INSTALL_DATA_DIR "${CMAKE_INSTALL_DATADIR}/veyon")
if(WIN32)
set(VEYON_PLUGIN_DIR "plugins")
set(VEYON_TRANSLATIONS_DIR "translations")
else()
set(VEYON_PLUGIN_DIR "../${VEYON_LIB_DIR}")
set(VEYON_TRANSLATIONS_DIR "../share/veyon/translations")
endif()
endif()
# find required Qt modules
option(WITH_QT6 "Build for Qt 6" OFF)
if(WITH_QT6)
set(QT_MAJOR_VERSION 6)
find_package(Qt6 COMPONENTS
Core
Core5Compat
Concurrent
Gui
Widgets
Network
Quick
QuickControls2
REQUIRED)
if(WITH_TRANSLATIONS)
find_package(Qt6 COMPONENTS LinguistTools REQUIRED)
endif()
if(VEYON_BUILD_ANDROID)
find_package(Qt6 COMPONENTS AndroidExtras REQUIRED)
endif()
else()
set(QT_MAJOR_VERSION 5)
find_package(Qt5Core REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5QuickControls2 REQUIRED)
if(WITH_TRANSLATIONS)
find_package(Qt5LinguistTools REQUIRED)
endif()
if(VEYON_BUILD_ANDROID)
find_package(Qt5AndroidExtras REQUIRED)
endif()
endif()
# find required libraries
find_package(Qca-qt${QT_MAJOR_VERSION} REQUIRED)
find_package(OpenSSL REQUIRED)
# find Linux-specific packages
if(VEYON_BUILD_LINUX)
include(XdgInstall)
endif()
if(${CMAKE_VERSION} VERSION_LESS "3.16.0")
set(WITH_PCH OFF)
set(WITH_UNITY_BUILD OFF)
elseif(WITH_UNITY_BUILD)
set(CMAKE_UNITY_BUILD ON)
endif()
if(VEYON_BUILD_WIN32)
set(WITH_LTO OFF)
endif()
if(WITH_LTO)
include(ProcessorCount)
ProcessorCount(CPU_COUNT)
set(GCC_LTO_FLAGS "-flto=${CPU_COUNT} -fno-fat-lto-objects")
endif()
if(WITH_FUZZERS)
set(WITH_TESTS ON)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong ${CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -fno-exceptions ${CXXFLAGS}")
if(WITH_TESTS)
enable_testing(TRUE)
if(WITH_QT6)
find_package(Qt6 COMPONENTS Test REQUIRED)
else()
find_package(Qt5Test REQUIRED)
endif()
else()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
endif()
add_definitions(
-DQT_DEPRECATED_WARNINGS
-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_KEYWORDS
-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT
-DQT_USE_QSTRINGBUILDER
-DQT_STRICT_ITERATORS
)
file(GLOB_RECURSE IN_FILES RELATIVE ${CMAKE_SOURCE_DIR} "veyonconfig.h.in" "*.rc.in" "*.desktop.in" "*.policy.in" "*.service.in" "*.manifest.in" "*.nsi.in")
configure_files(${IN_FILES})
set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTOUIC TRUE)
set(CMAKE_AUTORCC TRUE)
set(3rdparty_DIR ${CMAKE_SOURCE_DIR}/3rdparty)
set(ultravnc_DIR ${3rdparty_DIR}/ultravnc)
set(libvncserver_DIR ${3rdparty_DIR}/libvncserver)
set(x11vnc_DIR ${3rdparty_DIR}/x11vnc)
set(libfakekey_DIR ${3rdparty_DIR}/libfakekey)
set(qthttpserver_DIR ${3rdparty_DIR}/qthttpserver)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${VEYON_LIB_DIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(VEYON_BUILD_ANDROID)
include(AndroidDeployQt)
set(_CMAKE_ANDROID_DIR "${CMAKE_SOURCE_DIR}/android")
set(ANDROID_INSTALL_DIR "${CMAKE_BINARY_DIR}/install")
set(ANDROID_EXTRA_PLUGINS ${ANDROID_INSTALL_DIR}/${VEYON_LIB_DIR}/veyon/ ${QT_DIR}/lib/qca-qt5/crypto ${ANDROID_INSTALL_DIR}/jar)
set(ANDROID_EXTRA_LIBS)
list(APPEND ANDROID_EXTRA_LIBS "${ANDROID_SYSROOT_GENERIC}/libc++_shared.so")
list(APPEND ANDROID_EXTRA_LIBS "${QT_DIR}/lib/libldap.so"
"${QT_DIR}/lib/liblber.so"
"${QT_DIR}/lib/libsasl2.so")
add_custom_target(prepare-apk
COMMAND rm -rf ${ANDROID_INSTALL_DIR}
COMMAND cd ${CMAKE_BINARY_DIR}/core && make DESTDIR=${ANDROID_INSTALL_DIR} install
COMMAND cd ${CMAKE_BINARY_DIR}/plugins && make DESTDIR=${ANDROID_INSTALL_DIR} install
)
endif()
include(cmake/CPackDefinitions.cmake)
# make sub-directories
add_subdirectory(core)
if(NOT WITH_CORE_ONLY)
add_subdirectory(server)
add_subdirectory(service)
add_subdirectory(master)
add_subdirectory(configurator)
add_subdirectory(cli)
add_subdirectory(worker)
add_subdirectory(plugins)
add_subdirectory(tests)
add_subdirectory(translations)
endif()
if(WITH_ADDONS)
add_subdirectory(addons)
endif()
#
# add Windows installer related targets
#
if(WIN32)
include(WindowsInstaller)
endif()
#
# package generation
#
include(CPack)
#
# display configuration information
#
message("\n"
"Veyon build summary\n"
"--------------------\n"
"* Version : ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD} (${VERSION_STRING})\n"
"* Install prefix : ${CMAKE_INSTALL_PREFIX}\n"
"* Library directory : ${CMAKE_INSTALL_PREFIX}/${VEYON_LIB_DIR}\n"
"* Plugin directory : ${CMAKE_INSTALL_PREFIX}/${VEYON_INSTALL_PLUGIN_DIR}\n"
"* Build type : ${CMAKE_BUILD_TYPE}\n"
"* Build platform : ${CMAKE_SYSTEM_PROCESSOR}\n"
"* Compile flags : ${CMAKE_C_FLAGS} (CXX: ${CMAKE_CXX_FLAGS})\n"
"* Link-time optimization : ${WITH_LTO}\n"
"* Use precompiled headers : ${WITH_PCH}\n"
"* Use unity build : ${WITH_UNITY_BUILD}\n"
)