`cmake_parse_arguments` does not recognize missing value to "one_value_keywords"
If a function used cmake_parse_arguments()
to parse optional arguments with one value and that option is given as last parameters to a function without the required value, cmake_parse_arguments()
does not issue an error, nor return any UNPARSED_ARGUMENTS
.
Example:
function(foo)
message("in foo: ${ARGN}")
cmake_parse_arguments("" "" "ONE" "" ${ARGN})
if (DEFINED _UNPARSED_ARGUMENTS)
message("UNPARSED_ARGUMENTS: ${_UNPARSED_ARGUMENTS}")
endif()
if (DEFINED _ONE)
message("ONE: ${_ONE}")
endif()
endfunction()
foo(ONE 1)
foo(ONE 1 1)
foo(ONE)
The output is:
$ cmake -P fishy.cmake
in foo: ONE;1
ONE: 1
in foo: ONE;1;1
UNPARSED_ARGUMENTS: 1
ONE: 1
in foo: ONE
This applies to version 3.13.1. I would expect cmake_parse_arguments()
to either issue an error, or to return UNPARSED_ARGUMENTS
. (preferable to issue an error)
A workaround would be to add an additional parameter to cmake_parse_arguments()
and to check for UNPARSED_ARGUMENTS
:
cmake_parse_arguments("" "" "ONE" "" ${ARGN} UNUSED)
if (NOT DEFINED _UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Missing Parameter to one of the one-value-options.")
endif()