Skip to content

Add ament_auto_depend_on_packages to replace ament_target_dependencies - #571

Merged
sloretz merged 11 commits into
rollingfrom
sloretz__ament_cmake_auto_depend_on_packages
Mar 26, 2025
Merged

sloretz merged 11 commits into
rollingfrom
sloretz__ament_cmake_auto_depend_on_packages

Conversation

@sloretz

@sloretz sloretz commented Mar 14, 2025

Copy link
Copy Markdown
Contributor

This replaces use of ament_target_dependencies with a new function ament_auto_depend_on_packages.

#292

The new function ament_auto_depend_on_packages prefers depending on modern CMake targets when possible, but can fall-back to using old-style standard CMake variables.

sloretz added 4 commits March 18, 2025 23:52
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
@sloretz

sloretz commented Mar 19, 2025 •

Copy link
Copy Markdown
Contributor Author

The core ROS 2 repos don't really use ament_cmake_auto, so I built the core https://autoware.org repos to test this PR. That's been a small adventure.

I added these additional repos to my workspace:

autoware core repos
repositories:
  RSL:
    type: git
    url: https://github.com/PickNikRobotics/RSL.git
    version: main
  core/autoware.core:
    type: git
    url: [email protected]:sloretz/autoware_core.git
    version: sloretz_combined
  core/autoware_adapi_msgs:
    type: git
    url: https://github.com/autowarefoundation/autoware_adapi_msgs.git
    version: main
  core/autoware_cmake:
    type: git
    url: https://github.com/autowarefoundation/autoware_cmake.git
    version: main
  core/autoware_internal_msgs:
    type: git
    url: https://github.com/autowarefoundation/autoware_internal_msgs.git
    version: main
  core/autoware_lanelet2_extension:
    type: git
    url: https://github.com/autowarefoundation/autoware_lanelet2_extension.git
    version: main
  core/autoware_msgs:
    type: git
    url: https://github.com/autowarefoundation/autoware_msgs.git
    version: main
  core/autoware_utils:
    type: git
    url: [email protected]:sloretz/autoware_utils.git
    version: sloretz_remove_reference_hull_graham_andrew
  cpp_polyfills:
    type: git
    url: https://github.com/PickNikRobotics/cpp_polyfills.git
    version: main
  generate_parameter_library:
    type: git
    url: https://github.com/PickNikRobotics/generate_parameter_library.git
    version: main
  geographic_info:
    type: git
    url: https://github.com/ros-geographic-info/geographic_info.git
    version: ros2
  lanelet2:
    type: git
    url: https://github.com/fzi-forschungszentrum-informatik/lanelet2.git
    version: master
  mrt_cmake_modules:
    type: git
    url: https://github.com/KIT-MRT/mrt_cmake_modules.git
    version: master
  osqp_vendor:
    type: git
    url: https://github.com/tier4/osqp_vendor.git
    version: main
  pcl_msgs:
    type: git
    url: https://github.com/ros-perception/pcl_msgs.git
    version: ros2
  perception_pcl:
    type: git
    url: https://github.com/ros-perception/perception_pcl.git
    version: ros2
  point_cloud_msg_wrapper:
    type: git
    url: https://gitlab.com/ApexAI/point_cloud_msg_wrapper.git
    version: master
  proxsuite:
    type: git
    url: https://github.com/Simple-Robotics/proxsuite.git
    version: devel

I set the ROS_VERSION environment variable for osqp_vendor to build.

# Needed by osqp_vendor
export ROS_VERSION=2
# Needed by mrt packages
export ROS_PYTHON_VERSION=3

I manually installed libsimde-dev, not sure why rosdep didn't do this for me

sudo apt-get install -y libsimde-dev

Most packages build, but these fail:

colcon build --packages-above-and-dependencies ament_cmake_auto

@sloretz

sloretz commented Mar 26, 2025

Copy link
Copy Markdown
Contributor Author

Ok, I'm confident this PR works, so it's ready for review. The only autoware core packages I can't build are autoware_osqp_interface and autoware_qp_interface, but I'm pretty sure it's an upstream issue that I don't have time to debug right now.

@emersonknapp emersonknapp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM

@sloretz

sloretz commented Mar 26, 2025

Copy link
Copy Markdown
Contributor Author

Pulls: #571
Gist: https://gist.githubusercontent.com/sloretz/d0fc13f2fcbc954e7fcd214a2cd0aa7c/raw/232a694b9bd370ea4ed0986825a4a1dc479c6951/ros2.repos
BUILD args: --packages-above-and-dependencies ament_cmake_auto
TEST args: --packages-above ament_cmake_auto
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15491

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@mjcarroll mjcarroll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@emersonknapp is a committer, his approval is good here. Here is my proxy approval.

@sloretz
sloretz merged commit d359a1a into rolling Mar 26, 2025
@sloretz
sloretz deleted the sloretz__ament_cmake_auto_depend_on_packages branch March 26, 2025 20:31
@saikishor

Copy link
Copy Markdown

Hello!

Is there anyway, this can be backported to Jazzy and Humble?


if(${package_name}_TARGETS)
# Use modern CMake targets
target_link_libraries(${target} ${ARG_SCOPE} ${${package_name}_TARGETS})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@sloretz before I open an upstream PR, is there any reason not to do the following here?

Suggested change
target_link_libraries(${target} ${ARG_SCOPE} ${${package_name}_TARGETS})
target_link_libraries(${target} ${_implied_scope} ${${package_name}_TARGETS})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes there's a reason not to.

target_link_libraries has two signatures: one with scope keywords and one without. CMake will error if anyone uses two target_link_libraries calls on the same target, one having a scope keyword and one not. There's a short explanation here: https://discourse.cmake.org/t/plain-and-keyword-signature/4720 .

This isn't a problem when you control both the target_link_libraries calls, but I've seen it happen a when a project offers a CMake macro that internally calls target_link_libraries with a different signature. Here's an example where a macro inside of CMake did that: https://gitlab.kitware.com/cmake/cmake/-/issues/16602

Most CMake functions require the scope keyword already. If CMake ever removes the plain signature of target_link_libraries, then we should remove the variable _implied_scope and pass ${ARG_SCOPE} directly into all the CMake functions here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks @sloretz for the explanation. I'm porting a large ROS workspace from humble to kilted and I managed to narrow down problems I'm facing to the following example:

cmake_minimum_required(VERSION 3.16)
project(example_package)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

ament_auto_add_library(${PROJECT_NAME} src/example.cpp)

ament_auto_add_executable(${PROJECT_NAME}_main src/main.cpp)
target_link_libraries(${PROJECT_NAME}_main PRIVATE ${PROJECT_NAME})

ament_auto_package()

It fails with the following:

--- stderr: example_package
CMake Error at CMakeLists.txt:16 (target_link_libraries):
  The plain signature for target_link_libraries has already been used with
  the target "example_package_main".  All uses of target_link_libraries with
  a target must be either all-keyword or all-plain.

  The uses of the plain signature are here:

   * /home/dferigo/git/control_suite_pixi/.pixi/envs/default/share/ament_cmake_auto/cmake/ament_auto_add_executable.cmake:76 (target_link_libraries)
   * /home/dferigo/git/control_suite_pixi/.pixi/envs/default/share/ament_cmake_auto/cmake/ament_auto_depend_on_packages.cmake:80 (target_link_libraries)

---
Failed   <<< example_package [0.28s, exited with code 1]

The straightforward solution would be to remove PRIVATE, but it would be great having the possibility to keep using it. Do you see any way to work around this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Update: if fails similarly also if I link to the library something else not part of package.xml:

find_package(my_other_lib REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC my_other_lib)

This is more relevant than an executable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like ament_auto_add_library uses the plain signature of target_link_libraries():

target_link_libraries("${target}" ${${PROJECT_NAME}_LIBRARIES})

Some options are:

  • (Easiest) Use the plain signature in your code as well
  • (Medium effort) Modify your code to use ament_cmake instead of ament_cmake_auto
  • (Hardest) Modify ament_auto_add_library to accept a SCOPE argument with a way to specify which dependencies that scope applies to, and then make your code use that.

Since you're porting a large volume of code, if I was in your position I would go for the easiest option first until everything worked. Then I would refactor one package at a time to use ament_cmake instead of ament_cmake_auto. I don't think it would make sense to modify ament_auto_add_library to take a scope argument, because if you do then you also need to specify which dependencies that scope applies to, and if you're doing that you might as well use add_library and target_link_libraries directly.

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.

5 participants