Open stonier opened 3 years ago
- Create a nested
CMakeLists.txt
in the demos/composition package- Move the
talker_component
logic into the nested CMakeLists.txt (be sure to include the registering macro)
Hi, @stonier
I suppose you want to use the subdirectory to organize the source code. I think you could refer to this link firstly. (FYI: I have tried the workaround (the method might be a little different from the above link) for the demo and it seems working.)
I think it should be technically possible to support what @stonier is doing, and probably a good idea to do so as well. @sloretz's workaround will work, but is somewhat fragile because it depends on a cmake variable name that we otherwise don't expose and could be changed in the future. I don't have time to work on this at the moment, but we could consider changing how we set/get that variable to work around the scoping, or maybe we could add a macro that must be called in the child scope to make this work (a less-fragile form of the PARENT_SCOPE
workaround).
we could add a macro that must be called in the child scope to make this work
Yeah, this could be a method.
But I think users want to use rclcpp_components_register_nodes
in subdirectories in the same way as the root directory.
Patches that I am not sure if it's the right way.
```shell
diff --git a/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake b/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake
index e80550a3..74045f99 100644
--- a/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake
+++ b/rclcpp_components/cmake/rclcpp_components_register_nodes.cmake
@@ -67,6 +67,15 @@ macro(rclcpp_components_register_nodes target)
"${_RCLCPP_COMPONENTS_${resource_index}__NODES}${_arg};${_path}/$
```shell diff --git a/ament_cmake_core/cmake/core/ament_register_extension.cmake b/ament_cmake_core/cmake/core/ament_register_extension.cmake index 45effb2..b4118a4 100644 --- a/ament_cmake_core/cmake/core/ament_register_extension.cmake +++ b/ament_cmake_core/cmake/core/ament_register_extension.cmake @@ -30,4 +30,10 @@ macro(ament_register_extension extension_point package_name cmake_filename) list(APPEND AMENT_EXTENSIONS_${extension_point} "${package_name}:${cmake_filename}") + + if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(AMENT_EXTENSIONS_${extension_point} + ${AMENT_EXTENSIONS_${extension_point}} + PARENT_SCOPE) + endif() endmacro() ```
I think I am having the same issue, where my component is closely based on the DEMO, but the only thing which is returned by the ros2 pkg executables
command and is linked to the project is a .so
file with the name of the library created in CMakeLists.txt.
In my case I have two levels of add_subdirectory
. One for the project
level, which adds the src
level, which adds all the components
.
Bug report
Required Info:
Steps to reproduce issue
CMakeLists.txt
in the demos/composition packagetalker_component
logic into the nested CMakeLists.txt (be sure to include the registering macro)Expected behavior
The talker component will be present in
share/ament_index/resource_index/rclcpp_components/composition
, or at least, an error atCMake
configure time.Actual behavior
The talker component is missing.