From 6476e996c02b3327dbe63d3ef7fc7cd3d9f98b68 Mon Sep 17 00:00:00 2001 From: Takashi Sato Date: Mon, 6 May 2024 21:58:15 +0900 Subject: [PATCH] fixed target of ament_export_libraries (#295) (cherry picked from commit db4d8b0aeb77a986fa392b53b4cf46603777452e) # Conflicts: # gz_ros2_control/CMakeLists.txt --- gz_ros2_control/CMakeLists.txt | 122 +++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 gz_ros2_control/CMakeLists.txt diff --git a/gz_ros2_control/CMakeLists.txt b/gz_ros2_control/CMakeLists.txt new file mode 100644 index 00000000..acc7d047 --- /dev/null +++ b/gz_ros2_control/CMakeLists.txt @@ -0,0 +1,122 @@ +cmake_minimum_required(VERSION 3.5) +project(gz_ros2_control) + +# Default to C11 +if(NOT CMAKE_C_STANDARD) + set(CMAKE_C_STANDARD 11) +endif() +# Default to C++17 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() + +# Compiler options +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# Find dependencies +find_package(ament_cmake REQUIRED) +find_package(ament_index_cpp REQUIRED) +find_package(controller_manager REQUIRED) +find_package(hardware_interface REQUIRED) +find_package(pluginlib REQUIRED) +find_package(rclcpp REQUIRED) +find_package(yaml_cpp_vendor REQUIRED) + +set(GZ_PLUGIN) +set(GZ_SIM) + +if("$ENV{GZ_VERSION}" STREQUAL "garden") + find_package(gz-sim7 REQUIRED) + set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR}) + message(STATUS "Compiling against Gazebo Garden") + find_package(gz-plugin2 REQUIRED) + set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR}) + set(GZ_PLUGIN gz-plugin${GZ_PLUGIN_VER}::register) + set(GZ_SIM gz-sim${GZ_SIM_VER}::core) + add_definitions(-DGZ_HEADERS) +elseif("$ENV{GZ_VERSION}" STREQUAL "harmonic") + find_package(gz-sim8 REQUIRED) + set(GZ_SIM_VER ${gz-sim8_VERSION_MAJOR}) + message(STATUS "Compiling against Gazebo Harmonic") + find_package(gz-plugin2 REQUIRED) + set(GZ_PLUGIN_VER ${gz-plugin2_VERSION_MAJOR}) + set(GZ_PLUGIN gz-plugin${GZ_PLUGIN_VER}::register) + set(GZ_SIM gz-sim${GZ_SIM_VER}::core) + add_definitions(-DGZ_HEADERS) +else() + find_package(ignition-gazebo6 REQUIRED) + set(GZ_SIM_VER ${ignition-gazebo6_VERSION_MAJOR}) + message(STATUS "Compiling against Gazebo Fortress") + find_package(ignition-plugin1 REQUIRED) + set(GZ_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR}) + set(GZ_PLUGIN ignition-plugin${GZ_PLUGIN_VER}::register) + set(GZ_SIM ignition-gazebo${GZ_SIM_VER}::core) +endif() + +include_directories(include) + +add_library(${PROJECT_NAME}-system SHARED + src/gz_ros2_control_plugin.cpp +) + +target_link_libraries(${PROJECT_NAME}-system + ${GZ_SIM} + ${GZ_PLUGIN} +) +ament_target_dependencies(${PROJECT_NAME}-system + ament_index_cpp + controller_manager + hardware_interface + pluginlib + rclcpp + yaml_cpp_vendor + rclcpp_lifecycle +) + +######### + +add_library(gz_hardware_plugins SHARED + src/gz_system.cpp +) +ament_target_dependencies(gz_hardware_plugins + rclcpp_lifecycle + hardware_interface + rclcpp +) +target_link_libraries(gz_hardware_plugins + ${GZ_SIM} +) + +## Install +install(TARGETS + gz_hardware_plugins + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +install(DIRECTORY + include/ + DESTINATION include +) + +# Testing and linting +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}-system gz_hardware_plugins) + +# Install directories +install(TARGETS ${PROJECT_NAME}-system + DESTINATION lib +) + +pluginlib_export_plugin_description_file(gz_ros2_control gz_hardware_plugins.xml) + +# Setup the project +ament_package()