Created
July 7, 2015 20:05
-
-
Save dirk-thomas/83ae6bfbfc94e06cd519 to your computer and use it in GitHub Desktop.
CMakeLists.txt example with ament
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8.3) | |
project(foo) | |
if(NOT WIN32) | |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") | |
endif() | |
# find dependencies | |
find_package(ament_cmake REQUIRED) | |
find_package(rclcpp REQUIRED) | |
find_package(rosidl_default_generators REQUIRED) | |
find_package(rmw_connext_cpp REQUIRED) | |
find_package(std_interfaces REQUIRED) | |
# message generation | |
rosidl_generate_interfaces( | |
${PROJECT_NAME}_msg-gen | |
msg/MyMessage.msg | |
) | |
# setup targets | |
include_directories( | |
include | |
${rclcpp_INCLUDE_DIRS} | |
${rmw_connext_cpp_INCLUDE_DIRS} | |
${std_interfaces_INCLUDE_DIRS} | |
) | |
add_library(foo_lib src/lib.cpp) | |
target_link_libraries(foo_lib ${rclcpp_LIBRARIES} ${rmw_connext_cpp_LIBRARIES} ${std_interfaces}) | |
add_executable(foo_bin src/bin.cpp) | |
add_dependencies(foo_bin foo_lib) | |
# export information to downstream packages | |
ament_export_dependencies( | |
rclcpp | |
std_interfaces | |
) | |
ament_export_include_directories(include) | |
ament_export_libraries(foo_lib) | |
# must be called *after* the targets to check exported libraries etc. | |
ament_package( | |
CONFIG_EXTRAS "foo-extras.cmake" | |
) | |
# install artifacts | |
install( | |
DIRECTORY cmake | |
DESTINATION share/${PROJECT_NAME} | |
) | |
install( | |
DIRECTORY include/ | |
DESTINATION include | |
) | |
install( | |
TARGETS foo_lib foo_bin | |
ARCHIVE DESTINATION lib | |
LIBRARY DESTINATION lib | |
RUNTIME DESTINATION bin | |
) | |
# tests | |
if(AMENT_ENABLE_TESTING) | |
find_package(ament_cmake_gtest REQUIRED) | |
ament_add_gtest(foo_gtest test/my_test.cpp) | |
target_link_libraries(foo_gtest ${rclcpp_LIBRARIES} ${rmw_connext_cpp_LIBRARIES} ${std_interfaces}) | |
endif() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment