2
0
Эх сурвалжийг харах

Change how ROS 2 packages are included. (#204)

* Change how ROS 2 packages are included.

Include cmake configs from the ROS 2 package instead of building lib and
include paths.
Added function `target_depends_on_ros2_package` that allows specifying
version and optionality of the ROS 2 package.

Signed-off-by: Michał Pełka <[email protected]>

* Adjust to review

Signed-off-by: Michał Pełka <[email protected]>

* Change cmake to treat urdfdom as normal package, not ament package.
Signed-off-by: Michał Pełka <[email protected]>

---------

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 2 жил өмнө
parent
commit
80caf95319

+ 6 - 1
Gems/ROS2/Code/CMakeLists.txt

@@ -17,6 +17,7 @@ if (NOT ROS2_FOUND)
     message(FATAL_ERROR "Unable to detect a the ROS2 distribution on this system. Make sure it is installed and enabled.")
     message(FATAL_ERROR "Unable to detect a the ROS2 distribution on this system. Make sure it is installed and enabled.")
     return()
     return()
 endif()
 endif()
+message(DEBUG "Building ${gem_name} Gem with ros2 $ENV{ROS_DISTRO}")
 
 
 # Add the ROS2.Static target
 # Add the ROS2.Static target
 # Note: We include the common files and the platform specific files which are set in ros2_common_files.cmake
 # Note: We include the common files and the platform specific files which are set in ros2_common_files.cmake
@@ -44,7 +45,8 @@ ly_add_target(
             Gem::PhysX.Static
             Gem::PhysX.Static
 )
 )
 
 
-target_depends_on_ros2_packages(${gem_name}.Static rclcpp builtin_interfaces std_msgs sensor_msgs nav_msgs urdfdom tf2_ros ackermann_msgs gazebo_msgs control_toolbox)
+target_depends_on_ros2_packages(${gem_name}.Static rclcpp builtin_interfaces std_msgs sensor_msgs nav_msgs tf2_ros ackermann_msgs gazebo_msgs)
+target_depends_on_ros2_package(${gem_name}.Static control_toolbox 2.2.0 REQUIRED)
 
 
 ly_add_target(
 ly_add_target(
     NAME ${gem_name}.API HEADERONLY
     NAME ${gem_name}.API HEADERONLY
@@ -109,6 +111,9 @@ if(PAL_TRAIT_BUILD_HOST_TOOLS)
                 Gem::${gem_name}.Static
                 Gem::${gem_name}.Static
     )
     )
 
 
+    find_package(urdfdom)
+    target_link_libraries(${gem_name}.Editor.Static PUBLIC urdfdom::urdfdom_model)
+
     ly_add_target(
     ly_add_target(
         NAME ${gem_name}.Editor GEM_MODULE
         NAME ${gem_name}.Editor GEM_MODULE
         NAMESPACE Gem
         NAMESPACE Gem

+ 15 - 24
Gems/ROS2/Code/ros2_target_depends.cmake

@@ -3,29 +3,20 @@
 #
 #
 # SPDX-License-Identifier: Apache-2.0 OR MIT
 # SPDX-License-Identifier: Apache-2.0 OR MIT
 
 
-function(target_depends_on_ros2_packages TARGET_NAME)
-    find_package(ROS2 MODULE)
-    if (NOT ROS2_FOUND)
-        return()
-    endif()
-    message(DEBUG "Building ROS2 Gem with ros2 $ENV{ROS_DISTRO}")
-    set(_ament_prefix_path "$ENV{AMENT_PREFIX_PATH}")
+function(target_depends_on_ros2_package TARGET_NAME)
+    list(GET ARGN 0 _package)
+    find_package(${ARGN})
+    include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
+    if (${${_package}_FOUND_AMENT_PACKAGE})
+        message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
+        target_link_libraries(${TARGET_NAME} PUBLIC ${${_package}_TARGETS})
+    else ()
+        message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
+    endif ()
+endfunction()
 
 
-    # ros2 directories with libraries, e.g. /opt/ros/galactic/lib, locally built custom packages etc.
-    set(_ros2_library_directories)
-    set(_ros2_include_directories)
-    set(_ros2_package_libraries)
-    foreach(_ros2_packages_path IN LISTS _ament_prefix_path)
-        string(REPLACE ":" ";" _ros2_packages_path ${_ros2_packages_path})
-        list(APPEND _ros2_library_directories "${_ros2_packages_path}/lib")
-        list(APPEND _ros2_include_directories "${_ros2_packages_path}/include")
-    endforeach()
-    foreach(_package IN LISTS ARGN)
-        message(DEBUG "Processing package: ${_package}")
-        find_package(${_package} REQUIRED)
-        list(APPEND _ros2_package_libraries "${${_package}_LIBRARIES}")
-        list(APPEND _ros2_include_directories "${${_package}_INCLUDE_DIRS}")
-    endforeach()
-    target_include_directories(${TARGET_NAME} PUBLIC ${_ros2_include_directories})
-    target_link_libraries(${TARGET_NAME} PUBLIC ${_ros2_package_libraries})
+function(target_depends_on_ros2_packages TARGET_NAME)
+    foreach (_package IN LISTS ARGN)
+        target_depends_on_ros2_package(${TARGET_NAME} ${_package} REQUIRED)
+    endforeach ()
 endfunction()
 endfunction()