48
48
# project, expose the external project globally to any downstream CMake
49
49
# projects.
50
50
# :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.
51
76
#
52
77
# @public
53
78
#
@@ -60,7 +85,7 @@ macro(ament_vendor TARGET_NAME)
60
85
message (FATAL_ERROR "ament_vendor() must be called before ament_package()" )
61
86
endif ()
62
87
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} )
64
89
if (_ARG_UNPARSED_ARGUMENTS )
65
90
message (FATAL_ERROR "ament_vendor() called with unused arguments: "
66
91
"${_ARG_UNPARSED_ARGUMENTS} " )
@@ -93,15 +118,57 @@ macro(ament_vendor TARGET_NAME)
93
118
set (_ARG_SATISFIED FALSE )
94
119
endif ()
95
120
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
+
96
129
option (FORCE_BUILD_VENDOR_PKG
97
130
"Build vendor packages from source, even if system-installed packages are available"
98
131
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
99
145
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 )
101
148
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 " )
103
150
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 ()
104
170
171
+ if (_call_ament_vendor )
105
172
list_append_unique (_AMENT_CMAKE_VENDOR_PACKAGE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR} /${TARGET_NAME} -prefix/install" )
106
173
107
174
_ament_vendor (
@@ -115,6 +182,12 @@ macro(ament_vendor TARGET_NAME)
115
182
"${_ARG_SKIP_INSTALL} "
116
183
)
117
184
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
+
118
191
if (NOT _ament_vendor_called AND NOT _ARG_SKIP_INSTALL )
119
192
# Hooks for CMAKE_PREFIX_PATH
120
193
if (_ARG_GLOBAL_HOOK )
@@ -142,8 +215,6 @@ macro(ament_vendor TARGET_NAME)
142
215
143
216
set (_ament_vendor_called TRUE )
144
217
endif ()
145
- else ()
146
- message (STATUS "Skipping vendor package build for '${TARGET_NAME} ', which is already satisfied" )
147
218
endif ()
148
219
endmacro ()
149
220
0 commit comments