diff --git a/rclcpp_components/CMakeLists.txt b/rclcpp_components/CMakeLists.txt index e7eacd6043..92f089e878 100644 --- a/rclcpp_components/CMakeLists.txt +++ b/rclcpp_components/CMakeLists.txt @@ -89,7 +89,6 @@ if(BUILD_TESTING) APPEND_LIBRARY_DIRS "${append_library_dirs}") if(TARGET test_component_manager) target_link_libraries(test_component_manager component_manager) - target_include_directories(test_component_manager PRIVATE src) endif() ament_add_gtest(test_component_manager_api test/test_component_manager_api.cpp @@ -97,7 +96,6 @@ if(BUILD_TESTING) APPEND_LIBRARY_DIRS "${append_library_dirs}") if(TARGET test_component_manager_api) target_link_libraries(test_component_manager_api component_manager) - target_include_directories(test_component_manager_api PRIVATE src) endif() endif() diff --git a/rclcpp_components/cmake/rclcpp_components_package_hook.cmake b/rclcpp_components/cmake/rclcpp_components_package_hook.cmake index 4833d02a71..4d5b162e28 100644 --- a/rclcpp_components/cmake/rclcpp_components_package_hook.cmake +++ b/rclcpp_components/cmake/rclcpp_components_package_hook.cmake @@ -13,6 +13,11 @@ # limitations under the License. # register node plugins -ament_index_register_resource( - "rclcpp_components" CONTENT "${_RCLCPP_COMPONENTS__NODES}") +list(REMOVE_DUPLICATES _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES) +foreach(resource_index ${_RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES}) + #message(WARNING "registered index: ${resource_index}") + #message(WARNING "content for index: ${_RCLCPP_COMPONENTS_${resource_index}__NODES}") + ament_index_register_resource( + ${resource_index} CONTENT "${_RCLCPP_COMPONENTS_${resource_index}__NODES}") +endforeach() diff --git a/rclcpp_components/cmake/rclcpp_components_register_node.cmake b/rclcpp_components/cmake/rclcpp_components_register_node.cmake index e7fa3e2fd7..70443e9c81 100644 --- a/rclcpp_components/cmake/rclcpp_components_register_node.cmake +++ b/rclcpp_components/cmake/rclcpp_components_register_node.cmake @@ -22,15 +22,24 @@ # :type target: string # :param PLUGIN: the plugin name # :type PLUGIN: string -# :type EXECUTABLE: the node's executable name +# :param EXECUTABLE: the node's executable name # :type EXECUTABLE: string +# :param RESOURCE_INDEX: the ament resource index to register the components +# :type RESOURCE_INDEX: string # macro(rclcpp_components_register_node target) - cmake_parse_arguments(ARGS "" "PLUGIN;EXECUTABLE" "" ${ARGN}) + cmake_parse_arguments(ARGS "" "PLUGIN;EXECUTABLE;RESOURCE_INDEX" "" ${ARGN}) if(ARGS_UNPARSED_ARGUMENTS) message(FATAL_ERROR "rclcpp_components_register_node() called with unused " "arguments: ${ARGS_UNPARSED_ARGUMENTS}") endif() + # default to rclcpp_components if not specified otherwise + set(resource_index "rclcpp_components") + if(NOT "${ARGS_RESOURCE_INDEX}" STREQUAL "") + set(resource_index ${ARGS_RESOURCE_INDEX}) + message(STATUS "Setting component resource index to non-default value ${resource_index}") + endif() + set(component ${ARGS_PLUGIN}) set(node ${ARGS_EXECUTABLE}) _rclcpp_components_register_package_hook() @@ -39,8 +48,10 @@ macro(rclcpp_components_register_node target) if(WIN32) set(_path "bin") endif() - set(_RCLCPP_COMPONENTS__NODES - "${_RCLCPP_COMPONENTS__NODES}${component};${_path}/$\n") + set(_RCLCPP_COMPONENTS_${resource_index}__NODES + "${_RCLCPP_COMPONENTS_${resource_index}__NODES}${component};${_path}/$\n") + list(APPEND _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES ${resource_index}) + configure_file(${rclcpp_components_NODE_TEMPLATE} ${PROJECT_BINARY_DIR}/rclcpp_components/node_main_configured_${node}.cpp.in) file(GENERATE OUTPUT ${PROJECT_BINARY_DIR}/rclcpp_components/node_main_${node}.cpp diff --git a/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake b/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake index eac3841fda..d52c58e9bc 100644 --- a/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake +++ b/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake @@ -21,6 +21,8 @@ # :type target: string # :param ARGN: the unique plugin names being exported using class_loader # :type ARGN: list of strings +# :param RESOURCE_INDEX: the ament resource index to register the components +# :type RESOURCE_INDEX: string # macro(rclcpp_components_register_nodes target) if(NOT TARGET ${target}) @@ -29,6 +31,17 @@ macro(rclcpp_components_register_nodes target) "rclcpp_components_register_nodes() first argument " "'${target}' is not a target") endif() + cmake_parse_arguments(ARGS "" "RESOURCE_INDEX" "" ${ARGN}) + if(ARGS_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "rclcpp_components_register_node() called with unused " + "arguments: ${ARGS_UNPARSED_ARGUMENTS}") + endif() + # default to rclcpp_components if not specified otherwise + set(resource_index "rclcpp_components") + if(NOT "${ARGS_RESOURCE_INDEX}" STREQUAL "") + set(resource_index ${ARGS_RESOURCE_INDEX}) + message(STATUS "Setting component resource index to non-default value ${resource_index}") + endif() get_target_property(_target_type ${target} TYPE) if(NOT _target_type STREQUAL "SHARED_LIBRARY") message( @@ -54,8 +67,9 @@ macro(rclcpp_components_register_nodes target) else() set(_path "lib") endif() - set(_RCLCPP_COMPONENTS__NODES - "${_RCLCPP_COMPONENTS__NODES}${_arg};${_path}/$\n") + set(_RCLCPP_COMPONENTS_${resource_index}__NODES + "${_RCLCPP_COMPONENTS_${resource_index}__NODES}${_arg};${_path}/$\n") + list(APPEND _RCLCPP_COMPONENTS_PACKAGE_RESOURCE_INDICES ${resource_index}) endforeach() endif() endmacro()