|
| 1 | +cmake_minimum_required(VERSION 3.5) |
| 2 | + |
| 3 | +project(rclcpp_lifecycle) |
| 4 | + |
| 5 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 6 | + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++14") |
| 7 | + add_compile_options(-Wall -Wextra -Wpedantic) |
| 8 | +endif() |
| 9 | + |
| 10 | +find_package(ament_cmake REQUIRED) |
| 11 | +find_package(rclcpp REQUIRED) |
| 12 | +find_package(rcl_lifecycle REQUIRED) |
| 13 | +find_package(rmw_implementation_cmake REQUIRED) |
| 14 | +find_package(std_msgs REQUIRED) |
| 15 | +find_package(lifecycle_msgs REQUIRED) |
| 16 | + |
| 17 | +include_directories(include) |
| 18 | + |
| 19 | +macro(targets) |
| 20 | + get_rclcpp_information("${rmw_implementation}" "rclcpp${target_suffix}") |
| 21 | + get_rcl_lifecycle_information("${rmw_implementation}" "rcl_lifecycle${target_suffix}") |
| 22 | + |
| 23 | + ### CPP High level library |
| 24 | + add_library(rclcpp_lifecycle${target_suffix} |
| 25 | + SHARED |
| 26 | + src/lifecycle_node.cpp |
| 27 | + src/node_interfaces/lifecycle_node_interface.cpp |
| 28 | + src/state.cpp |
| 29 | + src/transition.cpp |
| 30 | + ) |
| 31 | + ament_target_dependencies(rclcpp_lifecycle${target_suffix} |
| 32 | + "rclcpp${target_suffix}" |
| 33 | + "rcl_lifecycle${target_suffix}" |
| 34 | + "lifecycle_msgs") |
| 35 | + |
| 36 | + # Causes the visibility macros to use dllexport rather than dllimport, |
| 37 | + # which is appropriate when building the dll but not consuming it. |
| 38 | + target_compile_definitions(rclcpp_lifecycle${target_suffix} PRIVATE "RCLCPP_LIFECYCLE_BUILDING_DLL") |
| 39 | + |
| 40 | + install(TARGETS |
| 41 | + rclcpp_lifecycle${target_suffix} |
| 42 | + ARCHIVE DESTINATION lib |
| 43 | + LIBRARY DESTINATION lib |
| 44 | + RUNTIME DESTINATION bin) |
| 45 | +endmacro() |
| 46 | + |
| 47 | +call_for_each_rmw_implementation(targets GENERATE_DEFAULT) |
| 48 | + |
| 49 | +if(BUILD_TESTING) |
| 50 | + find_package(ament_lint_auto REQUIRED) |
| 51 | + ament_lint_auto_find_test_dependencies() |
| 52 | + |
| 53 | + ament_add_gtest(test_lifecycle_node test/test_lifecycle_node.cpp) |
| 54 | + if(TARGET test_lifecycle_node) |
| 55 | + target_include_directories(test_lifecycle_node PUBLIC |
| 56 | + ${rcl_lifecycle_INCLUDE_DIRS} |
| 57 | + ${rclcpp_INCLUDE_DIRS} |
| 58 | + ${rclcpp_lifecycle_INCLUDE_DIRS} |
| 59 | + ) |
| 60 | + target_link_libraries(test_lifecycle_node ${PROJECT_NAME}) |
| 61 | + endif() |
| 62 | + ament_add_gtest(test_state_machine_info test/test_state_machine_info.cpp) |
| 63 | + if(TARGET test_state_machine_info) |
| 64 | + target_include_directories(test_state_machine_info PUBLIC |
| 65 | + ${rcl_lifecycle_INCLUDE_DIRS} |
| 66 | + ${rclcpp_INCLUDE_DIRS} |
| 67 | + ${rclcpp_lifecycle_INCLUDE_DIRS} |
| 68 | + ) |
| 69 | + target_link_libraries(test_state_machine_info ${PROJECT_NAME}) |
| 70 | + endif() |
| 71 | + ament_add_gtest(test_register_custom_callbacks test/test_register_custom_callbacks.cpp) |
| 72 | + if(TARGET test_register_custom_callbacks) |
| 73 | + target_include_directories(test_register_custom_callbacks PUBLIC |
| 74 | + ${rcl_lifecycle_INCLUDE_DIRS} |
| 75 | + ${rclcpp_INCLUDE_DIRS} |
| 76 | + ${rclcpp_lifecycle_INCLUDE_DIRS} |
| 77 | + ) |
| 78 | + target_link_libraries(test_register_custom_callbacks ${PROJECT_NAME}) |
| 79 | + endif() |
| 80 | + ament_add_gtest(test_callback_exceptions test/test_callback_exceptions.cpp) |
| 81 | + if(TARGET test_callback_exceptions) |
| 82 | + target_include_directories(test_callback_exceptions PUBLIC |
| 83 | + ${rcl_lifecycle_INCLUDE_DIRS} |
| 84 | + ${rclcpp_INCLUDE_DIRS} |
| 85 | + ${rclcpp_lifecycle_INCLUDE_DIRS} |
| 86 | + ) |
| 87 | + target_link_libraries(test_callback_exceptions ${PROJECT_NAME}) |
| 88 | + endif() |
| 89 | +endif() |
| 90 | + |
| 91 | +ament_export_dependencies(rclcpp) |
| 92 | +ament_export_dependencies(rcl_lifecycle) |
| 93 | +ament_export_dependencies(lifecycle_msgs) |
| 94 | +ament_export_include_directories(include) |
| 95 | +ament_export_libraries(${PROJECT_NAME}) |
| 96 | +ament_package() |
| 97 | + |
| 98 | +install(DIRECTORY include/ |
| 99 | + DESTINATION include) |
0 commit comments