-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
376 lines (323 loc) · 11.7 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
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
cmake_minimum_required(VERSION 3.13) # Latest versions of Ubuntu should have at least 3.16;
# argparse library requires 3.12.4 currently
set(CMAKE_CXX_STANDARD 17) # 11 For the json library, 17 for std library features
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(Rover LANGUAGES CXX C)
include(FetchContent)
# If a build type was not explicitly specified, default to "RelWithDebInfo" (Same optimization
# as the "Release" configuration but with debugging symbols).
#
# To change, you can pass -DCMAKE_BUILD_TYPE=... where ... is the configuration you would like
# to use. For example, if you want to do a full debug build (little to no optimization, with
# debugging symbols), add -DCMAKE_BUILD_TYPE=Debug to your `cmake` command. You may want to do
# a full debug build if code you want to debug gets optimized out by the compiler.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The type of build to perform.")
set(AVAILABLE_BUILD_TYPES "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${AVAILABLE_BUILD_TYPES})
message("========================================\n\
Building ${CMAKE_BUILD_TYPE} configuration...\n\
Add -DCMAKE_BUILD_TYPE=... to change\n\
========================================")
# Generate a compile_commands.json file by default unless explicitly disabled.
# This allows editors like Visual Studio Code to be able to index the project correctly and
# locate header files and libraries.
if(NOT CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE STRING "Enable/Disable output of compile commands
during generation." FORCE)
endif()
##====== Module settings ======
# These variables control whether various modules are enabled or disabled. The goal is to allow
# a user to selectively exclude modules that they do not need.
set(GPS "ARDUPILOT" CACHE STRING "GPS interface to use.")
set(AVAILABLE_GPS "USB" "ARDUPILOT" "NONE")
set_property(CACHE GPS PROPERTY STRINGS ${AVAILABLE_GPS})
set(WITH_TESTS ON CACHE BOOL "Enable/Disable the tests.")
set(WORLD_INTERFACE "REAL" CACHE STRING "The world interface implementation to use.")
set(AVAILABLE_WORLD_INTERFACES "REAL" "SIMULATOR" "NO-OP")
set_property(CACHE WORLD_INTERFACE PROPERTY STRINGS ${AVAILABLE_WORLD_INTERFACES})
if(NOT WORLD_INTERFACE IN_LIST AVAILABLE_WORLD_INTERFACES)
message(FATAL_ERROR "Invalid value for WORLD_INTERFACE: ${WORLD_INTERFACE}\n\
Valid values are ${AVAILABLE_WORLD_INTERFACES}")
endif()
if(NOT GPS IN_LIST AVAILABLE_GPS)
message(FATAL_ERROR "Invalid value for GPS: ${GPS}\n\
Valid values are ${AVAILABLE_GPS}")
endif()
message("========================================\n\
Module settings:")
message(" GPS:\t\t\t${GPS}")
message(" Test Suite:\t\t${WITH_TESTS}")
message(" World Interface:\t${WORLD_INTERFACE}")
message("========================================")
##====== Dependencies ======
# Some of these are optional depending on module settings above.
# Get the Eigen linear algebra library. Eigen's CMake config includes its headers as user
# headers instead of system headers by default, so explicitly force them to be system includes
# here to avoid the compiler spamming warnings at us for stuff in the Eigen headers.
find_package(Eigen3 REQUIRED NO_MODULE)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
# Find the WebSocket++ library and Boost (provides the ASIO backend for Websocket++ and also
# provides the program_options argument parser). Only the `system` component of Boost is
# currently required.
find_package(websocketpp REQUIRED)
find_package(Boost REQUIRED COMPONENTS system)
# Find Frozen, library used for constexpr immutable containers
find_package(frozen REQUIRED)
# Frozen is just an interface library, only containing headers and some CMake settings. It
# should be fine to "link" the library to every target, since if the headers are not included,
# it will not have any effect on size or performance. This will help us not have to worry about
# making sure the headers are available in every file that includes Constants.h, for example.
link_libraries(frozen::frozen)
# Find argparse, library used for parsing command line arguments
find_package(argparse REQUIRED)
# Find the JSON library
find_package(nlohmann_json 3.2.0 REQUIRED)
# Find the CAN library; contains packet and protocol definitions and does not
# actually require physical CAN to be present.
FetchContent_Declare(
HindsightCAN
GIT_REPOSITORY https://github.com/huskyroboticsteam/HindsightCAN.git
GIT_TAG 45b1544f20e7ba6dd0db19fb97e947430031fc6a
)
FetchContent_MakeAvailable(HindsightCAN)
FetchContent_Declare(LoguruGitRepo
GIT_REPOSITORY "https://github.com/emilk/loguru"
GIT_TAG "master"
)
# set any loguru compile-time flags before calling MakeAvailable()
set(LOGURU_WITH_STREAMS TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru'
link_libraries(loguru::loguru -ldl)
find_package(Threads REQUIRED)
find_package(OpenCV REQUIRED)
if(WITH_TESTS)
find_package(Catch2 REQUIRED)
endif()
# Libraries needed to interface with real-life sensors. If we aren't using the real world
# interface, these aren't needed.
if(WORLD_INTERFACE STREQUAL "REAL")
if(GPS STREQUAL "USB")
# Find pkg-config (needed for libgps, as it doesn't have CMake configuration)
find_package(PkgConfig REQUIRED)
# Find the libgps USB GPS library.
pkg_check_modules(libgps REQUIRED libgps)
endif()
endif()
if(WITH_TESTS)
enable_testing()
endif()
add_library(camera SHARED
camera/Camera.cpp
camera/CameraParams.cpp
camera/CameraConfig.cpp
)
target_link_libraries(camera PUBLIC ${OpenCV_LIBS})
# shared library for utility code
add_library(utils SHARED
utils/core.cpp
utils/random.cpp
utils/ScopedTimer.cpp
utils/transform.cpp
utils/threading.cpp
utils/math.cpp
utils/json.cpp
gps/gps_util.cpp
base64/base64.cpp
base64/base64_img.cpp
kinematics/DiffDriveKinematics.cpp
kinematics/DiffWristKinematics.cpp
kinematics/SwerveDriveKinematics.cpp
world_interface/data.cpp)
target_link_libraries(utils ${OpenCV_LIBS})
## ====== CAN Interfaces =======
# Stub CAN interface is used for the tests (and for the Rover if
# CAN is disabled) and the real CAN interface is used for the Rover if CAN is
# enabled.
# Common CAN source files
# **DON'T MAKE THIS SHARED**
# Making this library shared causes some memory fuckery
# No clue why but CAN I/O goes to shit. Don't do it.
add_library(can_interface STATIC)
target_sources(can_interface PRIVATE
CAN/CANMotor.cpp
CAN/CANUtils.cpp
)
# Hardware specific source files
target_sources(can_interface PRIVATE
CAN/CAN.cpp)
target_link_libraries(can_interface PUBLIC
HindsightCAN
Threads::Threads
utils
)
## GPS Implementations
add_library(gps_interface STATIC)
if(GPS STREQUAL "USB")
target_sources(gps_interface PUBLIC gps/usb_gps/read_usb_gps.cpp)
target_link_libraries(gps_interface ${libgps_LIBRARIES})
elseif(GPS STREQUAL "ARDUPILOT")
target_sources(gps_interface PUBLIC
ardupilot/ArduPilotProtocol.cpp
ardupilot/ArduPilotInterface.cpp)
target_link_libraries(gps_interface utils websocket_utils)
else()
target_sources(gps_interface PUBLIC gps/dummy/dummy_gps.cpp)
endif()
## ====== World Interfaces =======
# hardware-agnostic utilities and common code for world interface
add_library(world_interface_core STATIC
world_interface/gps_common_interface.cpp
ar/Detector.cpp
ar/MarkerSet.cpp
ar/MarkerPattern.cpp
ar/Tag.cpp
ar/read_landmarks.cpp
world_interface/motor/base_motor.cpp
)
target_include_directories(world_interface_core SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(world_interface_core PUBLIC ${vision_libs} opencv_aruco ${OpenCV_LIBS} utils camera)
# CAN library (above) requires some utilities from this
target_link_libraries(can_interface PUBLIC utils)
add_library(stub_world_interface STATIC
world_interface/noop_world.cpp)
add_library(real_world_interface STATIC
world_interface/real_world_interface.cpp
world_interface/motor/can_motor.cpp
)
add_library(simulator_interface STATIC
world_interface/simulator_interface.cpp
world_interface/motor/sim_motor.cpp
)
target_link_libraries(real_world_interface gps_interface can_interface world_interface_core)
target_link_libraries(simulator_interface world_interface_core)
target_link_libraries(stub_world_interface world_interface_core)
if(WORLD_INTERFACE STREQUAL "REAL")
add_library(world_interface ALIAS real_world_interface)
elseif(WORLD_INTERFACE STREQUAL "SIMULATOR")
add_library(world_interface ALIAS simulator_interface)
else()
add_library(world_interface ALIAS stub_world_interface)
endif()
add_library(filters SHARED
filters/StateSpaceUtil.cpp
)
target_link_libraries(filters utils)
add_library(video STATIC
video/H264Encoder.cpp
video/encoder.cpp
)
target_link_libraries(video
${OpenCV_LIBS}
x264 avutil avcodec avformat swscale
)
add_library(control SHARED
control/TrapezoidalVelocityProfile.cpp
control/SwerveController.cpp
)
target_link_libraries(control utils)
add_library(commands SHARED
commands/DriveToWaypointCommand.cpp)
add_library(autonomous SHARED
autonomous/AutonomousTask.cpp)
target_link_libraries(autonomous commands world_interface)
add_library(constants SHARED Constants.cpp)
link_libraries(constants)
add_executable(Rover Rover.cpp)
# **DON'T MAKE THIS SHARED**
# Making this library shared causes some memory fuckery
# No clue why but CAN I/O goes to shit. Don't do it.
add_library(rover_common STATIC
Globals.cpp
control_interface.cpp
)
target_link_libraries(rover_common
utils
websocket_utils
world_interface
)
list(APPEND rover_libs
rover_common
Threads::Threads
websocket_utils
filters
control
commands
utils
)
target_link_libraries(Rover
${rover_libs}
mission_control_interface
world_interface
${vision_libs}
)
add_executable(TunePID TunePID.cpp)
target_link_libraries(TunePID
${rover_libs}
can_interface
)
target_link_libraries(TunePID ${vision_libs})
if(WITH_TESTS)
add_executable(tests
Tests.cpp
# AR Detection tests
ar/DetectorTests.cpp
ar/MarkerSetTests.cpp
# Camera tests
../tests/camera/CameraParamsTests.cpp
# GPS tests
../tests/gps/GPSDatumTest.cpp
../tests/gps/GPSConverterTest.cpp
# Controller tests
../tests/control/TrapezoidalVelocityProfileTest.cpp
../tests/control/JacobianControllerTest.cpp
../tests/control/PIDControllerTest.cpp
../tests/control/PlanarArmControllerTest.cpp
# Kinematics tests
../tests/kinematics/DiffDriveKinematicsTest.cpp
../tests/kinematics/SwerveDriveKinematicsTest.cpp
../tests/kinematics/PlanarArmFKTest.cpp
../tests/kinematics/FabrikSolver2DTest.cpp
# Filter tests
../tests/filters/RollingAvgFilterTest.cpp
../tests/filters/EKFTest.cpp
../tests/filters/MultiSensorEKFTest.cpp
../tests/filters/StateSpaceUtilsTest.cpp
# Command tests
../tests/commands/DriveToWaypointCommandTest.cpp
# Util tests
../tests/util/CoreTest.cpp
../tests/util/DataTest.cpp
../tests/util/MathTest.cpp
../tests/util/TimeTest.cpp
../tests/util/SchedulerTest.cpp
../tests/util/RandomTest.cpp
../tests/util/JsonTest.cpp
../tests/util/ThreadingTest.cpp
# Protocol/teleop tests
../tests/kinematics/DiffWristKinematicsTest.cpp)
target_link_libraries(tests
${rover_libs}
${OpenCV_LIBS})
include(CTest)
include(Catch)
target_link_libraries(tests Catch2::Catch2)
catch_discover_tests(tests)
endif()
add_executable(gpsd_test
gps/gpsd_test.cpp)
target_link_libraries(gpsd_test gps)
if (WORLD_INTERFACE STREQUAL "REAL")
add_executable(LimitSwitchCalibration
LimitCalib.cpp)
target_link_libraries(LimitSwitchCalibration real_world_interface)
endif()
add_compile_options(
-Wall
-Wextra
-Werror
)
add_subdirectory(ar)
add_subdirectory(camera)
add_subdirectory(CAN)
add_subdirectory(network)