From a8679c42e729665e04c315a0d4865e0ed4672d40 Mon Sep 17 00:00:00 2001 From: Felix Blix Everberg Date: Tue, 5 Aug 2025 14:22:15 +0200 Subject: [PATCH] Transition from ament_target_dependencies to target_link_libraries Since kilted, the use of ament_target_dependencies has been deprecated. This commit replaces all uses of the macro with target_link_libraries as suggested in the deprecation warning, and does some additional steps in for the ethercat_interface package to ensure exports are done in the "modern" target-based fashion. --- ethercat_driver/CMakeLists.txt | 20 +++++------ .../sphinx/developer_guide/new_plugin.rst | 7 ++-- .../CMakeLists.txt | 12 +++---- .../ethercat_generic_slave/CMakeLists.txt | 16 ++++----- ethercat_interface/CMakeLists.txt | 36 +++++++------------ ethercat_manager/CMakeLists.txt | 7 ++-- 6 files changed, 41 insertions(+), 57 deletions(-) diff --git a/ethercat_driver/CMakeLists.txt b/ethercat_driver/CMakeLists.txt index a97e0e4a..9300b778 100644 --- a/ethercat_driver/CMakeLists.txt +++ b/ethercat_driver/CMakeLists.txt @@ -18,19 +18,17 @@ add_library( SHARED src/ethercat_driver.cpp) -target_include_directories( - ${PROJECT_NAME} - PRIVATE - include +target_include_directories(${PROJECT_NAME} PRIVATE + $ + $ ) -ament_target_dependencies( - ${PROJECT_NAME} - hardware_interface - pluginlib - rclcpp - rclcpp_lifecycle - ethercat_interface +target_link_libraries(${PROJECT_NAME} PUBLIC + hardware_interface::hardware_interface + pluginlib::pluginlib + rclcpp::rclcpp + rclcpp_lifecycle::rclcpp_lifecycle + ethercat_interface::ethercat_interface ) # Causes the visibility macros to use dllexport rather than dllimport, diff --git a/ethercat_driver_ros2/sphinx/developer_guide/new_plugin.rst b/ethercat_driver_ros2/sphinx/developer_guide/new_plugin.rst index 145550cd..35eded2f 100644 --- a/ethercat_driver_ros2/sphinx/developer_guide/new_plugin.rst +++ b/ethercat_driver_ros2/sphinx/developer_guide/new_plugin.rst @@ -137,10 +137,9 @@ Modify your :code:`CMakeLists.txt` file so that it looks like this: $ $ ) - ament_target_dependencies( - ${PROJECT_NAME} - "ethercat_interface" - "pluginlib" + target_link_libraries(${PROJECT_NAME} PUBLIC + ethercat_interface::ethercat_interface + pluginlib::pluginlib ) pluginlib_export_plugin_description_file(ethercat_interface ethercat_plugins.xml) install( diff --git a/ethercat_generic_plugins/ethercat_generic_cia402_drive/CMakeLists.txt b/ethercat_generic_plugins/ethercat_generic_cia402_drive/CMakeLists.txt index 2cc2ace1..0ffed1cc 100644 --- a/ethercat_generic_plugins/ethercat_generic_cia402_drive/CMakeLists.txt +++ b/ethercat_generic_plugins/ethercat_generic_cia402_drive/CMakeLists.txt @@ -26,15 +26,11 @@ target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17) # Require C target_include_directories(${PROJECT_NAME} PUBLIC $ $) -target_link_libraries(${PROJECT_NAME} yaml-cpp) - -ament_target_dependencies( - ${PROJECT_NAME} - ethercat_interface - ethercat_generic_slave - pluginlib - yaml_cpp_vendor +target_link_libraries(${PROJECT_NAME} PUBLIC + ethercat_interface::ethercat_interface + ethercat_generic_slave::ethercat_generic_slave + pluginlib::pluginlib yaml-cpp ) diff --git a/ethercat_generic_plugins/ethercat_generic_slave/CMakeLists.txt b/ethercat_generic_plugins/ethercat_generic_slave/CMakeLists.txt index f243db41..d1bfbb2a 100644 --- a/ethercat_generic_plugins/ethercat_generic_slave/CMakeLists.txt +++ b/ethercat_generic_plugins/ethercat_generic_slave/CMakeLists.txt @@ -25,14 +25,9 @@ target_compile_features(${PROJECT_NAME} PUBLIC c_std_99 cxx_std_17) # Require C target_include_directories(${PROJECT_NAME} PUBLIC $ $) -ament_target_dependencies( - ${PROJECT_NAME} - ethercat_interface - pluginlib - yaml_cpp_vendor - yaml-cpp -) -target_link_libraries(${PROJECT_NAME} +target_link_libraries(${PROJECT_NAME} PUBLIC + ethercat_interface::ethercat_interface + pluginlib::pluginlib yaml-cpp ) @@ -70,7 +65,10 @@ if(BUILD_TESTING) test_generic_ec_slave test/test_generic_ec_slave.cpp ) - target_include_directories(test_generic_ec_slave PRIVATE include) + target_include_directories(test_generic_ec_slave PRIVATE + $ + $ + ) target_link_libraries(test_generic_ec_slave ${PROJECT_NAME} ) diff --git a/ethercat_interface/CMakeLists.txt b/ethercat_interface/CMakeLists.txt index 79cf4b9d..fb841aa0 100644 --- a/ethercat_interface/CMakeLists.txt +++ b/ethercat_interface/CMakeLists.txt @@ -23,38 +23,34 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) find_library(ETHERCAT_LIB ethercat HINTS ${ETHERLAB_DIR}/lib) -ament_export_include_directories( - include - ${ETHERLAB_DIR}/include -) - add_library( ${PROJECT_NAME} SHARED src/ec_master.cpp) -target_include_directories( - ${PROJECT_NAME} - PRIVATE - include +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ ${ETHERLAB_DIR}/include ) -target_link_libraries(${PROJECT_NAME} ${ETHERCAT_LIB}) - -ament_target_dependencies( - ${PROJECT_NAME} - rclcpp +target_link_libraries(${PROJECT_NAME} + ${ETHERCAT_LIB} + rclcpp::rclcpp ) # INSTALL install( TARGETS ${PROJECT_NAME} - DESTINATION lib + EXPORT export_${PROJECT_NAME} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin ) + install( DIRECTORY include/ - DESTINATION include + DESTINATION include/${PROJECT_NAME} ) if(BUILD_TESTING) @@ -79,13 +75,7 @@ if(BUILD_TESTING) endif() ## EXPORTS -ament_export_include_directories( - include -) -ament_export_libraries( - ${PROJECT_NAME} - ${ETHERCAT_LIBRARY} -) +ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) ament_export_dependencies( rclcpp ) diff --git a/ethercat_manager/CMakeLists.txt b/ethercat_manager/CMakeLists.txt index a1e5837c..750493fb 100644 --- a/ethercat_manager/CMakeLists.txt +++ b/ethercat_manager/CMakeLists.txt @@ -31,8 +31,11 @@ target_include_directories( include ${ETHERLAB_DIR}/include ) -target_link_libraries(ethercat_sdo_srv_server ${ETHERCAT_LIB}) -ament_target_dependencies(ethercat_sdo_srv_server rclcpp ethercat_msgs) +target_link_libraries(ethercat_sdo_srv_server PUBLIC + ${ETHERCAT_LIB} + rclcpp::rclcpp + ${ethercat_msgs_TARGETS} +) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED)