|
| 1 | +cmake_minimum_required(VERSION 3.12) |
| 2 | + |
| 3 | +project(rclcpp) |
| 4 | + |
| 5 | +find_package(Threads REQUIRED) |
| 6 | + |
| 7 | +find_package(ament_cmake_ros REQUIRED) |
| 8 | +find_package(ament_index_cpp REQUIRED) |
| 9 | +find_package(builtin_interfaces REQUIRED) |
| 10 | +find_package(libstatistics_collector REQUIRED) |
| 11 | +find_package(rcl REQUIRED) |
| 12 | +find_package(rcl_interfaces REQUIRED) |
| 13 | +find_package(rcl_yaml_param_parser REQUIRED) |
| 14 | +find_package(rcpputils REQUIRED) |
| 15 | +find_package(rcutils REQUIRED) |
| 16 | +find_package(rmw REQUIRED) |
| 17 | +find_package(rosgraph_msgs REQUIRED) |
| 18 | +find_package(rosidl_runtime_cpp REQUIRED) |
| 19 | +find_package(rosidl_typesupport_c REQUIRED) |
| 20 | +find_package(rosidl_typesupport_cpp REQUIRED) |
| 21 | +find_package(statistics_msgs REQUIRED) |
| 22 | +find_package(tracetools REQUIRED) |
| 23 | + |
| 24 | +# TODO(wjwwood): remove this when gtest can build on its own, when using target_compile_features() |
| 25 | +# Default to C++17 |
| 26 | +if(NOT CMAKE_CXX_STANDARD) |
| 27 | + set(CMAKE_CXX_STANDARD 17) |
| 28 | +endif() |
| 29 | +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 30 | + # About -Wno-sign-conversion: With Clang, -Wconversion implies -Wsign-conversion. There are a number of |
| 31 | + # implicit sign conversions in rclcpp and gtest.cc, see https://ci.ros2.org/job/ci_osx/9265/. |
| 32 | + # Hence disabling -Wsign-conversion for now until all those have eventually been fixed. |
| 33 | + # (from https://github.com/ros2/rclcpp/pull/1188#issuecomment-650229140) |
| 34 | + add_compile_options(-Wall -Wextra -Wconversion -Wno-sign-conversion -Wpedantic -Wnon-virtual-dtor -Woverloaded-virtual) |
| 35 | +endif() |
| 36 | + |
| 37 | +set(${PROJECT_NAME}_SRCS |
| 38 | + src/rclcpp/any_executable.cpp |
| 39 | + src/rclcpp/callback_group.cpp |
| 40 | + src/rclcpp/client.cpp |
| 41 | + src/rclcpp/clock.cpp |
| 42 | + src/rclcpp/context.cpp |
| 43 | + src/rclcpp/contexts/default_context.cpp |
| 44 | + src/rclcpp/detail/add_guard_condition_to_rcl_wait_set.cpp |
| 45 | + src/rclcpp/detail/resolve_parameter_overrides.cpp |
| 46 | + src/rclcpp/detail/rmw_implementation_specific_payload.cpp |
| 47 | + src/rclcpp/detail/rmw_implementation_specific_publisher_payload.cpp |
| 48 | + src/rclcpp/detail/rmw_implementation_specific_subscription_payload.cpp |
| 49 | + src/rclcpp/detail/utilities.cpp |
| 50 | + src/rclcpp/duration.cpp |
| 51 | + src/rclcpp/event.cpp |
| 52 | + src/rclcpp/exceptions/exceptions.cpp |
| 53 | + src/rclcpp/executable_list.cpp |
| 54 | + src/rclcpp/executor.cpp |
| 55 | + src/rclcpp/executors.cpp |
| 56 | + src/rclcpp/executors/multi_threaded_executor.cpp |
| 57 | + src/rclcpp/executors/single_threaded_executor.cpp |
| 58 | + src/rclcpp/executors/static_executor_entities_collector.cpp |
| 59 | + src/rclcpp/executors/static_single_threaded_executor.cpp |
| 60 | + src/rclcpp/expand_topic_or_service_name.cpp |
| 61 | + src/rclcpp/future_return_code.cpp |
| 62 | + src/rclcpp/generic_publisher.cpp |
| 63 | + src/rclcpp/generic_subscription.cpp |
| 64 | + src/rclcpp/graph_listener.cpp |
| 65 | + src/rclcpp/guard_condition.cpp |
| 66 | + src/rclcpp/init_options.cpp |
| 67 | + src/rclcpp/intra_process_manager.cpp |
| 68 | + src/rclcpp/logger.cpp |
| 69 | + src/rclcpp/logging_mutex.cpp |
| 70 | + src/rclcpp/memory_strategies.cpp |
| 71 | + src/rclcpp/memory_strategy.cpp |
| 72 | + src/rclcpp/message_info.cpp |
| 73 | + src/rclcpp/network_flow_endpoint.cpp |
| 74 | + src/rclcpp/node.cpp |
| 75 | + src/rclcpp/node_interfaces/node_base.cpp |
| 76 | + src/rclcpp/node_interfaces/node_clock.cpp |
| 77 | + src/rclcpp/node_interfaces/node_graph.cpp |
| 78 | + src/rclcpp/node_interfaces/node_logging.cpp |
| 79 | + src/rclcpp/node_interfaces/node_parameters.cpp |
| 80 | + src/rclcpp/node_interfaces/node_services.cpp |
| 81 | + src/rclcpp/node_interfaces/node_time_source.cpp |
| 82 | + src/rclcpp/node_interfaces/node_timers.cpp |
| 83 | + src/rclcpp/node_interfaces/node_topics.cpp |
| 84 | + src/rclcpp/node_interfaces/node_waitables.cpp |
| 85 | + src/rclcpp/node_options.cpp |
| 86 | + src/rclcpp/parameter.cpp |
| 87 | + src/rclcpp/parameter_client.cpp |
| 88 | + src/rclcpp/parameter_event_handler.cpp |
| 89 | + src/rclcpp/parameter_events_filter.cpp |
| 90 | + src/rclcpp/parameter_map.cpp |
| 91 | + src/rclcpp/parameter_service.cpp |
| 92 | + src/rclcpp/parameter_value.cpp |
| 93 | + src/rclcpp/publisher_base.cpp |
| 94 | + src/rclcpp/qos.cpp |
| 95 | + src/rclcpp/qos_event.cpp |
| 96 | + src/rclcpp/qos_overriding_options.cpp |
| 97 | + src/rclcpp/serialization.cpp |
| 98 | + src/rclcpp/serialized_message.cpp |
| 99 | + src/rclcpp/service.cpp |
| 100 | + src/rclcpp/signal_handler.cpp |
| 101 | + src/rclcpp/subscription_base.cpp |
| 102 | + src/rclcpp/subscription_intra_process_base.cpp |
| 103 | + src/rclcpp/time.cpp |
| 104 | + src/rclcpp/time_source.cpp |
| 105 | + src/rclcpp/timer.cpp |
| 106 | + src/rclcpp/type_support.cpp |
| 107 | + src/rclcpp/typesupport_helpers.cpp |
| 108 | + src/rclcpp/utilities.cpp |
| 109 | + src/rclcpp/wait_set_policies/detail/write_preferring_read_write_lock.cpp |
| 110 | + src/rclcpp/waitable.cpp |
| 111 | +) |
| 112 | + |
| 113 | +find_package(Python3 REQUIRED COMPONENTS Interpreter) |
| 114 | + |
| 115 | +# "watch" template for changes |
| 116 | +configure_file( |
| 117 | + "resource/logging.hpp.em" |
| 118 | + "logging.hpp.em.watch" |
| 119 | + COPYONLY |
| 120 | +) |
| 121 | +# generate header with logging macros |
| 122 | +set(python_code_logging |
| 123 | + "import em" |
| 124 | + "em.invoke(['-o', 'include/rclcpp/logging.hpp', '${CMAKE_CURRENT_SOURCE_DIR}/resource/logging.hpp.em'])") |
| 125 | +string(REPLACE ";" "$<SEMICOLON>" python_code_logging "${python_code_logging}") |
| 126 | +add_custom_command(OUTPUT include/rclcpp/logging.hpp |
| 127 | + COMMAND ${CMAKE_COMMAND} -E make_directory "include/rclcpp" |
| 128 | + COMMAND Python3::Interpreter ARGS -c "${python_code_logging}" |
| 129 | + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/logging.hpp.em.watch" |
| 130 | + COMMENT "Expanding logging.hpp.em" |
| 131 | + VERBATIM |
| 132 | +) |
| 133 | +list(APPEND ${PROJECT_NAME}_SRCS |
| 134 | + include/rclcpp/logging.hpp) |
| 135 | + |
| 136 | +file(GLOB interface_files "include/rclcpp/node_interfaces/node_*_interface.hpp") |
| 137 | +foreach(interface_file ${interface_files}) |
| 138 | + get_filename_component(interface_name ${interface_file} NAME_WE) |
| 139 | + |
| 140 | + # "watch" template for changes |
| 141 | + configure_file( |
| 142 | + "resource/interface_traits.hpp.em" |
| 143 | + "${CMAKE_CURRENT_BINARY_DIR}/${interface_name}_traits.hpp.em.watch" |
| 144 | + COPYONLY |
| 145 | + ) |
| 146 | + set(python_${interface_name}_traits |
| 147 | + "import em" |
| 148 | + "em.invoke(['-D', 'interface_name = \\'${interface_name}\\'', '-o', 'include/rclcpp/node_interfaces/${interface_name}_traits.hpp', '${CMAKE_CURRENT_SOURCE_DIR}/resource/interface_traits.hpp.em'])") |
| 149 | + string(REPLACE ";" "$<SEMICOLON>" python_${interface_name}_traits "${python_${interface_name}_traits}") |
| 150 | + add_custom_command(OUTPUT include/rclcpp/node_interfaces/${interface_name}_traits.hpp |
| 151 | + COMMAND ${CMAKE_COMMAND} -E make_directory "include/rclcpp/node_interfaces" |
| 152 | + COMMAND Python3::Interpreter ARGS -c "${python_${interface_name}_traits}" |
| 153 | + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${interface_name}_traits.hpp.em.watch" |
| 154 | + COMMENT "Expanding interface_traits.hpp.em into ${interface_name}_traits.hpp" |
| 155 | + VERBATIM |
| 156 | + ) |
| 157 | + list(APPEND ${PROJECT_NAME}_SRCS |
| 158 | + include/rclcpp/node_interfaces/${interface_name}_traits.hpp) |
| 159 | + |
| 160 | + # "watch" template for changes |
| 161 | + configure_file( |
| 162 | + "resource/get_interface.hpp.em" |
| 163 | + "get_${interface_name}.hpp.em.watch" |
| 164 | + COPYONLY |
| 165 | + ) |
| 166 | + set(python_get_${interface_name} |
| 167 | + "import em" |
| 168 | + "em.invoke(['-D', 'interface_name = \\'${interface_name}\\'', '-o', 'include/rclcpp/node_interfaces/get_${interface_name}.hpp', '${CMAKE_CURRENT_SOURCE_DIR}/resource/get_interface.hpp.em'])") |
| 169 | + string(REPLACE ";" "$<SEMICOLON>" python_get_${interface_name} "${python_get_${interface_name}}") |
| 170 | + add_custom_command(OUTPUT include/rclcpp/node_interfaces/get_${interface_name}.hpp |
| 171 | + COMMAND ${CMAKE_COMMAND} -E make_directory "include/rclcpp/node_interfaces" |
| 172 | + COMMAND Python3::Interpreter ARGS -c "${python_get_${interface_name}}" |
| 173 | + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/get_${interface_name}.hpp.em.watch" |
| 174 | + COMMENT "Expanding get_interface.hpp.em into get_${interface_file}.hpp" |
| 175 | + VERBATIM |
| 176 | + ) |
| 177 | + list(APPEND ${PROJECT_NAME}_SRCS |
| 178 | + include/rclcpp/node_interfaces/get_${interface_name}.hpp) |
| 179 | +endforeach() |
| 180 | + |
| 181 | +add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS}) |
| 182 | +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) |
| 183 | +# TODO(wjwwood): address all deprecation warnings and then remove this |
| 184 | +if(WIN32) |
| 185 | + target_compile_definitions(${PROJECT_NAME} PUBLIC "_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS") |
| 186 | +endif() |
| 187 | +target_include_directories(${PROJECT_NAME} PUBLIC |
| 188 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" |
| 189 | + "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>" |
| 190 | + "$<INSTALL_INTERFACE:include/${PROJECT_NAME}>") |
| 191 | +target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT}) |
| 192 | +# specific order: dependents before dependencies |
| 193 | +ament_target_dependencies(${PROJECT_NAME} |
| 194 | + "ament_index_cpp" |
| 195 | + "libstatistics_collector" |
| 196 | + "rcl" |
| 197 | + "rcl_interfaces" |
| 198 | + "rcl_yaml_param_parser" |
| 199 | + "rcpputils" |
| 200 | + "rcutils" |
| 201 | + "builtin_interfaces" |
| 202 | + "rosgraph_msgs" |
| 203 | + "rosidl_typesupport_cpp" |
| 204 | + "rosidl_runtime_cpp" |
| 205 | + "statistics_msgs" |
| 206 | + "tracetools" |
| 207 | +) |
| 208 | + |
| 209 | +# Causes the visibility macros to use dllexport rather than dllimport, |
| 210 | +# which is appropriate when building the dll but not consuming it. |
| 211 | +target_compile_definitions(${PROJECT_NAME} |
| 212 | + PRIVATE "RCLCPP_BUILDING_LIBRARY") |
| 213 | + |
| 214 | +install( |
| 215 | + TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} |
| 216 | + ARCHIVE DESTINATION lib |
| 217 | + LIBRARY DESTINATION lib |
| 218 | + RUNTIME DESTINATION bin |
| 219 | +) |
| 220 | + |
| 221 | +# Export old-style CMake variables |
| 222 | +ament_export_include_directories("include/${PROJECT_NAME}") |
| 223 | +ament_export_libraries(${PROJECT_NAME}) |
| 224 | + |
| 225 | +# Export modern CMake targets |
| 226 | +ament_export_targets(${PROJECT_NAME}) |
| 227 | + |
| 228 | +# specific order: dependents before dependencies |
| 229 | +ament_export_dependencies(ament_index_cpp) |
| 230 | +ament_export_dependencies(libstatistics_collector) |
| 231 | +ament_export_dependencies(rcl) |
| 232 | +ament_export_dependencies(rcpputils) |
| 233 | +ament_export_dependencies(rcutils) |
| 234 | +ament_export_dependencies(builtin_interfaces) |
| 235 | +ament_export_dependencies(rosgraph_msgs) |
| 236 | +ament_export_dependencies(rosidl_typesupport_cpp) |
| 237 | +ament_export_dependencies(rosidl_typesupport_c) |
| 238 | +ament_export_dependencies(rosidl_runtime_cpp) |
| 239 | +ament_export_dependencies(rcl_yaml_param_parser) |
| 240 | +ament_export_dependencies(statistics_msgs) |
| 241 | +ament_export_dependencies(tracetools) |
| 242 | + |
| 243 | +if(BUILD_TESTING) |
| 244 | + find_package(ament_lint_auto REQUIRED) |
| 245 | + ament_lint_auto_find_test_dependencies() |
| 246 | + |
| 247 | + add_subdirectory(test) |
| 248 | +endif() |
| 249 | + |
| 250 | +ament_package() |
| 251 | + |
| 252 | +install( |
| 253 | + DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/ |
| 254 | + DESTINATION include/${PROJECT_NAME} |
| 255 | +) |
| 256 | + |
| 257 | +if(TEST cppcheck) |
| 258 | + # must set the property after ament_package() |
| 259 | + set_tests_properties(cppcheck PROPERTIES TIMEOUT 500) |
| 260 | +endif() |
| 261 | + |
| 262 | +ament_generate_version_header(${PROJECT_NAME}) |
0 commit comments