cmake: add check_arguments_... macro to facilitate function writing
Add a new zephyr_check_arguments_required_allow_empty() macro for function argument validation. Zephyr already has a zephyr_check_arguments_required() for checking required arguments, like zephyr_check_arguments_required(foo_func <prefix> FOO BAR) which ensures that one of FOO or BAR are given in a call like: foo_func(BAR val) One limitation however, is that is some cases BAR may be allowed to be empty, so that it's still possible to know if FOO or BAR were supplied. In most case, BAR and FOO will have values following the keyword, like: foo_func(BAR my_bar_val) foo_func(FOO my_foo_val) but in cases where `my_bar_val` is a variable which may be empty, like: set(my_bar_val) foo_func(BAR ${my_bar_val}) # (expands to: foo_func(BAR) then BAR was actually supplied. To support functions where such empty expansion is allowed, then a new helper macro `zephyr_check_arguments_required_allow_empty()` has been implemented, as to be able to distinguish `foo_func()` from `foo_func(BAR)` when parsing arguments. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
parent
2a6f151524
commit
9da2766846
1 changed files with 20 additions and 0 deletions
|
@ -5168,6 +5168,24 @@ macro(zephyr_check_arguments_required function prefix)
|
|||
set(check_defined)
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# Helper macro for verifying that at least one of the required arguments has
|
||||
# been provided by the caller. Arguments with empty values are allowed.
|
||||
#
|
||||
# A FATAL_ERROR will be raised if not one of the required arguments has been
|
||||
# passed by the caller.
|
||||
#
|
||||
# Usage:
|
||||
# zephyr_check_arguments_required_allow_empty(<function_name> <prefix> <arg1> [<arg2> ...])
|
||||
#
|
||||
macro(zephyr_check_arguments_required_allow_empty function prefix)
|
||||
set(check_defined DEFINED)
|
||||
set(allow_empty TRUE)
|
||||
zephyr_check_flags_required(${function} ${prefix} ${ARGN})
|
||||
set(allow_empty)
|
||||
set(check_defined)
|
||||
endmacro()
|
||||
|
||||
#
|
||||
# Helper macro for verifying that at least one of the required flags has
|
||||
# been provided by the caller.
|
||||
|
@ -5183,6 +5201,8 @@ macro(zephyr_check_flags_required function prefix)
|
|||
foreach(required ${ARGN})
|
||||
if(${check_defined} ${prefix}_${required})
|
||||
set(required_found TRUE)
|
||||
elseif("${allow_empty}" AND ${required} IN_LIST ${prefix}_KEYWORDS_MISSING_VALUES)
|
||||
set(required_found TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue