[Development] ROS2 Colcon cheat sheet - cpslabor-education/robotwiki GitHub Wiki
ROS 2 Colcon build reference
Adding library
Use the following snippet in your packages's CMakeLists.txt:
add_library(${PROJECT_NAME} SHARED
src/library.cpp
src/library2.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(
${PROJECT_NAME}
YOUR_DEPENDENCIES_HERE
)
Add unit tests
Add GTest as the following:
find_package(ament_cmake_gtest REQUIRED)
ament_add_gtest(test_${PROJECT_NAME} test/test_1.cpp)
ament_target_dependencies(test_${PROJECT_NAME} rclcpp)
In case you built a link, you can link it as the following:
target_link_libraries(test_${PROEJCT_NAME} ${PROJECT_NAME})
Add Eigen to your project
Add Eigen to the project:
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
Use only one thread on build
Build package on ONE thread (ROS 2 Foxy):
MAKEFLAGS="-j1 -l1" colcon build --executor sequential
Explicitly enable colcon debug output
colcon build --event-handlers console_direct+