Using ros2_local_repository
following the ros-humble installation (the debian way) yields errors the following CMAKE errors -
--- captured stderr ---
CMake Warning at /opt/ros/humble/share/quality_of_service_demo_cpp/cmake/ament_cmake_export_include_directories-extras.cmake:11 (message):
Package 'quality_of_service_demo_cpp' exports the include directory
'/opt/ros/humble/share/quality_of_service_demo_cpp/cmake/../../../include/quality_of_service_demo_cpp'
which doesn't exist
Call Stack (most recent call first):
/opt/ros/humble/share/quality_of_service_demo_cpp/cmake/quality_of_service_demo_cppConfig.cmake:41 (include)
CMakeLists.txt:16 (find_package)
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_generator_c" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_fastrtps_c" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_generator_cpp" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_fastrtps_cpp" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_introspection_c" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_c" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_introspection_cpp" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_typesupport_cpp" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs__rosidl_generator_py" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_image_tools" links to target
"sensor_msgs::sensor_msgs_library" but the target was not found. Perhaps a
find_package() call is missing for an IMPORTED target, or an ALIAS target
is missing?
CMake Generate step failed. Build files cannot be regenerated correctly.
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target "tf2::tf2" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_generator_c" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_fastrtps_c" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_introspection_c" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_c" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_generator_cpp" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_fastrtps_cpp" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_introspection_cpp" but
the target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_typesupport_cpp" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target
"geometry_msgs::geometry_msgs__rosidl_generator_py" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target "tf2_ros::tf2_ros" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Generate step failed. Build files cannot be regenerated correctly.
Trying to build my [outdoor_slam_ros2][1]
package with drake-ros' bazel rules.
Relevant snippet from WORKSPACE
. Is there some other way to pull in packages and use via an overlay workspace?
# Use ROS 2
ros2_local_repository(
name = "ros2",
workspaces = ["/opt/ros/humble/"],
)
I can reproduce the same error after installing ros-humble-desktop
. The solution is to include just the packages you need from a workspace with the include_packages
option to ros2_local_repository()
.
ros2_local_repository(
name = "ros2",
include_packages = [
"rclcpp",
],
workspaces = ["/opt/ros/humble/"],
)
In the background ros2_local_repository()
uses the CMake File API to "scrape" information about ROS 2 packages to build a BUILD.bazel
file for the @ros2
repo. That "scraping" works by generating a CMake package for each package in the ROS 2 workspace. The generated package tries to depend on everything in the ROS 2 package it's responsible for scraping. This can uncover bugs in the CMake logic of the ROS 2 package that might not be seen in typical use.
Take for example this one:
CMake Error at CMakeLists.txt:19 (add_library):
Target "empty_using_tf2_bullet" links to target "tf2_ros::tf2_ros" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
The bug is that tf2_bullet
publicly depends on tf2_ros::tf2_ros
, but does not tell downstream packages to find_package(tf2_ros)
to get access to that target. The tf2_bullet
package's CMakeLists.txt
is missing the line ament_export_dependencies(tf2_ros)
which would make downstream packages automatically find_package(tf2_ros)
when they find_package(tf2_bullet)
. The fact that this bug exists probably means that not many developers are using tf2_bullet
, or they're also already directly or indirectly calling find_package(tf2_ros)
.
Using the include_packages
option avoids these kinds of bugs by instructing ros2_local_repository()
to only scrape the ROS 2 packages that are actually needed, instead of scraping all of them in the workspace.