Skip to content

Conversation

@HansRobo
Copy link
Contributor

@HansRobo HansRobo commented Sep 13, 2025

This pull request adds an implementation for ament_auto_generate_code, which until now had an empty implementation.

This will automatically generate code for interfaces which are located below.

  • msg/*.msg
  • srv/*srv
  • action/*action

With this, many interface packages can have a simple CMake file like this:

cmake_minimum_required(VERSION 3.12)
project(sample_interfaces)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

ament_auto_generate_code()

ament_auto_package()

Link generated interfaces to targets in same package with TARGETS option

As described here, to use an interface in source code of the same package, explicit linking of the interface is required, which requires additional CMake instructions. With ament_auto_generate_code, linking is performed automatically by simply specifying the array of targets you want to link in the TARGETS option.

ament_auto_add_executable(${PROJECT_NAME}_node1 src/node1.cpp)
ament_auto_add_executable(${PROJECT_NAME}_node2 src/node2.cpp)

ament_auto_generate_code(TARGETS ${PROJECT_NAME}_node1 ${PROJECT_NAME}_node2)

Proper propagation of dependency updates

The ament_cmake_auto functions create a file list using globs, so even if build files or messages are added or removed, the CMake file does not need to be updated, and it was not possible to detect this and perform a rebuild.
However, this implementation uses the CONFIGURE_DEPENDS option added in CMake 3.12 to detect changes in the file list and automatically perform a rebuild.

Copy link

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

this dramatically reduces boilerplate for ROS interface packages and makes code generation and target linkage easier and less error-prone.

@HansRobo are you still working on this? i see this is tagged with draft.

@fujitatomoya
Copy link

@cottsay @hidmic can you take a look at this when you have time? i think this is good enhancement.

@cottsay
Copy link
Contributor

cottsay commented Oct 16, 2025

The underlying macro which backs this functionality is rosidl_generate_interfaces, which is defined down in the rosidl_cmake package. I think that is a much more appropriate place to define an "automatic" variation of it.

In general, there is no awareness of ROS-specific mechanisms like rosidl in ament_cmake, especially given that it usually results in a dependency cycle.

@HansRobo
Copy link
Contributor Author

I fixed a bug and finished the build check on my repository.

HansRobo/ros2_sandbox#4
https://github.com/HansRobo/ros2_sandbox/actions/runs/18565249987/job/52924441413?pr=4

@HansRobo HansRobo marked this pull request as ready for review October 16, 2025 14:52
@HansRobo
Copy link
Contributor Author

@cottsay Thank you for your feedback.
I will try to move this implementation into function like rosidl_auto_generate_interfaces in rosidl_cmake.

@fujitatomoya
Copy link

@cottsay thanks for the comment. i agree with you that it should stay in rosidl repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants