Skip to content

Commit b5e5ce0

Browse files
committed
cmake: zephyr_get_property: implement additional options
Extended the zephyr_get_property() CMake function with several convenience options: - 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 41bf59c commit b5e5ce0

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

‎cmake/modules/extensions.cmake‎

Lines changed: 24 additions & 9 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
@@ -185,25 +185,36 @@ endfunction()
185185
# - DELIMITER <delimiter>:
186186
# Specify the output delimiter to use for the list entries. Defaults to
187187
# "$<SEMICOLON>". Cannot be used with AS_STRING.
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.
188193
# - LANG <C|CXX|ASM>:
189194
# When set, the property value is filtered for $<COMPILE_LANGUAGE:lang>
190195
# entries, and only those matching the given language are kept.
196+
# Cannot be used with GENEX.
191197
# - PREFIX <prefix>:
192198
# Specify a prefix to use for each entry in the output list. Defaults
193199
# for INCLUDE_DIRECTORIES (-I), SYSTEM_INCLUDE_DIRECTORIES (-isystem),
194200
# COMPILE_DEFINITIONS (-D) and their INTERFACE_ variants are implicit.
195201
# - STRIP_PREFIX:
196202
# Omit the prefix string, even if implicit or given by PREFIX.
203+
# - TARGET <target>:
204+
# Specify the target to get the property from. Defaults to
205+
# "zephyr_interface".
197206

198207
function(zephyr_get_build_property output)
199-
set(options AS_STRING STRIP_PREFIX)
200-
set(single_args DELIMITER LANG PREFIX PROPERTY)
208+
set(options AS_STRING GENEX STRIP_PREFIX)
209+
set(single_args DELIMITER LANG PREFIX PROPERTY TARGET)
201210
cmake_parse_arguments(args "${options}" "${single_args}" "" ${ARGN})
202211
zephyr_check_arguments_required_all(zephyr_get_build_property args PROPERTY)
203212
zephyr_check_arguments_exclusive(zephyr_get_build_property args AS_STRING DELIMITER)
213+
zephyr_check_arguments_exclusive(zephyr_get_build_property args GENEX LANG)
204214
if(args_UNPARSED_ARGUMENTS)
205215
message(FATAL_ERROR "zephyr_get_build_property() given unknown arguments: ${args_UNPARSED_ARGUMENTS}")
206216
endif()
217+
set_ifndef(args_TARGET "zephyr_interface")
207218

208219
if(args_AS_STRING)
209220
set(args_DELIMITER " ")
@@ -225,13 +236,17 @@ function(zephyr_get_build_property output)
225236
set(maybe_prefix "${prefix_${args_PROPERTY}}")
226237
endif()
227238

228-
get_property(flags TARGET zephyr_interface PROPERTY ${args_PROPERTY})
229-
if(args_LANG)
230-
process_flags(${args_LANG} flags output_list)
239+
if(args_GENEX)
240+
set(genexp_output_list "$<TARGET_PROPERTY:${args_TARGET},${args_PROPERTY}>")
231241
else()
232-
set(output_list "${flags}")
242+
get_property(flags TARGET ${args_TARGET} PROPERTY ${args_PROPERTY})
243+
if(args_LANG)
244+
process_flags(${args_LANG} flags output_list)
245+
else()
246+
set(output_list "${flags}")
247+
endif()
248+
string(REPLACE ";" "$<SEMICOLON>" genexp_output_list "${output_list}")
233249
endif()
234-
string(REPLACE ";" "$<SEMICOLON>" genexp_output_list "${output_list}")
235250

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

0 commit comments

Comments
 (0)