Skip to content

Commit fe70e0b

Browse files
committed
Refactor requires_arguments() macro
Wanted to make the "prefix" parameter optional. Sadly this is not as easy as I hoped for, when dealing with a macro. For now, this will have to do.
1 parent 0ddb655 commit fe70e0b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cmake/rsp/helpers.cmake

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,26 @@ if (NOT COMMAND "requires_arguments")
5858
# @see https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html#cmake-parse-arguments
5959
# @see https://cmake.org/cmake/help/latest/command/if.html#defined
6060
#
61-
# @param <variable|string> input The parsed arguments prefix
62-
# @param <list> required List of required arguments
61+
# @param <list> required List of required arguments
62+
# @param <variable|string> prefix The parsed input arguments prefix
63+
# used in your cmake_parse_arguments() call.
6364
#
6465
# @throws If required arguments are not defined
6566
#
66-
macro(requires_arguments input required)
67+
macro(requires_arguments required prefix)
68+
# Note: the "prefix" parameter cannot be made optional for this macro.
69+
# It is unsafe to rely on any ${ARGV} in this context, ...
70+
# @see https://cmake.org/cmake/help/latest/command/macro.html#argument-caveats
71+
72+
# Append "_" to the prefix, if given.
73+
# @see https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html#cmake-parse-arguments
74+
set(resolved_prefix "${prefix}")
75+
if(NOT ${prefix} EQUAL "")
76+
set(resolved_prefix "${prefix}_")
77+
endif ()
78+
6779
foreach (arg ${required})
68-
if (NOT DEFINED "${input}_${arg}")
80+
if (NOT DEFINED "${resolved_prefix}${arg}")
6981
message(FATAL_ERROR "${arg} argument is missing, for ${CMAKE_CURRENT_FUNCTION}()")
7082
endif ()
7183
endforeach ()

0 commit comments

Comments
 (0)