forked from mavlink/qgroundcontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
428 lines (365 loc) · 15.1 KB
/
Copy pathCMakeLists.txt
File metadata and controls
428 lines (365 loc) · 15.1 KB
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
# ============================================================================
# QGroundControl CMake Build Configuration
# ============================================================================
cmake_minimum_required(VERSION 3.25)
# ----------------------------------------------------------------------------
# CMake Module Paths
# ----------------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake"
"${CMAKE_SOURCE_DIR}/cmake/find-modules"
"${CMAKE_SOURCE_DIR}/cmake/install"
"${CMAKE_SOURCE_DIR}/cmake/install/CPack"
"${CMAKE_SOURCE_DIR}/cmake/modules"
"${CMAKE_SOURCE_DIR}/cmake/platform"
)
include(Helpers)
# ----------------------------------------------------------------------------
# Default Build Type
# ----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (Debug or Release)" FORCE)
message(STATUS "No build type specified. Defaulting to Release.")
endif()
# ----------------------------------------------------------------------------
# CMake Policy Configuration
# ----------------------------------------------------------------------------
set(CMAKE_REQUIRED_QUIET ON)
set(CMAKE_POLICY_VERSION_MINIMUM ${CMAKE_MINIMUM_REQUIRED_VERSION})
# ============================================================================
# Custom Build Configuration
# ============================================================================
# Load default options and allow custom builds to override
include(CustomOptions)
option(QGC_VERBOSE_CONFIGURE "Prefix configure messages with module context labels" OFF)
set(CMAKE_MESSAGE_CONTEXT_SHOW ${QGC_VERBOSE_CONFIGURE})
list(APPEND CMAKE_MESSAGE_CONTEXT qgc)
# build-config.json is the source of truth; keep cmake_minimum_required(...) above in sync.
if(CMAKE_VERSION VERSION_LESS QGC_CONFIG_CMAKE_MINIMUM)
message(FATAL_ERROR "QGC: requires CMake ${QGC_CONFIG_CMAKE_MINIMUM}+, found ${CMAKE_VERSION}")
endif()
if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/${QGC_CUSTOM_DIR}")
message(STATUS "QGC: Custom build directory detected: ${QGC_CUSTOM_DIR}")
set(QGC_CUSTOM_BUILD ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/${QGC_CUSTOM_DIR}/cmake")
include(CustomOverrides)
endif()
# Disable testing if not explicitly enabled
if(NOT QGC_BUILD_TESTING)
set(BUILD_TESTING OFF CACHE INTERNAL "Disable testing by default" FORCE)
endif()
# ============================================================================
# Project Configuration
# ============================================================================
# ----------------------------------------------------------------------------
# Apple-Specific Pre-Project Settings
# ----------------------------------------------------------------------------
# APPLE is true on iOS too; gate on CMAKE_SYSTEM_NAME or the iOS toolchain's
# arm64-only CMAKE_OSX_ARCHITECTURES gets clobbered with x86_64h;arm64.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET "${QGC_CONFIG_MACOS_DEPLOYMENT_TARGET}" CACHE STRING "macOS minimum deployment target")
if(QGC_MACOS_UNIVERSAL_BUILD)
set(CMAKE_OSX_ARCHITECTURES "x86_64h;arm64")
endif()
endif()
# ----------------------------------------------------------------------------
# Git Integration & Version Extraction
# ----------------------------------------------------------------------------
include(Git)
# ----------------------------------------------------------------------------
# Compiler Caching Configuration
# ----------------------------------------------------------------------------
if(QGC_USE_CACHE)
qgc_config_caching()
endif()
# ----------------------------------------------------------------------------
# Project Declaration
# ----------------------------------------------------------------------------
project(${QGC_APP_NAME}
VERSION ${QGC_APP_VERSION}
DESCRIPTION "${QGC_APP_DESCRIPTION}"
HOMEPAGE_URL "https://${QGC_ORG_DOMAIN}"
LANGUAGES C CXX
)
# ============================================================================
# CMake & Build System Configuration
# ============================================================================
# Standard CMake modules
include(GNUInstallDirs)
include(FetchContent)
include(CMakePrintHelpers)
if(QGC_BUILD_TESTING)
include(CTest)
endif()
# ----------------------------------------------------------------------------
# CPM (CMake Package Manager) Configuration
# ----------------------------------------------------------------------------
if(NOT CPM_SOURCE_CACHE)
if(DEFINED ENV{CPM_SOURCE_CACHE} AND NOT "$ENV{CPM_SOURCE_CACHE}" STREQUAL "")
set(CPM_SOURCE_CACHE "$ENV{CPM_SOURCE_CACHE}" CACHE PATH "CPM source cache directory")
else()
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/CPM" CACHE PATH "CPM source cache directory")
endif()
endif()
include(CPM)
include(CPMTrackHead)
# ----------------------------------------------------------------------------
# Toolchain Configuration (Compiler, Linker, Build Settings)
# ----------------------------------------------------------------------------
include(Toolchain)
# ----------------------------------------------------------------------------
# Python interpreter for code generators (prefer workspace .venv)
# ----------------------------------------------------------------------------
include(PythonVenv)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
include(QGCQmlCodegen)
# ----------------------------------------------------------------------------
# Output Directories
# ----------------------------------------------------------------------------
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>")
if(ANDROID)
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIG>")
endif()
# ----------------------------------------------------------------------------
# CMake Policies
# ----------------------------------------------------------------------------
# CMP0168: Modern FetchContent integration
if(POLICY CMP0168)
cmake_policy(SET CMP0168 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0168 NEW)
endif()
# CMP0141: MSVC debug information format
cmake_policy(SET CMP0141 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0141 NEW)
# CMP0075: Include files in CheckIncludeFile
cmake_policy(SET CMP0075 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0075 NEW)
# CMP0194: MSVC is not an assembler for language ASM (zstd)
if(POLICY CMP0194)
cmake_policy(SET CMP0194 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0194 NEW)
endif()
# ============================================================================
# Vulkan Headers (needed by Qt on Windows when Vulkan SDK is not installed)
# ============================================================================
if(WIN32 AND NOT TARGET Vulkan::Headers)
find_package(Vulkan QUIET COMPONENTS Headers)
if(NOT Vulkan_FOUND)
CPMAddPackage(
NAME VulkanHeaders
GITHUB_REPOSITORY KhronosGroup/Vulkan-Headers
GIT_TAG vulkan-sdk-1.4.341.0
SYSTEM YES
)
if(VulkanHeaders_SOURCE_DIR)
set(Vulkan_INCLUDE_DIR "${VulkanHeaders_SOURCE_DIR}/include" CACHE PATH "" FORCE)
endif()
endif()
endif()
# ============================================================================
# Qt6 Configuration
# ============================================================================
set(QT_NO_PRIVATE_MODULE_WARNING ON)
find_package(Qt6 ${QGC_QT_MINIMUM_VERSION} QUIET COMPONENTS Core)
if(NOT Qt6_FOUND)
message(FATAL_ERROR
"Qt6 ${QGC_QT_MINIMUM_VERSION}+ not found.\n"
"Set CMAKE_PREFIX_PATH to your Qt installation, e.g.:\n"
" cmake -DCMAKE_PREFIX_PATH=~/Qt/6.8.3/gcc_64 ..\n"
" (or use qt-cmake which sets this automatically)\n"
"Searched: ${CMAKE_PREFIX_PATH}"
)
endif()
find_package(Qt6
${QGC_QT_MINIMUM_VERSION}...${QGC_QT_MAXIMUM_VERSION}
REQUIRED
COMPONENTS
Graphs
Concurrent
Core
Gui
HttpServer
LinguistTools
Location
LocationPrivate
Multimedia
Network
Positioning
Qml
QmlIntegration
Quick
QuickControls2
QuickVectorImage
QuickWidgets
Sensors
Sql
Svg
TextToSpeech
Xml
Quick3D
StateMachine
OPTIONAL_COMPONENTS
Bluetooth
MultimediaQuickPrivate
OpenGL
QuickTest
SerialPort
Test
)
if(LINUX AND NOT ANDROID)
find_package(Qt6 ${QGC_QT_MINIMUM_VERSION}...${QGC_QT_MAXIMUM_VERSION} COMPONENTS WaylandClient)
endif()
if(QGC_USE_MOCCACHE)
qgc_config_moccache()
endif()
qt_standard_project_setup(
REQUIRES ${QGC_QT_MINIMUM_VERSION}
SUPPORTS_UP_TO ${QGC_QT_MAXIMUM_VERSION}
I18N_SOURCE_LANGUAGE en
)
# ----------------------------------------------------------------------------
# Qt Policies (Enable modern Qt6 behaviors)
# ----------------------------------------------------------------------------
qt_policy(
SET QTP0001 NEW # Modern resource handling
SET QTP0002 NEW # New behavior for QML module URI
SET QTP0003 NEW # Better QML type registration
SET QTP0004 NEW # Improved translation handling
SET QTP0005 NEW # Enhanced deployment handling
)
if(QT_QML_NO_CACHEGEN)
add_compile_definitions(QT_QML_NO_CACHEGEN)
endif()
# ============================================================================
# Custom Build Subdirectory
# ============================================================================
if(QGC_CUSTOM_BUILD)
add_subdirectory("${QGC_CUSTOM_DIR}")
endif()
# ============================================================================
# QGroundControl Resources
# ============================================================================
# Resources go on the executable (not a library) to avoid Q_INIT_RESOURCE().
# Don't route the big .qrcs through qt_add_big_resources — its pass2 object-file
# output fails on MSVC ("No data signature found") when large data sections are elided.
list(APPEND QGC_RESOURCES
"${CMAKE_SOURCE_DIR}/qgcresources.qrc"
)
# ============================================================================
# QGroundControl Executable Target
# ============================================================================
include(Hardening)
qgc_apply_global_hardening()
qt_add_executable(${CMAKE_PROJECT_NAME}
WIN32 # Windows GUI application
MACOSX_BUNDLE # macOS application bundle
${QGC_RESOURCES}
)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
ADDITIONAL_CLEAN_FILES "${CMAKE_BINARY_DIR}/ccache-launcher"
)
include(Sanitizers)
include(Coverage)
qgc_apply_warning_flags()
# ----------------------------------------------------------------------------
# Platform-Specific Configuration
# ----------------------------------------------------------------------------
if(WIN32)
include(Windows)
elseif(APPLE)
include(Apple)
elseif(ANDROID)
include(Android)
elseif(LINUX)
include(Linux)
endif()
# ----------------------------------------------------------------------------
# QML Module Configuration
# ----------------------------------------------------------------------------
qt_add_qml_module(${CMAKE_PROJECT_NAME}
URI QGC
VERSION 1.0
RESOURCE_PREFIX /qml
IMPORTS
QtQuick
QtQuick.Controls
QtQuick.Dialogs
QtQuick.Layouts
)
# ----------------------------------------------------------------------------
# Source & Test Subdirectories
# ----------------------------------------------------------------------------
if(QGC_BUILD_TESTING)
# Marks test-capable builds at the preprocessor level so production code can
# compile out unit-test-only hooks (e.g. QGCCacheWorker::setUnitTestTileGenerator).
# Directory scope is intentional: the hooks live in sources compiled into several
# targets (${CMAKE_PROJECT_NAME}, QGroundControlModule, QGCLocation), so a single
# target-scoped definition would not cover them all.
add_compile_definitions(QGC_UNITTEST_BUILD)
endif()
add_subdirectory(src)
if(QGC_BUILD_TESTING)
add_subdirectory(test)
# Exclude test directory from translation scanning
set_property(DIRECTORY test PROPERTY QT_EXCLUDE_FROM_TRANSLATION ON)
# Pure-CMake unit tests for cmake/GStreamer helpers (no project build needed).
add_subdirectory(cmake/GStreamer/tests)
endif()
# ----------------------------------------------------------------------------
# Translation/Localization Configuration
# ----------------------------------------------------------------------------
file(GLOB TS_SOURCES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/translations/qgc_*.ts")
# Exclude pseudo-localization files from non-debug builds.
# Multi-config generators (VS, Xcode, Ninja Multi-Config) do not set CMAKE_BUILD_TYPE
# at configure time, so _eo files cannot be conditionally included for Debug only —
# excluding them from all multi-config configurations avoids shipping them in Release.
get_property(_qgc_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_qgc_is_multi_config OR NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
list(FILTER TS_SOURCES EXCLUDE REGEX "_eo\\.ts$")
endif()
set(QT_NO_MISSING_CATALOG_LANGUAGE_WARNING ON)
qt_add_translations(${CMAKE_PROJECT_NAME}
TS_FILES ${TS_SOURCES}
RESOURCE_PREFIX "/"
LUPDATE_OPTIONS -no-obsolete
TS_FILE_DIR "${CMAKE_SOURCE_DIR}/translations"
TS_FILE_BASE ${CMAKE_PROJECT_NAME}
QM_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/i18n"
MERGE_QT_TRANSLATIONS
)
# ----------------------------------------------------------------------------
# Qt Quick Controls Configuration
# ----------------------------------------------------------------------------
qgc_set_qt_resource_alias("${CMAKE_SOURCE_DIR}/resources/qtquickcontrols2.conf")
qt_add_resources(${CMAKE_PROJECT_NAME} "qgcresources_cmake"
PREFIX "/"
FILES "${CMAKE_SOURCE_DIR}/resources/qtquickcontrols2.conf"
)
# ----------------------------------------------------------------------------
# Qt Plugin Configuration
# ----------------------------------------------------------------------------
qt_import_plugins(${CMAKE_PROJECT_NAME}
INCLUDE Qt6::QSvgPlugin Qt6::QOffscreenIntegrationPlugin
EXCLUDE_BY_TYPE geoservices # Use built-in location plugins
INCLUDE_BY_TYPE sqldrivers Qt6::QSQLiteDriverPlugin
)
# Linux-specific Qt platform plugins
if(LINUX)
qt_import_plugins(${CMAKE_PROJECT_NAME}
INCLUDE
Qt6::QWaylandIntegrationPlugin # Wayland support (libqwayland.so)
Qt6::QXcbIntegrationPlugin # X11 support
Qt6::QEglFSIntegrationPlugin # Embedded GL support
)
endif()
# ============================================================================
# Installation & Packaging
# ============================================================================
include(Install)
# ============================================================================
# Build Summary
# ============================================================================
include(PrintSummary)