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
373 lines (318 loc) · 12.8 KB
/
CMakeLists.txt
File metadata and controls
373 lines (318 loc) · 12.8 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
# ============================================================================
# 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 helper functions early
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)
if(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/custom")
message(STATUS "QGC: Custom build directory detected")
set(QGC_CUSTOM_BUILD ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/custom/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
# ----------------------------------------------------------------------------
if(APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "${QGC_CONFIG_MACOS_DEPLOYMENT_TARGET}" CACHE STRING "macOS minimum deployment target")
# iOS builds: set(CMAKE_OSX_SYSROOT "iphoneos")
if(QGC_MACOS_UNIVERSAL_BUILD)
# Universal binary for both Intel and Apple Silicon
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)
# ----------------------------------------------------------------------------
# Toolchain Configuration (Compiler, Linker, Build Settings)
# ----------------------------------------------------------------------------
include(Toolchain)
# ----------------------------------------------------------------------------
# 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)
# ============================================================================
# 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
Charts
Concurrent
Core
Core5Compat
Gui
HttpServer
LinguistTools
Location
LocationPrivate
Multimedia
Network
Positioning
Qml
QmlIntegration
Quick
QuickControls2
QuickWidgets
Sensors
Sql
Svg
TextToSpeech
Widgets
Xml
Quick3D
StateMachine
OPTIONAL_COMPONENTS
Bluetooth
MultimediaQuickPrivate
OpenGL
QuickTest
SerialPort
Test
)
if(LINUX)
find_package(Qt6 ${QGC_QT_MINIMUM_VERSION}...${QGC_QT_MAXIMUM_VERSION} COMPONENTS WaylandClient)
endif()
qt_standard_project_setup(
REQUIRES ${QGC_QT_MINIMUM_VERSION}
SUPPORTS_UP_TO ${QGC_QT_MAXIMUM_VERSION}
I18N_SOURCE_LANGUAGE en
)
# ----------------------------------------------------------------------------
# QML Linting Configuration
# ----------------------------------------------------------------------------
if(QGC_ENABLE_QMLLINT)
set(QT_QML_GENERATE_QMLLINT ON CACHE BOOL "Enable automatic QML linting" FORCE)
else()
set(QT_QML_GENERATE_QMLLINT OFF CACHE BOOL "Disable automatic QML linting" FORCE)
endif()
# ----------------------------------------------------------------------------
# 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
)
# Disable QML cache generation in Debug builds across all targets.
add_compile_definitions($<$<CONFIG:Debug>:QT_QML_NO_CACHEGEN>)
# ============================================================================
# Custom Build Subdirectory
# ============================================================================
if(QGC_CUSTOM_BUILD)
add_subdirectory(custom)
endif()
# ============================================================================
# QGroundControl Resources
# ============================================================================
# Note: Resources added to executable (not library) to avoid needing Q_INIT_RESOURCE()
list(APPEND QGC_RESOURCES
"${CMAKE_SOURCE_DIR}/qgcimages.qrc"
"${CMAKE_SOURCE_DIR}/qgcresources.qrc"
"${CMAKE_SOURCE_DIR}/resources/InstrumentValueIcons/InstrumentValueIcons.qrc"
)
# ============================================================================
# QGroundControl Executable Target
# ============================================================================
# Create the main executable
qt_add_executable(${CMAKE_PROJECT_NAME}
WIN32 # Windows GUI application
MACOSX_BUNDLE # macOS application bundle
${QGC_RESOURCES}
)
# Apply optional sanitizer instrumentation to the main target.
include(Sanitizers)
# Apply optional coverage instrumentation and coverage targets.
include(Coverage)
# Apply compiler warning configuration to QGC target
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
# ----------------------------------------------------------------------------
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)
endif()
# ----------------------------------------------------------------------------
# Translation/Localization Configuration
# ----------------------------------------------------------------------------
file(GLOB TS_SOURCES "${CMAKE_SOURCE_DIR}/translations/qgc_*.ts")
set_source_files_properties(${TS_SOURCES} PROPERTIES OUTPUT_LOCATION "${CMAKE_BINARY_DIR}/i18n")
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}
# TS_FILES_OUTPUT_VARIABLE _ts_files_generated
# TS_OUTPUT_DIRECTORY "{CMAKE_SOURCE_DIR}/translations"
# 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
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)