From 546a32897839f015440ea0cc6c8f5b486359d26f Mon Sep 17 00:00:00 2001 From: Sylvain Joubert Date: Fri, 20 Oct 2017 09:05:13 +0200 Subject: Help: Fix cmake_parse_arguments behavior for not found arguments Value keywords are actually UNDEFINED rather than set to the empty string when they are not found in the argument list. --- Help/command/cmake_parse_arguments.rst | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Help/command/cmake_parse_arguments.rst b/Help/command/cmake_parse_arguments.rst index ec4ffed..b334a89 100644 --- a/Help/command/cmake_parse_arguments.rst +++ b/Help/command/cmake_parse_arguments.rst @@ -43,15 +43,18 @@ macro which can be followed by more than one value, like e.g. the ````. A warning will be emitted if uniqueness is violated. -When done, ``cmake_parse_arguments`` will have defined for each of the +When done, ``cmake_parse_arguments`` will consider for each of the keywords listed in ````, ```` and ```` a variable composed of the given ```` followed by ``"_"`` and the name of the respective keyword. These -variables will then hold the respective value from the argument list. -For the ```` keywords this will be ``TRUE`` or ``FALSE``. +variables will then hold the respective value from the argument list +or be undefined if the associated option could not be found. +For the ```` keywords, these will always be defined, +to ``TRUE`` or ``FALSE``, whether the option is in the argument list or not. All remaining arguments are collected in a variable -``_UNPARSED_ARGUMENTS``, this can be checked afterwards to see +``_UNPARSED_ARGUMENTS`` that will be undefined if all argument +where recognized. This can be checked afterwards to see whether your macro was called with unrecognized parameters. As an example here a ``my_install()`` macro, which takes similar arguments @@ -74,16 +77,16 @@ Assume ``my_install()`` has been called like this: my_install(TARGETS foo bar DESTINATION bin OPTIONAL blub) -After the ``cmake_parse_arguments`` call the macro will have set the -following variables:: +After the ``cmake_parse_arguments`` call the macro will have set or undefined +the following variables:: MY_INSTALL_OPTIONAL = TRUE - MY_INSTALL_FAST = FALSE (was not used in call to my_install) + MY_INSTALL_FAST = FALSE # was not used in call to my_install MY_INSTALL_DESTINATION = "bin" - MY_INSTALL_RENAME = "" (was not used) + MY_INSTALL_RENAME # was not used MY_INSTALL_TARGETS = "foo;bar" - MY_INSTALL_CONFIGURATIONS = "" (was not used) - MY_INSTALL_UNPARSED_ARGUMENTS = "blub" (nothing expected after "OPTIONAL") + MY_INSTALL_CONFIGURATIONS # was not used + MY_INSTALL_UNPARSED_ARGUMENTS = "blub" # nothing expected after "OPTIONAL" You can then continue and process these variables. -- cgit v0.12