diff --git a/ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake b/ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake index aaf96670..a500f5b2 100644 --- a/ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake +++ b/ament_cmake_export_targets/cmake/ament_cmake_export_targets_package_hook.cmake @@ -28,7 +28,7 @@ if(NOT _AMENT_CMAKE_EXPORT_TARGETS STREQUAL "") install( EXPORT "${_target}" DESTINATION share/${PROJECT_NAME}/cmake - NAMESPACE "${PROJECT_NAME}::" + NAMESPACE "${_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE}" FILE "${_target}Export.cmake" ) endforeach() diff --git a/ament_cmake_export_targets/cmake/ament_export_targets.cmake b/ament_cmake_export_targets/cmake/ament_export_targets.cmake index f48a1247..b4071a5d 100644 --- a/ament_cmake_export_targets/cmake/ament_export_targets.cmake +++ b/ament_cmake_export_targets/cmake/ament_export_targets.cmake @@ -16,12 +16,17 @@ # 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 +# :keyword NAMESPACE: the exported namespace for the target if set. +# The default is the value of ``${PROJECT_NAME}::``. +# This is an advanced option. It should be used carefully and clearly documented +# in a usage guide for any package that makes use of this option. +# :type NAMESPACE: string # :param ARGN: a list of export names # :type ARGN: list of strings # @@ -32,7 +37,7 @@ 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() @@ -40,6 +45,13 @@ macro(ament_export_targets) list(APPEND _AMENT_CMAKE_EXPORT_TARGETS "${_arg}") endforeach() + set(_AMENT_CMAKE_EXPORT_TARGETS_NAMESPACE ${_ARG_NAMESPACE}) + + # 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})