ros2_target_depends.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
  9. if (${${_package}_FOUND_AMENT_PACKAGE})
  10. message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
  11. target_link_libraries(${TARGET_NAME} PUBLIC ${${_package}_TARGETS})
  12. else ()
  13. message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
  14. endif ()
  15. endfunction()
  16. function(target_depends_on_ros2_packages TARGET_NAME)
  17. foreach (_package IN LISTS ARGN)
  18. target_depends_on_ros2_package(${TARGET_NAME} ${_package} REQUIRED)
  19. endforeach ()
  20. endfunction()
  21. function(target_interface_depends_on_ros2_package TARGET_NAME)
  22. list(GET ARGN 0 _package)
  23. find_package(${ARGN})
  24. include(${${_package}_DIR}/${_package}Config.cmake OPTIONAL)
  25. if (${${_package}_FOUND_AMENT_PACKAGE})
  26. message(DEBUG "Package ${_package} was found (${${_package}_DIR}) version ${${_package}_VERSION} targets : ${${_package}_TARGETS}")
  27. target_link_libraries(${TARGET_NAME} INTERFACE ${${_package}_TARGETS})
  28. else ()
  29. message(FATAL_ERROR "Package ${_package} was found (${${_package}_DIR}), but package is not an Ament package.")
  30. endif ()
  31. endfunction()
  32. function(target_interface_depends_on_ros2_packages TARGET_NAME)
  33. foreach (_package IN LISTS ARGN)
  34. target_interface_depends_on_ros2_package(${TARGET_NAME} ${_package} REQUIRED)
  35. endforeach ()
  36. endfunction()