forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
349 lines (293 loc) · 10.7 KB
/
Copy pathCMakeLists.txt
File metadata and controls
349 lines (293 loc) · 10.7 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
# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL " ${CMAKE_CURRENT_BINARY_DIR}")
message(
FATAL_ERROR
"
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
"
)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Windows SDK version checks
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(sdk_minimum 10.0.18362.0)
# If no CMAKE_SYSTEM_VERSION is set, warn the user and set a default
# If it's set but below the defined minimum, warn the user but don't change it
if(NOT DEFINED CMAKE_SYSTEM_VERSION)
message(WARNING "No CMAKE_SYSTEM_VERSION set, defaulting to ${sdk_minimum}")
set(CMAKE_SYSTEM_VERSION "${sdk_minimum}" CACHE STRING "Windows SDK target")
elseif(CMAKE_SYSTEM_VERSION VERSION_LESS sdk_minimum)
message(
WARNING
"Current Windows SDK target ${CMAKE_SYSTEM_VERSION} is below the recommended"
"minimum target of ${sdk_minimum}. Some features may be limited or unavailable."
"If this is incorrect, you may need to manually set CMAKE_SYSTEM_VERSION"
"to a higher target."
)
endif()
endif()
# Set default build type to release with debug info (i.e. release mode optimizations
# are performed, but debug info still exists).
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
cmake_minimum_required(VERSION 3.21)
project(allwpilib)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# Make timestamps of extracted files from FetchContent the time of extraction
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
set(WPILIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
include(CMakeDependentOption)
include(CPack)
include(OptionValidation)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
if(MSVC)
add_compile_options(/Zc:__cplusplus)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${WPILIB_BINARY_DIR}/bin)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Options for building certain parts of the repo. Everything is built by default.
option(BUILD_SHARED_LIBS "Build with shared libs" ON)
option(WPILIB_WITH_DOCS "Build Doxygen docs (needs Git for versioning)" OFF)
cmake_dependent_option(
DOCS_WARNINGS_AS_ERRORS
"Make docs warnings into errors"
OFF
WPILIB_WITH_DOCS
OFF
)
option(WPILIB_WITH_CSCORE "Build cscore (needs OpenCV)" ON)
option(WPILIB_WITH_NTCORE "Build ntcore" ON)
option(WPILIB_WITH_WPICAL "Build wpical" OFF)
option(WPILIB_WITH_WPIMATH "Build wpimath" ON)
option(WPILIB_WITH_WPILIB "Build hal, wpilibc/j, and developerRobot (needs OpenCV)" ON)
option(WPILIB_WITH_EXAMPLES "Build examples" OFF)
option(WPILIB_WITH_TESTS "Build unit tests (requires internet connection)" ON)
option(WPILIB_WITH_GUI "Build GUI items (needs SDL3)" OFF)
cmake_dependent_option(
WPILIB_WITH_FIELDS
"Build the fields target"
OFF
"NOT WPILIB_WITH_GUI;NOT WPILIB_WITH_EXAMPLES"
ON
)
option(WPILIB_WITH_SIMULATION_MODULES "Build simulation modules" ON)
option(WPILIB_WITH_BENCHMARK "Build the benchmark project" ON)
# Options for using a package manager (e.g., vcpkg) for certain dependencies.
option(WPILIB_USE_SYSTEM_EIGEN "Use system Eigen" OFF)
option(WPILIB_USE_SYSTEM_LIBUV "Use system libuv" OFF)
option(WPILIB_USE_SYSTEM_SLEIPNIR "Use system Sleipnir" OFF)
option(WPILIB_USE_LINKED_AVAHI "Use directly linked Avahi instead of loading at runtime" OFF)
# Options for compilation flags.
option(WPILIB_NO_WERROR "Disable -Werror flag during compilation" OFF)
wpilib_config(
OPTIONS WPILIB_WITH_SIMULATION_MODULES
REQUIRES BUILD_SHARED_LIBS WPILIB_WITH_WPILIB WPILIB_WITH_NTCORE
)
wpilib_config(OPTIONS WPILIB_WITH_CSCORE REQUIRES WPILIB_WITH_NTCORE)
wpilib_config(OPTIONS WPILIB_WITH_GUI REQUIRES WPILIB_WITH_NTCORE WPILIB_WITH_WPIMATH)
wpilib_config(OPTIONS WPILIB_WITH_WPILIB REQUIRES WPILIB_WITH_NTCORE WPILIB_WITH_WPIMATH)
wpilib_config(OPTIONS WPILIB_WITH_FIELDS REQUIRES WPILIB_WITH_WPIMATH)
set(include_dest include)
if(WPILIB_WITH_DOCS)
find_package(Doxygen REQUIRED)
find_package(Git REQUIRED)
include(AddDoxygenDocs)
add_doxygen_docs()
endif()
find_package(LIBSSH CONFIG 0.7.1)
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
if(NOT "Asan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Asan)
endif()
if(NOT "Tsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Tsan)
endif()
if(NOT "Ubsan" IN_LIST CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Ubsan)
endif()
else()
set(allowedBuildTypes
Asan
Tsan
Ubsan
Debug
Release
RelWithDebInfo
MinSizeRel
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${allowedBuildTypes}")
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE IN_LIST allowedBuildTypes)
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()
set(CMAKE_C_FLAGS_ASAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C compiler for Asan build type or configuration."
FORCE
)
set(CMAKE_CXX_FLAGS_ASAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C++ compiler for Asan build type or configuration."
FORCE
)
set(CMAKE_EXE_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address"
CACHE STRING
"Linker flags to be used to create executables for Asan build type."
FORCE
)
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address"
CACHE STRING
"Linker flags to be used to create shared libraries for Asan build type."
FORCE
)
set(CMAKE_C_FLAGS_TSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C compiler for Tsan build type or configuration."
FORCE
)
set(CMAKE_CXX_FLAGS_TSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=thread -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C++ compiler for Tsan build type or configuration."
FORCE
)
set(CMAKE_EXE_LINKER_FLAGS_TSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread"
CACHE STRING
"Linker flags to be used to create executables for Tsan build type."
FORCE
)
set(CMAKE_SHARED_LINKER_FLAGS_TSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=thread"
CACHE STRING
"Linker flags to be used to create shared libraries for Tsan build type."
FORCE
)
set(CMAKE_C_FLAGS_UBSAN
"${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C compiler for Ubsan build type or configuration."
FORCE
)
set(CMAKE_CXX_FLAGS_UBSAN
"${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer"
CACHE STRING
"Flags used by the C++ compiler for Ubsan build type or configuration."
FORCE
)
set(CMAKE_EXE_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined -fno-sanitize-recover=all"
CACHE STRING
"Linker flags to be used to create executables for Ubsan build type."
FORCE
)
set(CMAKE_SHARED_LINKER_FLAGS_UBSAN
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=undefined"
CACHE STRING
"Linker flags to be used to create shared libraries for Ubsan build type."
FORCE
)
if(WPILIB_WITH_TESTS)
enable_testing()
add_subdirectory(thirdparty/googletest)
include(GoogleTest)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/catch2/extras")
add_subdirectory(thirdparty/catch2)
include(Catch)
endif()
if(WPILIB_USE_SYSTEM_LIBUV)
set(LIBUV_SYSTEM_REPLACE "find_dependency(libuv CONFIG)")
endif()
if(WPILIB_USE_SYSTEM_EIGEN)
set(EIGEN_SYSTEM_REPLACE "find_package(Eigen3 CONFIG)")
endif()
set(FILENAME_DEP_REPLACE "get_filename_component(SELF_DIR \"$\{CMAKE_CURRENT_LIST_FILE\}\" PATH)")
set(SELF_DIR "$\{SELF_DIR\}")
set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
add_subdirectory(wpiutil)
if(WPILIB_WITH_NTCORE OR WPILIB_WITH_GUI OR WPILIB_WITH_WPILIB)
set(DATALOG_DEP_REPLACE "find_dependency(datalog)")
add_subdirectory(datalog)
endif()
if(WPILIB_WITH_NTCORE)
set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
set(WPINET_DEP_REPLACE "find_dependency(wpinet)")
add_subdirectory(wpinet)
add_subdirectory(ntcore)
endif()
if(WPILIB_WITH_WPIMATH)
set(WPIMATH_DEP_REPLACE "find_dependency(wpimath)")
add_subdirectory(wpimath)
endif()
if(WPILIB_WITH_FIELDS)
add_subdirectory(fields)
endif()
if(WPILIB_WITH_GUI)
find_package(SDL3 CONFIG REQUIRED)
add_subdirectory(thirdparty/imgui_suite)
add_subdirectory(wpigui)
add_subdirectory(glass)
add_subdirectory(tools/outlineviewer)
add_subdirectory(tools/sysid)
if(WPILIB_WITH_WPICAL)
add_subdirectory(tools/wpical)
endif()
if(LIBSSH_FOUND)
add_subdirectory(tools/datalogtool)
endif()
endif()
if(WPILIB_WITH_WPILIB OR WPILIB_WITH_SIMULATION_MODULES)
set(HAL_DEP_REPLACE "find_dependency(hal)")
add_subdirectory(hal)
endif()
if(WPILIB_WITH_CSCORE)
set(CSCORE_DEP_REPLACE "find_dependency(cscore)")
find_package(OpenCV REQUIRED)
add_subdirectory(cscore)
endif()
if(WPILIB_WITH_WPILIB)
set(WPILIBC_DEP_REPLACE "find_dependency(wpilibc)")
set(COMMAND_DEP_REPLACE "find_dependency(commandsv2)")
add_subdirectory(apriltag)
add_subdirectory(wpilibc)
if(WPILIB_WITH_CSCORE)
add_subdirectory(cameraserver)
endif()
add_subdirectory(commandsv2)
add_subdirectory(romiVendordep)
add_subdirectory(xrpVendordep)
if(WPILIB_WITH_EXAMPLES)
add_subdirectory(wpilibcExamples)
endif()
add_subdirectory(developerRobot)
endif()
if(WPILIB_WITH_BENCHMARK)
add_subdirectory(benchmark)
endif()
if(WPILIB_WITH_SIMULATION_MODULES)
add_subdirectory(simulation)
endif()
configure_file(wpilib-config.cmake.in ${WPILIB_BINARY_DIR}/wpilib-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/wpilib-config.cmake DESTINATION share/wpilib)