forked from umrover/mrover-ros2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
294 lines (235 loc) · 10.8 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
cmake_minimum_required(VERSION 3.25)
project(mrover VERSION 2025.0.0 LANGUAGES C CXX)
# Supress ROS CMake warning about Python.
cmake_policy(SET CMP0148 OLD)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Generate compile_commands.json for clangd language server.
# Can be used by VSCode, CLion, VIM, etc.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(MROVER_CI "Enable CI options" OFF)
option(MROVER_CLANG_TIDY "Enable static analysis with Clang tidy" ${MROVER_CI})
option(MROVER_WARNINGS_AS_ERRORS "Treat warnings as errors" ${MROVER_CI})
if (APPLE)
# Ensures that homebrew packages are never used over miniforge packages.
set(CMAKE_IGNORE_PATH /opt/homebrew)
# Find mamba python
find_package(PythonLibs REQUIRED)
link_libraries(${PYTHON_LIBRARIES})
endif ()
if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Wno-deprecated-declarations)
if (MROVER_WARNINGS_AS_ERRORS)
message(STATUS "Treating warnings as errors")
add_compile_options(-Werror)
endif ()
if (NOT APPLE)
# Try to use LLD instead of the system linker (which is usually GNU ld).
# LLD is faster and uses less memory.
# Could look into using mold which should be even faster.
find_program(LLD_PROGRAM lld)
if (LLD_PROGRAM)
message(STATUS "Using lld linker")
add_link_options(-fuse-ld=lld-18)
endif()
endif ()
endif ()
# Ccache is a compiler cache.
# It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.
# It is global, so even if you delete the build directory, it will still work.
# This can cause problems in rare cases so run "ccache -C" to clear the cache.
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
set(CMAKE_C_COMPILER_LAUNCHER ccache)
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
set(CMAKE_CUDA_COMPILER_LAUNCHER ccache)
endif ()
## Dependencies
find_package(rclpy REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(urdf REQUIRED)
find_package(std_srvs REQUIRED)
find_package(Assimp NAMES Assimp assimp REQUIRED)
find_package(Bullet REQUIRED)
find_package(glfw3 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenCV REQUIRED)
if (NOT APPLE)
find_package(TBB REQUIRED)
link_libraries(TBB::tbb)
endif()
find_package(dawn QUIET)
if (dawn_FOUND)
message(STATUS "Using Dawn system install")
else ()
message(STATUS "Using Dawn from source")
add_library(webgpu SHARED IMPORTED)
set(WEBGPU_BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/deps/dawn/out/Release)
if (APPLE)
set(WEBGPU_SHARED_LIB ${WEBGPU_BUILD_DIR}/src/dawn/native/libwebgpu_dawn.dylib)
else ()
set(WEBGPU_SHARED_LIB ${WEBGPU_BUILD_DIR}/src/dawn/native/libwebgpu_dawn.so)
endif ()
if (EXISTS ${WEBGPU_SHARED_LIB})
target_include_directories(webgpu INTERFACE ${CMAKE_CURRENT_LIST_DIR}/deps/dawn/include ${WEBGPU_BUILD_DIR}/gen/include)
set_property(TARGET webgpu PROPERTY IMPORTED_LOCATION ${WEBGPU_SHARED_LIB})
set(dawn_FOUND TRUE)
else ()
message(WARNING "Dawn not found. If on Ubuntu install with 'sudo apt install -f ./pkg/libdawn-dev.deb'. Or build from source with ./scripts/build_dawn.sh")
endif ()
endif ()
find_package(manif QUIET)
if (NOT manif_FOUND)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/deps/manif/include/manif)
set(BUILD_TESTING_OLD ${BUILD_TESTING})
set(BUILD_TESTING OFF)
add_subdirectory(deps/manif EXCLUDE_FROM_ALL SYSTEM)
set(BUILD_TESTING ${BUILD_TESTING_OLD})
add_library(MANIF::manif ALIAS manif)
set(manif_FOUND TRUE)
else()
message(FATAL_ERROR "Manif not found. If on Ubuntu install with 'sudo apt install -f ./pkg/libmanif-dev.deb'. Or build from source with 'submodule update --init deps/manif' and make sure it is non-empty")
endif()
endif()
find_package(PkgConfig REQUIRED)
pkg_search_module(NetLink libnl-3.0 IMPORTED_TARGET QUIET)
pkg_search_module(NetLinkRoute libnl-route-3.0 IMPORTED_TARGET QUIET)
pkg_search_module(Gst gstreamer-1.0 IMPORTED_TARGET QUIET)
pkg_search_module(GstApp gstreamer-app-1.0 IMPORTED_TARGET QUIET)
pkg_search_module(LibUdev libudev IMPORTED_TARGET QUIET)
add_subdirectory(deps/imgui EXCLUDE_FROM_ALL SYSTEM)
add_subdirectory(deps/webgpuhpp EXCLUDE_FROM_ALL SYSTEM)
add_subdirectory(deps/glfw3webgpu EXCLUDE_FROM_ALL SYSTEM)
add_subdirectory(deps/mjbots EXCLUDE_FROM_ALL SYSTEM)
if (BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif ()
include_directories(BEFORE SYSTEM preload)
include(cmake/macros.cmake)
# include(cmake/deps.cmake)
## Messages & Services & Actions
file(GLOB_RECURSE MROVER_MESSAGE_FILE_PATHS RELATIVE ${CMAKE_CURRENT_LIST_DIR} CONFIGURE_DEPENDS msg/*.msg)
message(STATUS "Found message files: ${MROVER_MESSAGE_FILE_PATHS}")
file(GLOB_RECURSE MROVER_SERVICE_FILE_PATHS RELATIVE ${CMAKE_CURRENT_LIST_DIR} CONFIGURE_DEPENDS srv/*.srv)
message(STATUS "Found service files: ${MROVER_SERVICE_FILE_PATHS}")
# Starter Project
message(STATUS "PROJ NAME: ${PROJECT_NAME}")
set(MROVER_CMAKE_INCLUDES
starter_project/autonomy/AutonomyStarterProject.cmake
)
foreach (MROVER_CMAKE_INCLUDE ${MROVER_CMAKE_INCLUDES})
include(${MROVER_CMAKE_INCLUDE})
endforeach ()
message(STATUS "Found message files: ${MROVER_MESSAGE_FILE_PATHS}")
rosidl_generate_interfaces(${PROJECT_NAME}
${MROVER_MESSAGE_FILE_PATHS}
${MROVER_SERVICE_FILE_PATHS}
DEPENDENCIES nav_msgs sensor_msgs geometry_msgs
)
# Starter project
# TODO (ali): delete once AutonomyStarterProject.cmake is fixed
mrover_add_node(starter_project_perception ${CMAKE_CURRENT_LIST_DIR}/starter_project/autonomy/src/*.cpp)
target_link_libraries(starter_project_perception ${OpenCV_LIBS})
ament_target_dependencies(starter_project_perception rclcpp std_msgs sensor_msgs)
# Install our executable so that ROS knows about it
# This allows us to launch it with ros2 run
install(PROGRAMS
starter_project/autonomy/src/localization.py
starter_project/autonomy/src/navigation/navigation_starter_project.py
DESTINATION
lib/${PROJECT_NAME}
)
install(DIRECTORY starter_project/autonomy/launch DESTINATION share/${PROJECT_NAME})
## Python
ament_python_install_package(navigation)
ament_python_install_package(lie)
ament_python_install_package(state_machine)
## C++
# Libraries
include_directories(perception)
mrover_add_library(lie lie/*.cpp lie)
target_link_libraries(lie MANIF::manif)
ament_target_dependencies(lie rclcpp geometry_msgs tf2 tf2_ros)
mrover_add_header_only_library(units units)
mrover_add_header_only_library(loop_profiler loop_profiler)
# Simulator
mrover_add_node(simulator simulator/*.cpp simulator simulator/pch.hpp)
ament_target_dependencies(simulator rclcpp rclcpp_components nav_msgs sensor_msgs geometry_msgs tf2 tf2_ros urdf)
target_link_libraries(simulator
assimp::assimp glfw3webgpu webgpu glfw webgpu_hpp imgui
${BULLET_LIBRARIES}
lie Eigen3::Eigen
opencv_core opencv_imgcodecs opencv_imgproc
loop_profiler
)
target_include_directories(simulator SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS})
# Perception
mrover_add_node(tag_detector perception/tag_detector/*.cpp perception/tag_detector/pch.hpp)
ament_target_dependencies(tag_detector rclcpp tf2 tf2_ros)
target_link_libraries(tag_detector lie opencv_core opencv_aruco opencv_imgproc loop_profiler)
# Embedded
mrover_add_node(differential_drive_controller esw/differential_drive_controller.cpp)
target_link_libraries(differential_drive_controller units)
ament_target_dependencies(differential_drive_controller rclcpp)
mrover_add_node(arm_controller teleoperation/arm_controller/arm_controller.cpp teleoperation/arm_controller/pch.hpp)
target_link_libraries(arm_controller lie)
ament_target_dependencies(arm_controller rclcpp)
if (Gst_FOUND AND GstApp_FOUND)
mrover_add_node(usb_camera esw/usb_camera/*.cpp esw/usb_camera/pch.hpp)
target_link_libraries(usb_camera PkgConfig::Gst PkgConfig::GstApp opencv_core opencv_imgcodecs)
ament_target_dependencies(usb_camera rclcpp)
if (LibUdev_FOUND)
mrover_add_library(websocket_server esw/websocket_server/*.cpp esw/websocket_server)
target_compile_definitions(websocket_server PUBLIC BOOST_ASIO_NO_DEPRECATED)
ament_target_dependencies(websocket_server rclcpp)
mrover_add_component(gst_websocket_streamer esw/gst_websocket_streamer/*.c* esw/gst_websocket_streamer/pch.hpp)
target_link_libraries(gst_websocket_streamer PkgConfig::Gst PkgConfig::GstApp PkgConfig::LibUdev opencv_core opencv_imgcodecs websocket_server)
ament_target_dependencies(gst_websocket_streamer rclcpp rclcpp_components sensor_msgs)
rclcpp_components_register_nodes(gst_websocket_streamer "mrover::GstWebsocketStreamer")
set(node_plugins "${node_plugins}mrover::GstWebsocketStreamer;$<TARGET_FILE:gst_websocket_streamer>\n")
endif ()
endif ()
if (NetLink_FOUND AND NetLinkRoute_FOUND)
mrover_add_node(can_bridge esw/can_bridge/*.cpp esw/can_bridge/pch.hpp)
target_link_libraries(can_bridge PkgConfig::NetLink PkgConfig::NetLinkRoute)
ament_target_dependencies(can_bridge rclcpp)
endif ()
## Install
# You must add Python scripts here to be able to "ros2 launch" them in terminal
install(PROGRAMS
navigation/nav.py
navigation/stuck_detector/stuck_detector.py
localization/rover_gps_driver.py
localization/gps_linearization.py
localization/basestation_gps_driver.py
superstructure/superstructure.py
scripts/debug_course_publisher.py
scripts/visualizer.py
# starter project sources
starter_project/autonomy/src/localization.py
starter_project/autonomy/src/navigation/navigation_starter_project.py
DESTINATION
lib/${PROJECT_NAME}
)
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
install(DIRECTORY urdf DESTINATION share/${PROJECT_NAME})
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})
# install (DIRECTORY ${} DESTINATION lib/${PROJECT_NAME})
ament_package()