Repository navigation
Add ament_auto_depend_on_packages to replace ament_target_dependencies - #571
Conversation
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]>
Signed-off-by: Shane Loretz <[email protected]>
Signed-off-by: Shane Loretz <[email protected]>
|
The core ROS 2 repos don't really use I added these additional repos to my workspace: autoware core reposrepositories:
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: develI set the # Needed by osqp_vendor
export ROS_VERSION=2
# Needed by mrt packages
export ROS_PYTHON_VERSION=3I manually installed Most packages build, but these fail:
colcon build --packages-above-and-dependencies ament_cmake_auto |
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]>
Signed-off-by: Shane Loretz <[email protected]>
|
Ok, I'm confident this PR works, so it's ready for review. The only |
|
Pulls: #571 |
mjcarroll
left a comment
There was a problem hiding this comment.
@emersonknapp is a committer, his approval is good here. Here is my proxy approval.
|
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}) |
There was a problem hiding this comment.
@sloretz before I open an upstream PR, is there any reason not to do the following here?
| target_link_libraries(${target} ${ARG_SCOPE} ${${package_name}_TARGETS}) | |
| target_link_libraries(${target} ${_implied_scope} ${${package_name}_TARGETS}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Looks like ament_auto_add_library uses the plain signature of target_link_libraries():
Some options are:
- (Easiest) Use the plain signature in your code as well
- (Medium effort) Modify your code to use
ament_cmakeinstead ofament_cmake_auto - (Hardest) Modify
ament_auto_add_libraryto accept aSCOPEargument 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.
This replaces use of
ament_target_dependencieswith a new functionament_auto_depend_on_packages.#292
The new function
ament_auto_depend_on_packagesprefers depending on modern CMake targets when possible, but can fall-back to using old-style standard CMake variables.