Skip to content

Commit 7fdd2d1

Browse files
authored
Add NAMESPACE support to ament_export_targets (#498)
* Add NAMESPACE support to ament_export_targets * Improve documentation for NAMESPACE argument Signed-off-by: Ryan Friedman <[email protected]>
1 parent a6a7e0c commit 7fdd2d1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if(NOT _AMENT_CMAKE_EXPORT_TARGETS STREQUAL "")
2828
install(
2929
EXPORT "${_target}"
3030
DESTINATION share/${PROJECT_NAME}/cmake
31-
NAMESPACE "${PROJECT_NAME}::"
31+
NAMESPACE "${_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE}"
3232
FILE "${_target}Export.cmake"
3333
)
3434
endforeach()

ament_cmake_export_targets/cmake/ament_export_targets.cmake

+14-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
# Export targets to downstream packages.
1717
#
1818
# Each export name must have been used to install targets using
19-
# ``install(TARGETS ... EXPORT name ...)``.
19+
# ``install(TARGETS ... EXPORT name NAMESPACE my_namespace ...)``.
2020
# The ``install(EXPORT ...)`` invocation is handled by this macros.
2121
#
2222
# :param HAS_LIBRARY_TARGET: if set, an environment variable will be defined
2323
# so that the library can be found at runtime
2424
# :type HAS_LIBRARY_TARGET: option
25+
# :keyword NAMESPACE: the exported namespace for the target if set.
26+
# The default is the value of ``${PROJECT_NAME}::``.
27+
# This is an advanced option. It should be used carefully and clearly documented
28+
# in a usage guide for any package that makes use of this option.
29+
# :type NAMESPACE: string
2530
# :param ARGN: a list of export names
2631
# :type ARGN: list of strings
2732
#
@@ -32,14 +37,21 @@ macro(ament_export_targets)
3237
message(FATAL_ERROR
3338
"ament_export_targets() must be called before ament_package()")
3439
endif()
35-
cmake_parse_arguments(_ARG "HAS_LIBRARY_TARGET" "" "" ${ARGN})
40+
cmake_parse_arguments(_ARG "HAS_LIBRARY_TARGET" "NAMESPACE" "" ${ARGN})
3641

3742
if(${ARGC} GREATER 0)
3843
_ament_cmake_export_targets_register_package_hook()
3944
foreach(_arg ${_ARG_UNPARSED_ARGUMENTS})
4045
list(APPEND _AMENT_CMAKE_EXPORT_TARGETS "${_arg}")
4146
endforeach()
4247

48+
set(_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE ${_ARG_NAMESPACE})
49+
50+
# Allow optionally overriding default namespace
51+
if(NOT DEFINED _AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE)
52+
set(_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE "${PROJECT_NAME}::")
53+
endif()
54+
4355
# if the export name contains is a library target
4456
# make sure to register an environment hook
4557
if(${_ARG_HAS_LIBRARY_TARGET})

0 commit comments

Comments
 (0)