Skip to content

Commit 3e77b2f

Browse files
committed
ament_vendor: Add IS_VENDORED_OUTPUT_VARIABLE_NAME argument and AMENT_VENDOR_POLICY CMake option
Signed-off-by: Silvio <[email protected]>
1 parent 17d4da4 commit 3e77b2f

File tree

1 file changed

+76
-5
lines changed

1 file changed

+76
-5
lines changed

ament_cmake_vendor_package/cmake/ament_vendor.cmake

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@
4848
# project, expose the external project globally to any downstream CMake
4949
# projects.
5050
# :type GLOBAL_HOOK: option
51+
# :param IS_VENDORED_OUTPUT_VARIABLE_NAME: the name of the variable that
52+
# will be set to ``TRUE`` if the package has been vendored, or ``FALSE``
53+
# otherwise.
54+
# :type IS_VENDORED_OUTPUT_VARIABLE_NAME: string
55+
#
56+
# Beside proper CMake macro arguments, the macro also is influenced by the
57+
# following CMake advanced options, that can be set from the CMake command
58+
# line when the project that contains the 'ament_vendor' call is configured.
59+
#
60+
# AMENT_VENDOR_POLICY: String option that specifies how ament_vendor behaves,
61+
# the allowed values are listed in the following.
62+
# DEFAULT: Vendor if ``SATISFIED`` argument is not supplied or false,
63+
# do not vendor otherwise.
64+
# FORCE_BUILD_VENDOR: Always vendor, independently of the value of the
65+
# ``SATISFIED`` argument.
66+
# NEVER_VENDOR: Never vendor, and raise an error if ``SATISFIED`` argument
67+
# is not supplied or false.
68+
# NEVER_VENDOR_IGNORE_SATISFIED_CHECK: Never vendor, and do not raise
69+
# an error even if ``SATISFIED`` argument is not supplied
70+
# or false. This option is in unsupported by most packages,
71+
# so use at your own risk, as it could break the buid.
72+
#
73+
# To check if a package has been actually vendored, downstream users of
74+
# ``ament_vendor` can pass a variable name to IS_VENDORED_OUTPUT_VARIABLE_NAME
75+
# argument, and check its value.
5176
#
5277
# @public
5378
#
@@ -60,7 +85,7 @@ macro(ament_vendor TARGET_NAME)
6085
message(FATAL_ERROR "ament_vendor() must be called before ament_package()")
6186
endif()
6287

63-
cmake_parse_arguments(_ARG "GLOBAL_HOOK;SKIP_INSTALL" "SOURCE_SUBDIR;VCS_TYPE;VCS_URL;VCS_VERSION;SATISFIED" "CMAKE_ARGS;PATCHES" ${ARGN})
88+
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})
6489
if(_ARG_UNPARSED_ARGUMENTS)
6590
message(FATAL_ERROR "ament_vendor() called with unused arguments: "
6691
"${_ARG_UNPARSED_ARGUMENTS}")
@@ -93,15 +118,57 @@ macro(ament_vendor TARGET_NAME)
93118
set(_ARG_SATISFIED FALSE)
94119
endif()
95120

121+
# If defined, let's set ${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} to FALSE, it will be set
122+
# to TRUE if the package is actually vendored
123+
if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME)
124+
# There is no PARENT_SCOPE as this is a cmake macro,
125+
# if it is converted to a function PARENT_SCOPE will need to be added
126+
set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} FALSE)
127+
endif()
128+
96129
option(FORCE_BUILD_VENDOR_PKG
97130
"Build vendor packages from source, even if system-installed packages are available"
98131
OFF)
132+
mark_as_advanced(FORCE_BUILD_VENDOR_PKG)
133+
134+
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.")
135+
set(AMENT_VENDOR_POLICY "DEFAULT" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS})
136+
set_property(CACHE AMENT_VENDOR_POLICY PROPERTY STRINGS "DEFAULT" "FORCE_BUILD_VENDOR" "NEVER_VENDOR" "NEVER_VENDOR_IGNORE_SATISFIED_CHECK")
137+
mark_as_advanced(AMENT_VENDOR_POLICY)
138+
139+
if(FORCE_BUILD_VENDOR_PKG AND NOT AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR")
140+
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.")
141+
set(CMAKE_BUILD_TYPE "FORCE_BUILD_VENDOR" CACHE STRING ${_AMENT_VENDOR_POLICY_DOCS} FORCE)
142+
endif()
143+
144+
# AMENT_VENDOR_POLICY
99145

100-
if(NOT _ARG_SATISFIED OR FORCE_BUILD_VENDOR_PKG)
146+
if(AMENT_VENDOR_POLICY STREQUAL "FORCE_BUILD_VENDOR")
147+
set(_call_ament_vendor TRUE)
101148
if(_ARG_SATISFIED)
102-
message(STATUS "Forcing vendor package build for '${TARGET_NAME}', which is already satisfied")
149+
message(STATUS "Forcing vendor package build for '${TARGET_NAME}', which is already satisfied as AMENT_VENDOR_POLICY is set to FORCE_BUILD_VENDOR")
103150
endif()
151+
elseif(AMENT_VENDOR_POLICY STREQUAL "NEVER_VENDOR")
152+
if(NOT _ARG_SATISFIED)
153+
message(FATAL_ERROR "Error as SATISFIED argument is not TRUE, but AMENT_VENDOR_POLICY is set to NEVER_VENDOR")
154+
endif()
155+
set(_call_ament_vendor FALSE)
156+
elseif(AMENT_VENDOR_POLICY STREQUAL "NEVER_VENDOR_IGNORE_SATISFIED_CHECK")
157+
if(NOT _ARG_SATISFIED)
158+
message(STATUS "Not vendoring even if SATISFIED is not TRUE as AMENT_VENDOR_POLICY is set to NEVER_VENDOR_IGNORE_SATISFIED_CHECK")
159+
endif()
160+
set(_call_ament_vendor FALSE)
161+
else()
162+
# This is the default case
163+
if(_ARG_SATISFIED)
164+
message(STATUS "Skipping vendor package build for '${TARGET_NAME}', as SATISFIED is TRUE and AMENT_VENDOR_POLICY is set to DEFAULT")
165+
set(_call_ament_vendor FALSE)
166+
else()
167+
set(_call_ament_vendor TRUE)
168+
endif()
169+
endif()
104170

171+
if(_call_ament_vendor)
105172
list_append_unique(_AMENT_CMAKE_VENDOR_PACKAGE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}-prefix/install")
106173

107174
_ament_vendor(
@@ -115,6 +182,12 @@ macro(ament_vendor TARGET_NAME)
115182
"${_ARG_SKIP_INSTALL}"
116183
)
117184

185+
if(DEFINED _ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME)
186+
# There is no PARENT_SCOPE as this is a cmake macro,
187+
# if it is converted to a function PARENT_SCOPE will need to be added
188+
set(${_ARG_IS_VENDORED_OUTPUT_VARIABLE_NAME} TRUE)
189+
endif()
190+
118191
if(NOT _ament_vendor_called AND NOT _ARG_SKIP_INSTALL)
119192
# Hooks for CMAKE_PREFIX_PATH
120193
if(_ARG_GLOBAL_HOOK)
@@ -142,8 +215,6 @@ macro(ament_vendor TARGET_NAME)
142215

143216
set(_ament_vendor_called TRUE)
144217
endif()
145-
else()
146-
message(STATUS "Skipping vendor package build for '${TARGET_NAME}', which is already satisfied")
147218
endif()
148219
endmacro()
149220

0 commit comments

Comments
 (0)