-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
executable file
·498 lines (412 loc) · 19.1 KB
/
CMakeLists.txt
File metadata and controls
executable file
·498 lines (412 loc) · 19.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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
####################################################################################################################
## Autonomy Software ##
## 24.05.00 - Build 001 ##
## Mars Rover Design Team ##
## Copyright 2024 - All Rights Reserved ##
####################################################################################################################
## Set CMake Minimum Version
cmake_minimum_required(VERSION 3.24.3)
## Enforce Using GCC 10 / G++ 10
execute_process(
COMMAND gcc -dumpversion
OUTPUT_VARIABLE GCC_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GCC_VERSION VERSION_EQUAL "10.0")
message(FATAL_ERROR "Only GCC 10.0 is allowed! Detected GCC version ${GCC_VERSION}.")
endif()
## C++ and CUDA Version
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
## Project Name and Version
project(Autonomy_Software VERSION 24.05.00 LANGUAGES C CXX CUDA)
## CMake Policies
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "Suppress developer warnings")
####################################################################################################################
## Performance Enhancements ##
####################################################################################################################
## Use LLD linker if available to save RAM and time during the linking phase
if(NOT MSVC)
add_link_options("-fuse-ld=lld")
endif()
## Enable Unity Builds to drastically reduce memory usage during compilation
set(CMAKE_UNITY_BUILD ON)
set(CMAKE_UNITY_BUILD_BATCH_SIZE 8) # Adjust batch size based on project size. Lower is less RAM usage but longer compile times.
####################################################################################################################
## Options ##
####################################################################################################################
## Enable or Disable Simulation Mode
option(BUILD_SIM_MODE "Enable Simulation Mode" OFF)
## Enable or Disable Code Coverage Mode
option(BUILD_CODE_COVERAGE "Enable Code Coverage Mode" OFF)
## Enable or Disable Coverage Watch Mode
option(BUILD_COVERAGE_WATCH "Enable Code Coverage Watch Mode" OFF)
## Enable or Disable Verbose Makefile
option(BUILD_VERBOSE_MODE "Enable Verbose Makefile" OFF)
## Enable or Disable Tests Mode
option(BUILD_TESTS_MODE "Enable Tests Mode" OFF)
## Allow LiDAR/GeoPlanner unit tests (can require special data/env)
option(ENABLE_LIDAR_GEO_UTESTS "Enable unit tests in LidarHandler.cc and GeoPlanner.cc" OFF)
## Enable or Disable Examples Mode
option(BUILD_EXAMPLES_MODE "Enable Examples Mode" OFF)
## Enable or Disable ZED SDK Shared Linking Mode
option(LINK_SHARED_ZED "Link with the ZED SDK shared executable" ON)
## Enable or Disable RoveComm Cross-Compile Mode
option(RC_CROSS_COMPILE "Cross-Compile RoveComm for Windows and Linux" OFF)
## Enable or Disable Printing All CMake Variables
option(LIST_ALL_VARS "Print all CMake Variables" OFF)
####################################################################################################################
## Configuration Based on Options ##
####################################################################################################################
message("-- Autonomy System Options:")
## Simulation Mode
if (BUILD_SIM_MODE)
message("-- [x]: Sim Mode: Enabled")
add_compile_definitions(__AUTONOMY_SIM_MODE__=1)
set(EXE_NAME "${PROJECT_NAME}_Sim")
else()
message("-- [ ]: Sim Mode: Disabled")
add_compile_definitions(__AUTONOMY_SIM_MODE__=0)
set(EXE_NAME "${PROJECT_NAME}")
endif()
## Code Coverage Mode
if (BUILD_CODE_COVERAGE)
message("-- [x]: Code Coverage: Enabled")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -fprofile-arcs -ftest-coverage --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
else()
message("-- [ ]: Code Coverage: Disabled")
endif()
## Verbose Makefile
if (BUILD_VERBOSE_MODE)
message("-- [x]: Verbose Makefile: Enabled")
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "Verbose output" FORCE)
else()
message("-- [ ]: Verbose Makefile: Disabled")
endif()
## Build Unit and Integration Tests
if (BUILD_TESTS_MODE)
message("-- [x]: Build Unit and Integration Tests: Enabled")
include(CTest)
enable_testing()
else()
message("-- [ ]: Build Unit and Integration Tests: Disabled")
endif()
## Build Examples
if (BUILD_EXAMPLES_MODE)
message("-- [x]: Build Examples: Enabled")
else()
message("-- [ ]: Build Examples: Disabled")
endif()
## ZED SDK Shared Linking
if (LINK_SHARED_ZED)
message("-- [x]: ZED SDK Shared Linking: Enabled")
set(ZED_LIBS ${ZED_LIBRARIES} CUDA::toolkit)
else()
message("-- [ ]: ZED SDK Shared Linking: Disabled")
if (MSVC)
message(FATAL_ERROR "ZED SDK static libraries not available on Windows")
endif()
endif()
## RoveComm Cross-Compile
if (RC_CROSS_COMPILE)
message("-- [x]: RoveComm Cross-Compile: Enabled")
else()
message("-- [ ]: RoveComm Cross-Compile: Disabled")
set(BUILD_WIN OFF CACHE BOOL "Disable Windows Cross-Compile Mode for Autonomy Software" FORCE)
endif()
## Print All CMake Variables
if (LIST_ALL_VARS)
message("-- [x]: Print All CMake Variables: Enabled")
else()
message("-- [ ]: Print All CMake Variables: Disabled")
endif()
####################################################################################################################
## Dependencies and Libraries ##
####################################################################################################################
# Configure BSThreadPool
add_compile_definitions(BS_THREAD_POOL_ENABLE_PAUSE=1)
add_compile_definitions(BS_THREAD_POOL_ENABLE_PRIORITY=1)
add_compile_definitions(BS_THREAD_POOL_ENABLE_WAIT_DEADLOCK_CHECK=1)
## Find RoveComm
include_directories(external/rovecomm/src)
add_subdirectory(external/rovecomm)
add_compile_definitions(__ROVECOMM_LIBRARY_MODE__=1)
## Find Python3
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)
## Determine if shared or static libraries will be used.
if (NOT LINK_SHARED_ZED AND MSVC)
message(FATAL_ERROR "LINK_SHARED_ZED OFF : ZED SDK static libraries not available on Windows")
endif()
## Find Threads
find_package(Threads REQUIRED)
## Find OpenMP
find_package(OpenMP REQUIRED)
## Find OpenMS
find_package(OpenMS REQUIRED)
## Find SQLite3 (system)
find_package(SQLite3 REQUIRED)
## Find Quill
find_package(quill REQUIRED)
## Find LibDataChannel
find_package(LibDataChannel REQUIRED)
## Fine nlohmann JSON.
find_package(nlohmann_json 3.2.0 REQUIRED)
## Find OpenSSL
find_package(OpenSSL REQUIRED)
## Find FFMPEG.
find_package(PkgConfig REQUIRED)
pkg_check_modules(FFMPEG REQUIRED IMPORTED_TARGET libavcodec libavformat libavutil libswscale libswresample libavdevice libavfilter libpostproc SvtAv1Enc)
include_directories(${FFMPEG_INCLUDE_DIRS})
## Find MatPlotPlusPlus
find_package(Matplot++ REQUIRED)
## Find Google Test
find_package(GTest CONFIG REQUIRED)
include(GoogleTest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE gtest_main)
## Find Eigen3.
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
## Find OpenCV.
find_package(OpenCV REQUIRED)
## Find Geographic Lib.
find_package(GeographicLib REQUIRED)
## Find ZEDSDK. Add as system package to supress library warnings.
find_package(ZED 4 REQUIRED)
include_directories(SYSTEM ${ZED_INCLUDE_DIRS})
## Find CUDA. Must match ZEDSDK version. Add as system package to supress library warnings.
find_package(CUDAToolkit ${ZED_CUDA_VERSION} REQUIRED)
include_directories(SYSTEM ${CUDAToolkit_INCLUDE_DIRS})
## Find PyTorch.
set(CAFFE2_USE_CUDNN "1")
set(TORCH_CUDA_ARCH_LIST "8.0 8.6 8.9 9.0")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
## Find flatbuffers. This is a dependency of tensorflow.
find_package(Flatbuffers REQUIRED)
## Find Abseil. This is a dependency of tensorflow.
find_package(absl REQUIRED)
set(ABSL_LIBRARY_DIRS absl::algorithm
absl::base
absl::debugging
absl::flat_hash_map
absl::flags
absl::memory
absl::meta
absl::numeric
absl::random_random
absl::strings
absl::synchronization
absl::time
absl::utility
)
## Find TensorflowLite.
find_package(TENSORFLOWLITE REQUIRED PATHS "external/tensorflow/")
include_directories(SYSTEM ${TENSORFLOWLITE_INCLUDE_DIRS})
## Find Libedgetpu. This is used for interfacing with all Coral devices.
find_package(LIBEDGETPU REQUIRED PATHS "external/tensorflow/")
include_directories(SYSTEM ${LIBEDGETPU_INCLUDE_DIRS})
## Find OpenMPI. This is needed by PCL.
find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
## Fine PointCloudLibrary.
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
## Define libraries for ZED. Optionally static or dynamic.
if (LINK_SHARED_ZED)
set(ZED_LIBS ${ZED_LIBRARIES} CUDA::toolkit)
else()
set(ZED_LIBS ${ZED_LIBRARIES_STATIC_RELEASE} CUDA::toolkit)
endif()
## Add special flag if compiling on aarch64.
if (CMAKE_SYSTEM_PROCESSOR MATCHES aarch64)
add_definitions(-DJETSON_STYLE)
endif()
## Check if all variables should be listed.
if (LIST_ALL_VARS)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endif()
####################################################################################################################
## Build Executable ##
####################################################################################################################
## Search Project Directories for CPP Files
file(GLOB_RECURSE SRC CONFIGURE_DEPENDS "src/*.cpp")
file(GLOB_RECURSE Examples_SRC CONFIGURE_DEPENDS "examples/*/*.cpp")
file(GLOB_RECURSE External_SRC CONFIGURE_DEPENDS "external/src/*.cpp")
if (BUILD_EXAMPLES_MODE)
add_executable(${EXE_NAME} ${External_SRC} ${SRC} ${Examples_SRC} ${Tools_SRC})
else()
add_executable(${EXE_NAME} ${External_SRC} ${SRC} ${Tools_SRC})
endif()
## Compile Options
if (MSVC)
target_compile_options(${EXE_NAME} PRIVATE /W4 /WX)
else()
target_compile_options(${EXE_NAME} PRIVATE -Wall -Wextra -Wpedantic)
endif()
## Link Libraries
set(AUTONOMY_LIBRARIES Threads::Threads
OpenMP::OpenMP_CXX
SQLite::SQLite3
OpenMS
Eigen3::Eigen
RoveComm_CPP
Python3::Python
quill::quill
${OPENSSL_LIBRARIES}
PkgConfig::FFMPEG
LibDataChannel::LibDataChannel
nlohmann_json::nlohmann_json
Matplot++::matplot
${OpenCV_LIBS}
${GeographicLib_LIBRARIES}
${ZED_LIBS}
${TORCH_LIBRARIES}
flatbuffers::flatbuffers
${ABSL_LIBRARY_DIRS}
${TENSORFLOWLITE_LIBS}
${LIBEDGETPU_LIBS}
${MPI_LIBRARIES}
${PCL_LIBRARIES}
gcov
)
target_link_libraries(${EXE_NAME} PRIVATE ${AUTONOMY_LIBRARIES})
# Add a precompiled header for the heaviest libraries to vastly reduce RAM usage
target_precompile_headers(${EXE_NAME} PRIVATE
<vector>
<string>
<memory>
<Eigen/Dense>
<pcl/point_cloud.h>
<pcl/point_types.h>
<torch/torch.h>
<opencv2/opencv.hpp>
)
####################################################################################################################
## Installation and Tests ##
####################################################################################################################
## Tests Mode
if (BUILD_TESTS_MODE)
## Find Unit and Integration Tests
file(GLOB_RECURSE UTests_SRC CONFIGURE_DEPENDS "tests/Unit/src/*.cc")
file(GLOB_RECURSE ITests_SRC CONFIGURE_DEPENDS "tests/Integration/src/*.cc")
file(GLOB Runner_SRC CONFIGURE_DEPENDS "tests/main.cc")
## Find Source Files Required for Tests
file(GLOB_RECURSE TEST_SRC CONFIGURE_DEPENDS "src/*.cpp")
# Remove main.cpp from test compilation to avoid duplicate main function
list(REMOVE_ITEM TEST_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
list(LENGTH UTests_SRC UnitTests_LEN)
list(LENGTH ITests_SRC IntegrationTests_LEN)
string(TIMESTAMP CURRENT_TIMESTAMP "%Y%m%d-%H%M%S")
message("-- Current Timestamp: ${CURRENT_TIMESTAMP}")
if (UnitTests_LEN GREATER 0)
if (NOT ENABLE_LIDAR_GEO_UTESTS)
message("-- [ ]: LiDAR/GeoPlanner Unit Tests: Disabled (LiDARHandler.cc, GeoPlanner.cc)")
list(FILTER UTests_SRC EXCLUDE REGEX ".*/(LiDARHandler|GeoPlanner)\\.cc$")
else()
message("-- [x]: LiDAR/GeoPlanner Unit Tests: Enabled")
endif()
add_executable(${EXE_NAME}_UnitTests ${Runner_SRC} ${UTests_SRC} ${TEST_SRC})
target_link_libraries(${EXE_NAME}_UnitTests GTest::gtest GTest::gtest_main ${AUTONOMY_LIBRARIES})
# Apply precompiled headers to Unit Tests
target_precompile_headers(${EXE_NAME}_UnitTests PRIVATE
<vector>
<string>
<memory>
<Eigen/Dense>
<pcl/point_cloud.h>
<pcl/point_types.h>
<torch/torch.h>
<opencv2/opencv.hpp>
)
foreach(test_file ${UTests_SRC})
get_filename_component(test_name ${test_file} NAME_WE)
add_test(NAME UTest_${test_name} COMMAND ${EXE_NAME}_UnitTests --gtest_filter=${test_name}Test*.* --timestamp=${CURRENT_TIMESTAMP})
set_tests_properties(UTest_${test_name} PROPERTIES LABELS "UTest")
endforeach()
else()
message("No Unit Tests!")
endif()
if (IntegrationTests_LEN GREATER 0)
add_executable(${EXE_NAME}_IntegrationTests ${Runner_SRC} ${ITests_SRC} ${TEST_SRC})
target_link_libraries(${EXE_NAME}_IntegrationTests GTest::gtest GTest::gtest_main ${AUTONOMY_LIBRARIES})
# Apply precompiled headers to Integration Tests
target_precompile_headers(${EXE_NAME}_IntegrationTests PRIVATE
<vector>
<string>
<memory>
<Eigen/Dense>
<pcl/point_cloud.h>
<pcl/point_types.h>
<torch/torch.h>
<opencv2/opencv.hpp>
)
foreach(test_file ${ITests_SRC})
get_filename_component(test_name ${test_file} NAME_WE)
add_test(NAME ITest_${test_name} COMMAND ${EXE_NAME}_IntegrationTests --gtest_filter=${test_name}Test*.* --timestamp=${CURRENT_TIMESTAMP})
set_tests_properties(ITest_${test_name} PROPERTIES LABELS "iTest")
endforeach()
else()
message("No Integration Tests!")
endif()
# Add these near your other options
set(COVERAGE_EXCLUDES "external/;examples/;tests/;tools/;src/states/;src/handlers/;src/interfaces;src/vision" CACHE STRING "Directories to exclude from coverage")
# Then modify the run_coverage target to use these variables
if (BUILD_CODE_COVERAGE AND BUILD_COVERAGE_WATCH)
# Create separate exclude arguments for gcovr
set(GCOVR_EXCLUDE_ARGS "")
foreach(EXCLUDE_DIR ${COVERAGE_EXCLUDES})
list(APPEND GCOVR_EXCLUDE_ARGS --exclude)
list(APPEND GCOVR_EXCLUDE_ARGS ".*/${EXCLUDE_DIR}.*")
endforeach()
# Build lcov exclude arguments properly
set(LCOV_EXCLUDE_ARGS "--remove")
list(APPEND LCOV_EXCLUDE_ARGS "coverage_raw.info")
list(APPEND LCOV_EXCLUDE_ARGS "/usr/include/*")
foreach(EXCLUDE_DIR ${COVERAGE_EXCLUDES})
list(APPEND LCOV_EXCLUDE_ARGS "*/${EXCLUDE_DIR}/*")
endforeach()
add_custom_target(run_coverage ALL
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
COMMAND gcovr --root ${CMAKE_SOURCE_DIR} --xml-pretty --output Coverage.xml ${GCOVR_EXCLUDE_ARGS}
COMMAND lcov -c -d . -o coverage_raw.info
COMMAND lcov ${LCOV_EXCLUDE_ARGS} -o coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Running tests and generating coverage reports..."
VERBATIM
)
# Ensure dependencies for the run_coverage target. Tests must be built first.
if (UnitTests_LEN GREATER 0 AND IntegrationTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_UnitTests ${EXE_NAME}_IntegrationTests)
elseif (UnitTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_UnitTests)
elseif (IntegrationTests_LEN GREATER 0)
add_dependencies(run_coverage ${EXE_NAME}_IntegrationTests)
else()
message("No Tests to Run! run_coverage target will not be created.")
set_target_properties(run_coverage PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()
endif()
endif()
####################################################################################################################
## Final Build Configuration ##
####################################################################################################################
message("-- Final Autonomy Software Configuration Summary")
message("-- Executable Name: ${EXE_NAME}")
message("-- Simulation Mode: ${BUILD_SIM_MODE}")
message("-- Tests Mode: ${BUILD_TESTS_MODE}")
message("-- Examples Mode: ${BUILD_EXAMPLES_MODE}")
message("-- Code Coverage Mode: ${BUILD_CODE_COVERAGE}")
message("-- Verbose Makefile: ${BUILD_VERBOSE_MODE}")
message("-- ZED SDK Shared Linking Mode: ${LINK_SHARED_ZED}")