forked from mavlink/qgroundcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
422 lines (363 loc) · 13 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
cmake_minimum_required(VERSION 3.22.1)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
#######################################################
# Custom Build Configuration
#######################################################
include(CustomOptions)
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/custom)
message(STATUS "Enabling custom build")
set(QGC_CUSTOM_BUILD ON)
include(${CMAKE_SOURCE_DIR}/custom/CustomOverrides.cmake)
endif()
#######################################################
# Project Info
#######################################################
include(Git)
project(QGroundControl
VERSION ${QGC_APP_VERSION}
DESCRIPTION ${QGC_APP_DESCRIPTION}
HOMEPAGE_URL "https://qgroundcontrol.com/"
LANGUAGES C CXX
)
if(UNIX AND NOT APPLE AND NOT ANDROID)
set(LINUX TRUE)
endif()
if(APPLE AND NOT IOS)
set(MACOS TRUE)
endif()
if(IOS OR ANDROID)
set(MOBILE TRUE)
add_compile_definitions(__mobile__)
endif()
#######################################################
# CMake Configuration Options
#######################################################
include(GNUInstallDirs)
include(CMakeDependentOption)
include(FetchContent)
include(CMakePrintHelpers)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
if(LINUX)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/AppDir/usr)
else()
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/staging)
endif()
if(UNIX)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Using CCache")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
endif()
elseif(WIN32)
# find_program(SCCACHE_PROGRAM sccache)
if(SCCACHE_PROGRAM)
message(STATUS "Using SCCache")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_PROGRAM})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_PROGRAM})
if(MSVC)
string(APPEND CMAKE_CXX_FLAGS " /FS")
endif()
endif()
endif()
cmake_print_variables(
CMAKE_VERSION
CMAKE_PREFIX_PATH
CMAKE_HOST_SYSTEM_NAME
CMAKE_HOST_SYSTEM_VERSION
CMAKE_SYSTEM_NAME
CMAKE_SYSTEM_VERSION
CMAKE_CURRENT_SOURCE_DIR
CMAKE_BUILD_TYPE
CMAKE_TOOLCHAIN_FILE
)
#######################################################
# Qt6 Configuration
#######################################################
include(Qt6QGCConfiguration)
set(QT_QML_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/qml" CACHE PATH "Install path for QML" FORCE)
# set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "Extra QML Import Paths" FORCE)
add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x060600)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_definitions(
NDEBUG
QT_NO_DEBUG
QT_NO_DEBUG_OUTPUT
)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
include(CTest)
enable_testing()
set(QT_ENABLE_VERBOSE_DEPLOYMENT ON CACHE BOOL "Verbose Deployment")
endif()
if(ANDROID)
cmake_print_variables(QT_ANDROID_APPLICATION_ARGUMENTS QT_HOST_PATH)
# QT_USE_TARGET_ANDROID_BUILD_DIR
list(APPEND QT_ANDROID_MULTI_ABI_FORWARD_VARS QGC_STABLE_BUILD)
list(APPEND QT_ANDROID_MULTI_ABI_FORWARD_VARS QT_HOST_PATH)
cmake_print_variables(QT_ANDROID_MULTI_ABI_FORWARD_VARS)
# QT_ANDROID_DEPLOY_RELEASE
# set(QT_ANDROID_DEPLOYMENT_TYPE ON CACHE BOOL "Deployment Type")
cmake_dependent_option(QT_ANDROID_SIGN_APK "Enable Signing APK" ON "CMAKE_BUILD_TYPE STREQUAL Release" OFF)
if(QT_ANDROID_SIGN_APK)
message(STATUS "Signing APK")
message(STATUS "QT_ANDROID_KEYSTORE_PATH $ENV{QT_ANDROID_KEYSTORE_PATH}")
message(STATUS "QT_ANDROID_KEYSTORE_ALIAS $ENV{QT_ANDROID_KEYSTORE_ALIAS}")
# QT_ANDROID_KEYSTORE_STORE_PASS, QT_ANDROID_KEYSTORE_KEY_PASS
endif()
if(NOT Qt6LinguistTools_DIR)
set(Qt6LinguistTools_DIR ${QT_HOST_PATH}/lib/cmake/Qt6LinguistTools)
endif()
endif()
find_package(Qt6
REQUIRED
COMPONENTS
Bluetooth
Charts
Concurrent
Core
Core5Compat
Location
Multimedia
Network
Positioning
Quick
QuickControls2
QuickWidgets
OpenGL
Sensors
Sql
Svg
Test
TextToSpeech
Widgets
Xml
OPTIONAL_COMPONENTS
LinguistTools
SerialPort
HINTS
${QT_LIBRARY_HINTS}
)
# Require 6.6.3 because otherwise libQt6QuickControls2Basic.so.6 &
# libQt6QuickControls2BasicStyleImpl.so.6 are missing.
qt_standard_project_setup(REQUIRES 6.6.3)
qt_policy(
SET QTP0001 NEW
SET QTP0002 NEW
)
#######################################################
# QGroundControl Options
#######################################################
option(QGC_STABLE_BUILD "Stable build option" OFF)
if(NOT QGC_STABLE_BUILD)
add_compile_definitions(DAILY_BUILD)
endif()
cmake_dependent_option(QGC_BUILD_TESTING "Enable testing" ON "CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
if(QGC_BUILD_TESTING)
add_compile_definitions(UNITTEST_BUILD) # TODO: QGC_UNITTEST_BUILD
endif()
# option(QGC_DISABLE_MAVLINK_INSPECTOR "Disable Mavlink Inspector" OFF) # This removes QtCharts which is GPL licensed
cmake_dependent_option(QGC_DEBUG_QML "Build QGroundControl with QML debugging/profiling support." OFF "CMAKE_BUILD_TYPE STREQUAL Debug" OFF)
if(QGC_DEBUG_QML)
message(STATUS "To enable the QML debugger/profiler, run with: '-qmljsdebugger=port:1234'")
add_compile_definitions(QT_QML_DEBUG)
endif()
cmake_dependent_option(QGC_NO_SERIAL_LINK "Build QGroundControl without Serial Support Support." OFF "NOT IOS" ON)
#######################################################
# Custom Build Configuration
#######################################################
if(QGC_CUSTOM_BUILD)
add_subdirectory(custom)
endif()
if(QGC_DISABLE_APM_MAVLINK)
add_compile_definitions(NO_ARDUPILOT_DIALECT)
endif()
#######################################################
# QGroundControl Resources
#######################################################
if(NOT QGC_CUSTOM_BUILD)
# Custom builds can override the resources
list(APPEND QGC_RESOURCES
${CMAKE_SOURCE_DIR}/qgcimages.qrc
${CMAKE_SOURCE_DIR}/qgcresources.qrc
${CMAKE_SOURCE_DIR}/qgroundcontrol.qrc
)
endif()
list(APPEND QGC_RESOURCES
${CMAKE_SOURCE_DIR}/resources/InstrumentValueIcons/InstrumentValueIcons.qrc
${CMAKE_SOURCE_DIR}/src/FirmwarePlugin/APM/APMResources.qrc
${CMAKE_SOURCE_DIR}/src/FirmwarePlugin/PX4/PX4Resources.qrc
)
if(CONFIG_UTM_ADAPTER)
list(APPEND QGC_RESOURCES ${CMAKE_SOURCE_DIR}/src/UTMSP/utmsp.qrc)
else()
list(APPEND QGC_RESOURCES ${CMAKE_SOURCE_DIR}/src/UTMSP/dummy/utmsp_dummy.qrc)
endif()
if(QGC_BUILD_TESTING)
list(APPEND QGC_RESOURCES ${CMAKE_SOURCE_DIR}/test/UnitTest.qrc)
endif()
#######################################################
# QGroundControl Target
#######################################################
qt_add_executable(${PROJECT_NAME}
src/main.cc
${QGC_RESOURCES}
)
if(Qt6LinguistTools_FOUND)
file(GLOB TS_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/translations/qgc_*.ts)
qt_add_translations(${PROJECT_NAME} TS_FILES ${TS_SOURCES}) # TODO: Update to new qt_add_translations form in Qt6.7
endif()
set_target_properties(${PROJECT_NAME}
PROPERTIES
QT_RESOURCE_PREFIX "/qgc"
OUTPUT_NAME ${QGC_APP_NAME}
)
if(WIN32)
set(QGC_APP_ICON "${CMAKE_SOURCE_DIR}/deploy/windows/WindowsQGC.ico")
set_target_properties(${PROJECT_NAME}
PROPERTIES
WIN32_EXECUTABLE TRUE
QT_TARGET_RC_ICONS ${QGC_APP_ICON}
)
add_compile_definitions(_USE_MATH_DEFINES)
elseif(MACOS)
set(QGC_APP_ICON "${QGC_MACOS_ICON_PATH}/macx.icns")
set_source_files_properties(${QGC_APP_ICON}
PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(${PROJECT_NAME} PRIVATE ${QGC_APP_ICON})
set_target_properties(${PROJECT_NAME}
PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/deploy/mac/MacOSXBundleInfo.plist.in"
MACOSX_BUNDLE_BUNDLE_NAME "${QGC_APP_NAME}"
MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "${QGC_APP_COPYRIGHT}"
MACOSX_BUNDLE_GUI_IDENTIFIER "${QGC_BUNDLE_ID}"
MACOSX_BUNDLE_ICON_FILE "macx.icns"
MACOSX_BUNDLE_INFO_STRING "${QGC_APP_DESCRIPTION}"
MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
)
elseif(IOS)
enable_language(OBJC)
set_target_properties(${PROJECT_NAME}
PROPERTIES
QT_IOS_LAUNCH_SCREEN ${CMAKE_SOURCE_DIR}/deploy/ios/QGCLaunchScreen.xib
)
elseif(ANDROID)
FetchContent_Declare(android_openssl
DOWNLOAD_EXTRACT_TIMESTAMP true
URL https://github.com/KDAB/android_openssl/archive/refs/heads/master.zip
)
FetchContent_MakeAvailable(android_openssl)
include(${android_openssl_SOURCE_DIR}/android_openssl.cmake)
add_android_openssl_libraries(${PROJECT_NAME})
set(ANDROID_PLATFORM_ARCHITECTURE_CODE)
if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
set(ANDROID_PLATFORM_ARCHITECTURE_CODE "032")
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
set(ANDROID_PLATFORM_ARCHITECTURE_CODE "064")
elseif(${ANDROID_ABI} STREQUAL "x86")
set(ANDROID_PLATFORM_ARCHITECTURE_CODE "132")
elseif(${ANDROID_ABI} STREQUAL "x86_64")
set(ANDROID_PLATFORM_ARCHITECTURE_CODE "164")
endif()
set(ANDROID_VERSION_CODE "${ANDROID_PLATFORM_ARCHITECTURE_CODE}${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}")
set_target_properties(${PROJECT_NAME}
PROPERTIES
# QT_ANDROID_ABIS ${ANDROID_ABI}
QT_ANDROID_MIN_SDK_VERSION 26
QT_ANDROID_TARGET_SDK_VERSION 34
QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/android
QT_ANDROID_VERSION_NAME ${CMAKE_PROJECT_VERSION}
QT_ANDROID_VERSION_CODE ${ANDROID_VERSION_CODE}
# QT_QML_ROOT_PATH ${CMAKE_SOURCE_DIR}
)
# get_target_property(QGC_ANDROID_DEPLOY_FILE ${PROJECT_NAME} QT_ANDROID_DEPLOYMENT_SETTINGS_FILE)
elseif(LINUX)
endif()
add_compile_definitions(
QGC_APP_NAME="${QGC_APP_NAME}"
QGC_ORG_NAME="${QGC_ORG_NAME}"
QGC_ORG_DOMAIN="${QGC_ORG_DOMAIN}"
QGC_APP_VERSION_STR="${QGC_APP_VERSION_STR}"
)
add_subdirectory(src)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Qt6::Core
Qt6::Quick
Qt6::Widgets
Qt6::Svg # Used to import QSvgPlugin
QGC
QmlControls
Utilities
)
if(QGC_BUILD_TESTING)
add_subdirectory(test)
target_link_libraries(${PROJECT_NAME} PRIVATE qgctest)
endif()
#######################################################
# Install Configuration
#######################################################
qt_import_plugins(${PROJECT_NAME}
INCLUDE Qt6::QSvgPlugin
EXCLUDE_BY_TYPE geoservices
INCLUDE_BY_TYPE sqldrivers Qt6::QSQLiteDriverPlugin
)
install(
TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
BUNDLE DESTINATION .
)
qt_generate_deploy_qml_app_script(
TARGET ${PROJECT_NAME}
OUTPUT_SCRIPT deploy_script
# DEPLOY_TOOL_OPTIONS
MACOS_BUNDLE_POST_BUILD
NO_UNSUPPORTED_PLATFORM_ERROR
DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM
)
install(SCRIPT ${deploy_script})
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/resources/
DESTINATION ${CMAKE_INSTALL_DATADIR}/qgroundcontrol
)
if(LINUX)
install(
FILES ${CMAKE_SOURCE_DIR}/deploy/linux/org.mavlink.qgroundcontrol.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications
)
install(
FILES ${CMAKE_SOURCE_DIR}/resources/icons/qgroundcontrol.png
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/128x128/apps/
RENAME org.mavlink.qgroundcontrol.png
)
configure_file(
${CMAKE_SOURCE_DIR}/deploy/linux/org.mavlink.qgroundcontrol.metainfo.xml.in
${CMAKE_BINARY_DIR}/metainfo/org.mavlink.qgroundcontrol.metainfo.xml
@ONLY
)
install(
FILES ${CMAKE_BINARY_DIR}/metainfo/org.mavlink.qgroundcontrol.metainfo.xml
DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo/
)
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateAppImage.cmake")
elseif(WIN32)
# install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateQGCInstaller.cmake")
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateWinInstaller.cmake")
elseif(MACOS)
install(SCRIPT "${CMAKE_SOURCE_DIR}/cmake/CreateMacDMG.cmake")
endif()