-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
208 lines (171 loc) · 6.88 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
# SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors
# SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
cmake_policy(VERSION 3.21)
cmake_minimum_required(VERSION 3.26)
if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
endif()
set(SWIFT_LANGUAGES C CXX)
if(APPLE)
list(APPEND SWIFT_LANGUAGES OBJC OBJCXX)
endif()
project(swift LANGUAGES ${SWIFT_LANGUAGES})
include(cmake/tools.cmake)
include(cmake/pch_config.cmake)
include(CMakeDependentOption)
get_version_number()
configure_target_platform()
# CMake config
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/lib)
# Build related options
option(SWIFT_BUILD_SAMPLES "Build samples" ON)
option(SWIFT_BUILD_UNIT_TESTS "Build unit tests" ON)
option(SWIFT_BUILD_DOCUMENTATION "Build documentation" ON)
cmake_dependent_option(SWIFT_BUILD_FS9_PLUGIN "Build FS9 plugin" ON SWIFT_WIN32 OFF)
cmake_dependent_option(SWIFT_BUILD_FSX_PLUGIN "Build FSX plugin" ON SWIFT_WIN32 OFF)
cmake_dependent_option(SWIFT_BUILD_P3D_PLUGIN "Build P3D plugin" ON WIN32 OFF)
option(SWIFT_BUILD_XPLANE_PLUGIN "Build X-Plane plugin" ON)
cmake_dependent_option(SWIFT_BUILD_XSWIFTBUS "Build xswiftbus" ON "NOT SWIFT_WIN32" OFF)
option(SWIFT_BUILD_FLIGHTGEAR_PLUGIN "Build Flightgear plugin" ON)
option(SWIFT_BUILD_EMULATED_PLUGIN "Build Emulated plugin" ON)
cmake_dependent_option(SWIFT_BUILD_MSFS_PLUGIN "Build MSFS plugin" ON WIN32 OFF)
option(SWIFT_MINIFY_DEBUG_SYMBOLS "Minify debug symbols" OFF)
option(SWIFT_BUILD_CORE "Build Core" ON)
option(SWIFT_BUILD_SOUND "Build Sound" ON)
option(SWIFT_BUILD_INPUT "Build Input" ON)
option(SWIFT_BUILD_GUI "Build GUI" ON)
option(SWIFT_USE_CRASHPAD "Use crashpad" OFF)
# VATSIM related options
option(SWIFT_VATSIM_SUPPORT "Build with VATSIM support" ON)
set(VATSIM_KEY_JSON "" CACHE STRING "Path to JSON containing VATSIM key")
load_vatsim_key()
if(SWIFT_VATSIM_SUPPORT)
add_compile_definitions(SWIFT_VATSIM_SUPPORT)
endif()
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "CMAKE_BUILD_TYPE not defined. Falling back to Debug")
set(CMAKE_BUILD_TYPE Debug)
endif()
if(SWIFT_MINIFY_DEBUG_SYMBOLS)
if(MSVC)
add_link_options(/OPT:REF /OPT:ICF)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
add_compile_options(-g1 -gz)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang")
add_compile_options(-gline-tables-only)
endif()
endif()
if(MSVC)
# This also installs some dlls which we do not need
# but our script to create the installer does not pack them.
# Further they are removed with cleanup.cmake
# see https://gitlab.kitware.com/cmake/cmake/-/issues/17725
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION vcredist)
include(InstallRequiredSystemLibraries)
if (SWIFT_WIN32)
install(FILES ${MSVC_REDIST_DIR}/vc_redist.x86.exe DESTINATION vcredist)
else()
install(FILES ${MSVC_REDIST_DIR}/vc_redist.x64.exe DESTINATION vcredist)
endif()
endif()
# Find dependencies
find_package(Qt6 REQUIRED COMPONENTS Core DBus Gui Multimedia Network OpenGL Concurrent Xml Qml Widgets Svg Test Core5Compat)
# Global compiler options
if(MSVC)
add_compile_options(/W3 /w34100 /w34189 /wd4661)
# https://doc.qt.io/qt-6/qt-disable-unicode-defines.html
add_compile_definitions(UNICODE)
add_compile_definitions(_UNICODE)
add_compile_options(/utf-8)
add_compile_options(/permissive-)
add_compile_options(/Zc:lambda)
# Workaround C1128 error
add_compile_options(/bigobj)
# Debug iterators used by Qt 5
add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
add_compile_options(-Wall -Wextra)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Woverloaded-virtual;-Wzero-as-null-pointer-constant;-Wsuggest-override>")
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES ".*Clang")
add_compile_options(-Wall -Wextra)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX,OBJCXX>:-Woverloaded-virtual;-Wzero-as-null-pointer-constant;-Wno-return-std-move>")
endif()
add_compile_definitions(QT_NO_DEPRECATED_WARNINGS)
if(SWIFT_USE_CRASHPAD)
add_compile_definitions(SWIFT_USE_CRASHPAD)
endif()
if(APPLE)
set(CMAKE_INSTALL_RPATH @loader_path/../../../../lib)
elseif(UNIX)
set(CMAKE_INSTALL_RPATH \$ORIGIN/../lib)
endif()
if(UNIX AND NOT APPLE AND ${CMAKE_BUILD_TYPE} STREQUAL Debug)
# For swift::misc::getStackTrace
add_link_options(-rdynamic)
endif()
if(MSVC)
set(CMAKE_DEBUG_POSTFIX d)
endif()
# Add external folders
add_subdirectory(cmake/vatsimauth)
add_subdirectory(cmake/dbus)
add_subdirectory(cmake/sodium)
add_subdirectory(cmake/opus)
add_subdirectory(cmake/crashpad)
add_subdirectory(cmake/simconnect)
add_subdirectory(cmake/dplay)
add_subdirectory(third_party)
if(SWIFT_BUILD_XSWIFTBUS)
add_subdirectory(cmake/xp)
add_subdirectory(cmake/event)
endif()
# Add source folders
add_subdirectory(src)
add_subdirectory(resources)
if(SWIFT_BUILD_UNIT_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(SWIFT_BUILD_SAMPLES)
add_subdirectory(samples)
endif()
if(SWIFT_BUILD_DOCUMENTATION)
add_custom_target(documentation env DOXY_SRC_ROOT=${swift_SOURCE_DIR} doxygen Doxyfile WORKING_DIRECTORY ${swift_SOURCE_DIR}/docs)
endif()
include(cmake/install.cmake)
if(MSVC)
install(SCRIPT ${PROJECT_SOURCE_DIR}/cmake/cleanup.cmake)
endif()
# Copy externals to build directory to allow running swift and tests
# TODO This should be put into the corresponding targets responsible for these files and may use TARGET_RUNTIME_DLLS
if(WIN32)
add_custom_target(copy_externals_to_build_dir)
if(SWIFT_WIN32)
set(ARCH_DIR 32)
elseif(SWIFT_WIN64)
set(ARCH_DIR 64)
endif()
add_custom_command(TARGET copy_externals_to_build_dir
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different third_party/externals/win32-msvc/${ARCH_DIR}/bin ${PROJECT_BINARY_DIR}/out/bin
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(TARGET copy_externals_to_build_dir
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different third_party/externals/win32-msvc/${ARCH_DIR}/lib ${PROJECT_BINARY_DIR}/out/bin
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()
message(STATUS "Simulators:")
message(STATUS "\t FS9: ${SWIFT_BUILD_FS9_PLUGIN}")
message(STATUS "\t FSX: ${SWIFT_BUILD_FSX_PLUGIN}")
message(STATUS "\t P3D: ${SWIFT_BUILD_P3D_PLUGIN}")
message(STATUS "\t MSFS: ${SWIFT_BUILD_MSFS_PLUGIN}")
message(STATUS "\t XPLANE: ${SWIFT_BUILD_XPLANE_PLUGIN}")
message(STATUS "\t XSWIFTBUS: ${SWIFT_BUILD_XPLANE_PLUGIN}")
message(STATUS "\t FLIGHTGEAR: ${SWIFT_BUILD_FLIGHTGEAR_PLUGIN}")
message(STATUS "\t EMULATED: ${SWIFT_BUILD_EMULATED_PLUGIN}")