Skip to content

Commit

Permalink
Add NAMESPACE support to ament_export_targets
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Jan 19, 2024
1 parent a6a7e0c commit 4c3d9b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ list(APPEND ${PROJECT_NAME}_CONFIG_EXTRAS "${_generated_extra_file}")
# install export files for targets
if(NOT _AMENT_CMAKE_EXPORT_TARGETS STREQUAL "")
foreach(_target ${_AMENT_CMAKE_EXPORT_TARGETS})

install(
EXPORT "${_target}"
DESTINATION share/${PROJECT_NAME}/cmake
NAMESPACE "${PROJECT_NAME}::"
NAMESPACE "${_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE}"
FILE "${_target}Export.cmake"
)
endforeach()
Expand Down
14 changes: 12 additions & 2 deletions ament_cmake_export_targets/cmake/ament_export_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
# Export targets to downstream packages.
#
# Each export name must have been used to install targets using
# ``install(TARGETS ... EXPORT name ...)``.
# ``install(TARGETS ... EXPORT name NAMESPACE my_namespace ...)``.
# The ``install(EXPORT ...)`` invocation is handled by this macros.
#
# :param HAS_LIBRARY_TARGET: if set, an environment variable will be defined
# so that the library can be found at runtime
# :type HAS_LIBRARY_TARGET: option
# :param NAMESPACE: the exported namespace for the target if set.
# The default is the value of ``${PROJECT_NAME}::``.
# TODO not sure what to set for type and whatnot
# :type NAMESPACE: option
# :param ARGN: a list of export names
# :type ARGN: list of strings
#
Expand All @@ -32,14 +36,20 @@ macro(ament_export_targets)
message(FATAL_ERROR
"ament_export_targets() must be called before ament_package()")
endif()
cmake_parse_arguments(_ARG "HAS_LIBRARY_TARGET" "" "" ${ARGN})
cmake_parse_arguments(_ARG "HAS_LIBRARY_TARGET" "NAMESPACE" "" ${ARGN})

if(${ARGC} GREATER 0)
_ament_cmake_export_targets_register_package_hook()
foreach(_arg ${_ARG_UNPARSED_ARGUMENTS})
list(APPEND _AMENT_CMAKE_EXPORT_TARGETS "${_arg}")
set(_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE ${_ARG_NAMESPACE})
endforeach()

# Allow optionally overriding default namespace
if(NOT DEFINED _AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE)
set(_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE "${PROJECT_NAME}::")
endif()

# if the export name contains is a library target
# make sure to register an environment hook
if(${_ARG_HAS_LIBRARY_TARGET})
Expand Down

0 comments on commit 4c3d9b1

Please sign in to comment.