Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support components in ament_export_dependencies #457

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ if(NOT _exported_dependencies STREQUAL "")
set(@PROJECT_NAME@_RECURSIVE_DEPENDENCIES ${_exported_dependencies})
set(_libraries)
foreach(_dep ${_exported_dependencies})
if(NOT ${_dep}_FOUND)
find_package("${_dep}" QUIET REQUIRED)
# unpack components (if any)
string(REGEX REPLACE ":" ";" _unpacked "${_dep}")
list(POP_FRONT _unpacked _dep)
if(NOT "${_unpacked}" STREQUAL "")
# has components
find_package("${_dep}" QUIET REQUIRED COMPONENTS "${_unpacked}")
else()
# no components
if(NOT ${_dep}_FOUND)
find_package("${_dep}" QUIET REQUIRED)
endif()
endif()
# if a package provides modern CMake interface targets use them
# exclusively assuming the classic CMake variables only exist for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@
#
# Export dependencies to downstream packages.
#
# Behavior depends on whether ``COMPONENTS`` parameter is provided. If provided,
# ``ament_export_dependencies`` expects a single package name, followed a list
# of components to export. Otherwise, it expects a list of packages to export.
# Each package name must be find_package()-able with the exact same case.
# Additionally the exported variables must have a prefix with the same case
# and the suffixes must be INCLUDE_DIRS and LIBRARIES.
#
# :param ARGN: a list of package names
# :type ARGN: list of strings
# :param COMPONENTS: optional list of components. In such cas, only 1 package
# name shall be listed
# :type COMPONENTS: list of strings
#
# @public
#
Expand All @@ -32,12 +38,32 @@ macro(ament_export_dependencies)

if(${ARGC} GREATER 0)
_ament_cmake_export_dependencies_register_package_hook()
foreach(_arg ${ARGN})
# only pass package name
# will be resolved by downstream packages
# must be find_package()-able
# and provide _INCLUDE_DIRS and _LIBRARIES
list(APPEND _AMENT_CMAKE_EXPORT_DEPENDENCIES "${_arg}")
endforeach()

cmake_parse_arguments(_ARGS "" "" "COMPONENTS" ${ARGN})
if(NOT "${_ARGS_COMPONENTS}" STREQUAL "")
# parse a single dependency with its components
list(LENGTH _ARGS_UNPARSED_ARGUMENTS _unparsed_length)
if (NOT ${_unparsed_length} EQUAL "1")
message(FATAL_ERROR
"ament_export_dependencies() called with unknown arguments: ${ARGN}")
endif()
# pack the dependency and all its components "dep:compA:compB:compC"
# TODO use AMENT_BUILD_CONFIGURATION_KEYWORD_SEPARATOR-like variable instead of hardcoded ":"?
set (_unpacked "${_ARGS_UNPARSED_ARGUMENTS}")
list(APPEND _unpacked "${_ARGS_COMPONENTS}")
string(REGEX REPLACE ";" ":" _packed "${_unpacked}")
list(APPEND _AMENT_CMAKE_EXPORT_DEPENDENCIES "${_packed}")

else()
foreach(_arg ${ARGN})
# only pass package name
# will be resolved by downstream packages
# must be find_package()-able
# and provide _INCLUDE_DIRS and _LIBRARIES
list(APPEND _AMENT_CMAKE_EXPORT_DEPENDENCIES "${_arg}")
endforeach()

endif()
endif()

endmacro()