From b530c4b223e64d9e51214663379a39c34072a729 Mon Sep 17 00:00:00 2001 From: Silvio Date: Thu, 3 Jul 2025 10:14:56 +0200 Subject: [PATCH 1/6] ament_vendor: Add IS_VENDORED_OUTPUT_VARIABLE_NAME argument and AMENT_VENDOR_POLICY CMake option Signed-off-by: Silvio Signed-off-by: Silvio Traversaro --- .../cmake/ament_vendor.cmake | 81 +++++++++++++++++-- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index 0b1a86c1..2ca2f40a 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -48,6 +48,31 @@ # project, expose the external project globally to any downstream CMake # projects. # :type GLOBAL_HOOK: option +# :param IS_VENDORED_OUTPUT_VARIABLE_NAME: the name of the variable that +# will be set to ``TRUE`` if the package has been vendored, or ``FALSE`` +# otherwise. +# :type IS_VENDORED_OUTPUT_VARIABLE_NAME: string +# +# Beside proper CMake macro arguments, the macro also is influenced by the +# following CMake advanced options, that can be set from the CMake command +# line when the project that contains the 'ament_vendor' call is configured. +# +# AMENT_VENDOR_POLICY: String option that specifies how ament_vendor behaves, +# the allowed values are listed in the following. +# DEFAULT: Vendor if ``SATISFIED`` argument is not supplied or false, +# do not vendor otherwise. +# FORCE_BUILD_VENDOR: Always vendor, independently of the value of the +# ``SATISFIED`` argument. +# NEVER_VENDOR: Never vendor, and raise an error if ``SATISFIED`` argument +# is not supplied or false. +# NEVER_VENDOR_IGNORE_SATISFIED_CHECK: Never vendor, and do not raise +# an error even if ``SATISFIED`` argument is not supplied +# or false. This option is in unsupported by most packages, +# so use at your own risk, as it could break the buid. +# +# To check if a package has been actually vendored, downstream users of +# ``ament_vendor` can pass a variable name to IS_VENDORED_OUTPUT_VARIABLE_NAME +# argument, and check its value. # # @public # @@ -60,7 +85,7 @@ macro(ament_vendor TARGET_NAME) message(FATAL_ERROR "ament_vendor() must be called before ament_package()") endif() - cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED" "CMAKE_ARGS;PATCHES" ${ARGN}) + cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED;IS_VENDORED_OUTPUT_VARIABLE_NAME" "CMAKE_ARGS;PATCHES" ${ARGN}) if(_ARG_UNPARSED_ARGUMENTS) message(FATAL_ERROR "ament_vendor() called with unused arguments: " "${_ARG_UNPARSED_ARGUMENTS}") @@ -93,15 +118,57 @@ macro(ament_vendor TARGET_NAME) set(_ARG_SATISFIED FALSE) endif() + # If defined, let's set ${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} to FALSE, it will be set + # to TRUE if the package is actually vendored + if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME) + # There is no PARENT_SCOPE as this is a cmake macro, + # if it is converted to a function PARENT_SCOPE will need to be added + set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} FALSE) + endif() + option(FORCE_BUILD_VENDOR_PKG "Build vendor packages from source, even if system-installed packages are available" OFF) + mark_as_advanced(FORCE_BUILD_VENDOR_PKG) + + set(_AMENT_VENDOR_POLICY_DOCS "Specify how ament_vendor behaves, allowed values are DEFAULT, FORCE_BUILD_VENDOR, NEVER_VENDOR and NEVER_VENDOR_IGNORE_SATISFIED_CHECK.") + set(AMENT_VENDOR_POLICY "DEFAULT" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS}) + set_property(CACHE AMENT_VENDOR_POLICY PROPERTY STRINGS "DEFAULT" "FORCE_BUILD_VENDOR" "NEVER_VENDOR" "NEVER_VENDOR_IGNORE_SATISFIED_CHECK") + mark_as_advanced(AMENT_VENDOR_POLICY) + + if(FORCE_BUILD_VENDOR_PKG AND NOT AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR") + message(DEPRECATION "FORCE_BUILD_VENDOR_PKG set to ON detected, FORCE_BUILD_VENDOR_PKG variable is deprecated, please set AMENT_VENDOR_POLICY to FORCE_BUILD_VENDOR instead.") + set(CMAKE_BUILD_TYPE "FORCE_BUILD_VENDOR" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS} FORCE) + endif() + + # AMENT_VENDOR_POLICY - if(NOT _ARG_SATISFIED OR FORCE_BUILD_VENDOR_PKG) + if(AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR") + set(_call_ament_vendor TRUE) if(_ARG_SATISFIED) - message(STATUS "Forcing vendor package build for '${TARGET_NAME}', which is already satisfied") + message(STATUS "Forcing vendor package build for '${TARGET_NAME}', which is already satisfied as AMENT_VENDOR_POLICY is set to FORCE_BUILD_VENDOR") endif() + elseif(AMENT_VENDOR_POLICY STREQUAL "NEVER_VENDOR") + if(NOT _ARG_SATISFIED) + message(FATAL_ERROR "Error as SATISFIED argument is not TRUE, but AMENT_VENDOR_POLICY is set to NEVER_VENDOR") + endif() + set(_call_ament_vendor FALSE) + elseif(AMENT_VENDOR_POLICY STREQUAL "NEVER_VENDOR_IGNORE_SATISFIED_CHECK") + if(NOT _ARG_SATISFIED) + message(STATUS "Not vendoring even if SATISFIED is not TRUE as AMENT_VENDOR_POLICY is set to NEVER_VENDOR_IGNORE_SATISFIED_CHECK") + endif() + set(_call_ament_vendor FALSE) + else() + # This is the default case + if(_ARG_SATISFIED) + message(STATUS "Skipping vendor package build for '${TARGET_NAME}', as SATISFIED is TRUE and AMENT_VENDOR_POLICY is set to DEFAULT") + set(_call_ament_vendor FALSE) + else() + set(_call_ament_vendor TRUE) + endif() + endif() + if(_call_ament_vendor) list_append_unique(_AMENT_CMAKE_VENDOR_PACKAGE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}-prefix/install") _ament_vendor( @@ -115,6 +182,12 @@ macro(ament_vendor TARGET_NAME) "${_ARG_SKIP_INSTALL}" ) + if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME) + # There is no PARENT_SCOPE as this is a cmake macro, + # if it is converted to a function PARENT_SCOPE will need to be added + set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} TRUE) + endif() + if(NOT _ament_vendor_called AND NOT _ARG_SKIP_INSTALL) # Hooks for CMAKE_PREFIX_PATH if(_ARG_GLOBAL_HOOK) @@ -142,8 +215,6 @@ macro(ament_vendor TARGET_NAME) set(_ament_vendor_called TRUE) endif() - else() - message(STATUS "Skipping vendor package build for '${TARGET_NAME}', which is already satisfied") endif() endmacro() From d940d58cad2a1e17068130a24253b7932866d025 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Thu, 17 Jul 2025 22:01:54 +0200 Subject: [PATCH 2/6] Improve documentation by using active voice Co-authored-by: Shane Loretz Signed-off-by: Silvio Traversaro Signed-off-by: Silvio Traversaro --- .../cmake/ament_vendor.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index 2ca2f40a..c41fb8d4 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -53,9 +53,13 @@ # otherwise. # :type IS_VENDORED_OUTPUT_VARIABLE_NAME: string # -# Beside proper CMake macro arguments, the macro also is influenced by the -# following CMake advanced options, that can be set from the CMake command -# line when the project that contains the 'ament_vendor' call is configured. +# The AMENT_VENDOR_POLICY cache entry and the SATISFIED argument +# control whether or not this function builds the vendor package. +# If you want something other than the default, set AMENT_VENDOR_POLICY via the +# command line: +# +# * If you are using cmake directly: cmake -DAMENT_VENDOR_POLICY:STRING=DEFAULT ... +# * If you are using colcon: colcon --cmake-args -DAMENT_VENDOR_POLICY:STRING=DEFAULT ... # # AMENT_VENDOR_POLICY: String option that specifies how ament_vendor behaves, # the allowed values are listed in the following. @@ -70,9 +74,9 @@ # or false. This option is in unsupported by most packages, # so use at your own risk, as it could break the buid. # -# To check if a package has been actually vendored, downstream users of -# ``ament_vendor` can pass a variable name to IS_VENDORED_OUTPUT_VARIABLE_NAME -# argument, and check its value. +# To check if a package has been actually vendored, pass a variable name +# into the argument IS_VENDORED_OUTPUT_VARIABLE_NAME, and check +# if the variable is TRUE after you call `ament_vendor`. # # @public # From 0f7fa8a0d5bca2a7baa58d78f31b5d08feb0a62b Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sat, 28 Feb 2026 14:58:10 +0100 Subject: [PATCH 3/6] Remove IS_VENDORED_OUTPUT_VARIABLE_NAME output variable Signed-off-by: Silvio Traversaro --- .../cmake/ament_vendor.cmake | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index c41fb8d4..aa7bc6c7 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -48,10 +48,6 @@ # project, expose the external project globally to any downstream CMake # projects. # :type GLOBAL_HOOK: option -# :param IS_VENDORED_OUTPUT_VARIABLE_NAME: the name of the variable that -# will be set to ``TRUE`` if the package has been vendored, or ``FALSE`` -# otherwise. -# :type IS_VENDORED_OUTPUT_VARIABLE_NAME: string # # The AMENT_VENDOR_POLICY cache entry and the SATISFIED argument # control whether or not this function builds the vendor package. @@ -74,9 +70,8 @@ # or false. This option is in unsupported by most packages, # so use at your own risk, as it could break the buid. # -# To check if a package has been actually vendored, pass a variable name -# into the argument IS_VENDORED_OUTPUT_VARIABLE_NAME, and check -# if the variable is TRUE after you call `ament_vendor`. +# To check if a package has been actually vendored, check if the target name +# passed as TARGET_NAME exists with if(TARGET ). # # @public # @@ -89,7 +84,7 @@ macro(ament_vendor TARGET_NAME) message(FATAL_ERROR "ament_vendor() must be called before ament_package()") endif() - cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED;IS_VENDORED_OUTPUT_VARIABLE_NAME" "CMAKE_ARGS;PATCHES" ${ARGN}) + cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED" "CMAKE_ARGS;PATCHES" ${ARGN}) if(_ARG_UNPARSED_ARGUMENTS) message(FATAL_ERROR "ament_vendor() called with unused arguments: " "${_ARG_UNPARSED_ARGUMENTS}") @@ -122,14 +117,6 @@ macro(ament_vendor TARGET_NAME) set(_ARG_SATISFIED FALSE) endif() - # If defined, let's set ${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} to FALSE, it will be set - # to TRUE if the package is actually vendored - if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME) - # There is no PARENT_SCOPE as this is a cmake macro, - # if it is converted to a function PARENT_SCOPE will need to be added - set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} FALSE) - endif() - option(FORCE_BUILD_VENDOR_PKG "Build vendor packages from source, even if system-installed packages are available" OFF) @@ -186,12 +173,6 @@ macro(ament_vendor TARGET_NAME) "${_ARG_SKIP_INSTALL}" ) - if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME) - # There is no PARENT_SCOPE as this is a cmake macro, - # if it is converted to a function PARENT_SCOPE will need to be added - set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} TRUE) - endif() - if(NOT _ament_vendor_called AND NOT _ARG_SKIP_INSTALL) # Hooks for CMAKE_PREFIX_PATH if(_ARG_GLOBAL_HOOK) From e1555045ea142c2b5ccf19863fa250f67df9228a Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sat, 28 Feb 2026 15:06:04 +0100 Subject: [PATCH 4/6] Fix typo Co-authored-by: Scott K Logan Signed-off-by: Silvio Traversaro Signed-off-by: Silvio Traversaro --- ament_cmake_vendor_package/cmake/ament_vendor.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index aa7bc6c7..43f81055 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -67,7 +67,7 @@ # is not supplied or false. # NEVER_VENDOR_IGNORE_SATISFIED_CHECK: Never vendor, and do not raise # an error even if ``SATISFIED`` argument is not supplied -# or false. This option is in unsupported by most packages, +# or false. This option is unsupported by most packages, # so use at your own risk, as it could break the buid. # # To check if a package has been actually vendored, check if the target name From 57678fee2294f9d2531bbd966638ea14e7e481ba Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sat, 28 Feb 2026 15:06:46 +0100 Subject: [PATCH 5/6] Do not mark_as_advanced AMENT_VENDOR_POLICY Signed-off-by: Silvio Traversaro --- ament_cmake_vendor_package/cmake/ament_vendor.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index 43f81055..ebfd95cd 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -125,7 +125,6 @@ macro(ament_vendor TARGET_NAME) set(_AMENT_VENDOR_POLICY_DOCS "Specify how ament_vendor behaves, allowed values are DEFAULT, FORCE_BUILD_VENDOR, NEVER_VENDOR and NEVER_VENDOR_IGNORE_SATISFIED_CHECK.") set(AMENT_VENDOR_POLICY "DEFAULT" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS}) set_property(CACHE AMENT_VENDOR_POLICY PROPERTY STRINGS "DEFAULT" "FORCE_BUILD_VENDOR" "NEVER_VENDOR" "NEVER_VENDOR_IGNORE_SATISFIED_CHECK") - mark_as_advanced(AMENT_VENDOR_POLICY) if(FORCE_BUILD_VENDOR_PKG AND NOT AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR") message(DEPRECATION "FORCE_BUILD_VENDOR_PKG set to ON detected, FORCE_BUILD_VENDOR_PKG variable is deprecated, please set AMENT_VENDOR_POLICY to FORCE_BUILD_VENDOR instead.") From f6a75b44dff89f370252ca809aff57d23ee89a99 Mon Sep 17 00:00:00 2001 From: Silvio Traversaro Date: Sat, 7 Mar 2026 09:33:42 +0100 Subject: [PATCH 6/6] Fix wrong CMAKE_BUILD_TYPE set and remove variable pollution Signed-off-by: Silvio Traversaro --- ament_cmake_vendor_package/cmake/ament_vendor.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ament_cmake_vendor_package/cmake/ament_vendor.cmake b/ament_cmake_vendor_package/cmake/ament_vendor.cmake index ebfd95cd..528c05e4 100644 --- a/ament_cmake_vendor_package/cmake/ament_vendor.cmake +++ b/ament_cmake_vendor_package/cmake/ament_vendor.cmake @@ -128,8 +128,9 @@ macro(ament_vendor TARGET_NAME) if(FORCE_BUILD_VENDOR_PKG AND NOT AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR") message(DEPRECATION "FORCE_BUILD_VENDOR_PKG set to ON detected, FORCE_BUILD_VENDOR_PKG variable is deprecated, please set AMENT_VENDOR_POLICY to FORCE_BUILD_VENDOR instead.") - set(CMAKE_BUILD_TYPE "FORCE_BUILD_VENDOR" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS} FORCE) + set(AMENT_VENDOR_POLICY "FORCE_BUILD_VENDOR" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS} FORCE) endif() + unset(_AMENT_VENDOR_POLICY_DOCS) # AMENT_VENDOR_POLICY