Skip to content

Commit 350eecf

Browse files
committed
Add requires_arguments() util
1 parent 3116175 commit 350eecf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmake/rsp/helpers.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ if (NOT COMMAND "extract_value")
4848
endfunction()
4949
endif ()
5050

51+
if (NOT COMMAND "requires_arguments")
52+
53+
#! requires_arguments : Verifies that specified arguments have been defined, fails otherwise
54+
#
55+
# Macro is intended to be used within a custom function, after `cmake_parse_arguments()` has
56+
# been used.
57+
#
58+
# @see https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html#cmake-parse-arguments
59+
# @see https://cmake.org/cmake/help/latest/command/if.html#defined
60+
#
61+
# @param <variable|string> input The parsed arguments prefix
62+
# @param <list> required List of required arguments
63+
#
64+
# @throws If required arguments are not defined
65+
#
66+
macro(requires_arguments input required)
67+
foreach (arg ${required})
68+
if (NOT DEFINED "${input}_${arg}")
69+
message(FATAL_ERROR "${arg} argument is missing, for ${CMAKE_CURRENT_FUNCTION}()")
70+
endif ()
71+
endforeach ()
72+
endmacro()
73+
endif ()
74+
5175
if (NOT COMMAND "safeguard_properties")
5276

5377
#! safeguard_properties : Invoke a "risky" callback whilst "safeguarding" properties

0 commit comments

Comments
 (0)