Create a gist now

Instantly share code, notes, and snippets.

CMakeLists.txt example with catkin
cmake_minimum_required(VERSION 2.8.3)
project(foo)
# find dependencies
find_package(catkin REQUIRED COMPONENTS message_generation roscpp std_msgs)
find_package(Boost REQUIRED)
# message generation
add_message_files(
DIRECTORY msg
FILES MyMessage.msg
)
generate_messages(
DEPENDENCIES std_msgs
)
# export information to downstream packages
# must be called *before* the targets to generate them in the desired location in the devel space
catkin_package(
CATKIN_DEPENDS message_runtime std_msgs
CONFIG_EXTRAS "foo-extras.cmake"
DEPENDS Boost
)
# setup targets
include_directories(
include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
add_library(foo_lib src/lib.cpp)
target_link_libraries(foo_lib ${catkin_LIBRARIES})
add_executable(foo_bin src/bin.cpp)
add_dependencies(foo_bin foo_lib)
# 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(CATKIN_ENABLE_TESTING)
catkin_add_gtest(${PROJECT_NAME}_gtest test/my_test.cpp)
if(TARGET ${PROJECT_NAME}_gtest)
target_link_libraries(
${PROJECT_NAME}_gtest
${catkin_LIBRARIES}
)
endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment