Skip to content

Commit 2fa4231

Browse files
committed
cmake: zephyr_get_property: implement additional options
Extended the zephyr_get_property() CMake function with several convenience options: - AS_STRING: Returns the result as a string rather than a list. Equivalent to specifying DELIMITER " ". - GENEX: Uses generator expressions to get the property entries at build time, for targets that are not yet fully configured. Cannot be used with LANG. Also, CMake will complain if the requested property includes $<COMPILE_OPTIONS:...> expressions. - TARGET <target>: Specifies the target to get the property from. Defaults to "zephyr_interface" as before. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 2be93f4 commit 2fa4231

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

‎cmake/modules/extensions.cmake‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ function(zephyr_ld_options)
164164
target_ld_options(zephyr_interface INTERFACE ${ARGV})
165165
endfunction()
166166

167-
# Getter function for extracting information from zephyr_interface. The
168-
# function supports filtering for specific compile languages, prefixes, and
167+
# Getter function for extracting information from a target. The function
168+
# supports filtering for specific compile languages, prefixes, and
169169
# different output formats.
170170
#
171171
# The result is always returned as a generator expression, so its actual
@@ -179,39 +179,64 @@ endfunction()
179179
# - 'prop' is the CMake property to get from the target
180180
#
181181
# Options:
182+
# - AS_STRING:
183+
# Return the result as a string rather than a list. Equivalent to
184+
# specifying DELIMITER " ".
182185
# - DELIMITER <delimiter>:
183186
# Specify the output delimiter to use for the list entries. Defaults to
184187
# "$<SEMICOLON>".
188+
# - GENEX:
189+
# Use generator expressions to get the property entries at build time,
190+
# for targets that are not yet fully configured.
191+
# Cannot be used with LANG. Also, CMake will complain if the requested
192+
# property includes $<COMPILE_OPTIONS:...> expressions.
185193
# - LANG <C|CXX|ASM>:
186194
# When set, the property value is filtered for $<COMPILE_LANGUAGE:lang>
187195
# entries, and only those matching the given language are kept.
196+
# Cannot be used with GENEX.
188197
# - PREFIX <prefix>:
189198
# Specify a prefix to use for each entry in the output list.
190199
# - STRIP_PREFIX:
191200
# Omit the prefix string, even if given by PREFIX.
201+
# - TARGET <target>:
202+
# Specify the target to get the property from. Defaults to
203+
# "zephyr_interface".
192204

193205
function(zephyr_get_property output)
194-
set(options STRIP_PREFIX)
195-
set(single_args DELIMITER LANG PREFIX PROPERTY)
206+
set(options AS_STRING GENEX STRIP_PREFIX)
207+
set(single_args DELIMITER LANG PREFIX PROPERTY TARGET)
196208
cmake_parse_arguments(args "${options}" "${single_args}" "" ${ARGN})
197209
zephyr_check_arguments_required_all(zephyr_get_property args PROPERTY)
198210
if(args_UNPARSED_ARGUMENTS)
199211
message(FATAL_ERROR "zephyr_get_property() given unknown arguments: ${args_UNPARSED_ARGUMENTS}")
200212
endif()
213+
set_ifndef(args_TARGET "zephyr_interface")
201214

202-
set_ifndef(args_DELIMITER "$<SEMICOLON>")
215+
if(args_AS_STRING)
216+
set(args_DELIMITER " ")
217+
else()
218+
set_ifndef(args_DELIMITER "$<SEMICOLON>")
219+
endif()
203220

204221
if(args_PREFIX AND NOT args_STRIP_PREFIX)
205222
set(maybe_prefix "${args_PREFIX}")
206223
endif()
207224

208-
get_property(flags TARGET zephyr_interface PROPERTY ${args_PROPERTY})
209-
if(args_LANG)
210-
process_flags(${args_LANG} flags output_list)
225+
if(args_LANG AND args_GENEX)
226+
message(FATAL_ERROR "zephyr_get_property(): GENEX cannot be used with LANG.")
227+
endif()
228+
229+
if(args_GENEX)
230+
set(genexp_output_list "$<TARGET_PROPERTY:${args_TARGET},${args_PROPERTY}>")
211231
else()
212-
set(output_list "${flags}")
232+
get_property(flags TARGET ${args_TARGET} PROPERTY ${args_PROPERTY})
233+
if(args_LANG)
234+
process_flags(${args_LANG} flags output_list)
235+
else()
236+
set(output_list "${flags}")
237+
endif()
238+
string(REPLACE ";" "$<SEMICOLON>" genexp_output_list "${output_list}")
213239
endif()
214-
string(REPLACE ";" "$<SEMICOLON>" genexp_output_list "${output_list}")
215240

216241
set(result_output_list "${maybe_prefix}$<JOIN:${genexp_output_list},${args_DELIMITER}${maybe_prefix}>")
217242
set(maybe_result_output_list "$<$<BOOL:${genexp_output_list}>:${result_output_list}>")

0 commit comments

Comments
 (0)