[cmake-developers] CMakeParseArguments: Do not skip empty arguments

Daniele E. Domenichelli daniele.domenichelli at gmail.com
Tue Nov 5 10:45:44 EST 2013


Hello all,

Current implementation of cmake_parse_arguments skips empty arguments.

For example:

  cmake_parse_arguments("OPTION" "SINGLE" "MULTI" ${ARGN})

with ARGN that is set using something like:

  <args> SINGLE "" <more args>  # (<args>;SINGLE;;<more args>)
  <args> SINGLE ""  # (<args>;SINGLE;)

it will fail in 3 different ways:

1) because the "foreach" skips empty arguments
2) because list(APPEND <list> ${currentArg}) will fail to append an
   empty element to the list if currentArg is an empty string.
3) because empty arguments are not passed to cmake_parse_arguments
   if not quoted, i.e. if ARGN="a;;b"
   * ${ARGN} will pass the arguments "a", "b"
   * "${ARGN}" will pass the arguments "a", "", "b"

I wrote a small patch to fix this, you can find it in the
CMakeParseArguments_EmptyArgs topic. This patch fixes the first
behaviour using foreach(IN LISTS) version, the second by enclosing
currentArg in quotes where required, and finally fixes the documentation
in order to suggest to use quoted  "${ARGN}" in order not to miss the
empty arguments at the end of the list.

I don't know if this is to be considered a change of behaviour though,
but I'd rather consider it a bug, and I would like to see it fixed in
the next bugfix release... what do you think?


Cheers,
 Daniele



More information about the cmake-developers mailing list