ros2_target_depends.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (c) Contributors to the Open 3D Engine Project.
  2. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. #
  4. # SPDX-License-Identifier: Apache-2.0 OR MIT
  5. function(target_depends_on_ros2_package TARGET_NAME)
  6. list(GET ARGN 0 _package)
  7. find_package(${ARGN})
  8. if (${${_package}_FOUND})
  9. include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
  10. if (${${_package}_FOUND_AMENT_PACKAGE})
  11. message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
  12. target_link_libraries(${TARGET_NAME} PUBLIC ${${_package}_TARGETS})
  13. else ()
  14. message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
  15. endif ()
  16. else ()
  17. message(DEBUG "Package ${_package} was not found.")
  18. endif ()
  19. endfunction()
  20. function(target_depends_on_ros2_packages TARGET_NAME)
  21. foreach (_package IN LISTS ARGN)
  22. target_depends_on_ros2_package(${TARGET_NAME} ${_package} REQUIRED)
  23. endforeach ()
  24. endfunction()
  25. function(target_interface_depends_on_ros2_package TARGET_NAME)
  26. list(GET ARGN 0 _package)
  27. find_package(${ARGN})
  28. include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
  29. if (${${_package}_FOUND_AMENT_PACKAGE})
  30. message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
  31. target_link_libraries(${TARGET_NAME} INTERFACE ${${_package}_TARGETS})
  32. else ()
  33. message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
  34. endif ()
  35. endfunction()
  36. function(target_interface_depends_on_ros2_packages TARGET_NAME)
  37. foreach (_package IN LISTS ARGN)
  38. target_interface_depends_on_ros2_package(${TARGET_NAME} ${_package} REQUIRED)
  39. endforeach ()
  40. endfunction()