Feature request: Provide versions of ARGV and ARGN that escape semicolons in arguments
The CMake variables ARGV
and ARGN
split arguments that are themselves lists into multiple individual arguments. This differs from the behaviour of ARGC
and ARGV#
, which retain list arguments individually. This makes using these variable in commands like list()
or foreach(IN LISTS)
error prone. The same goes for forwarding arguments to functions like cmake_parse_arguments()
.
The following script demonstrated this difference:
function(test)
message("arguments as exposed by ARGC and ARGV#:")
math(EXPR last "${ARGC} - 1")
foreach(n RANGE 0 ${last})
message("> ${ARGV${n}}")
endforeach()
message("arguments as exposed by ARGV:")
foreach(arg IN LISTS ARGV)
message("> ${arg}")
endforeach()
endfunction()
test("ABC" "X;Y;Z" "123")
The output is:
arguments as exposed by ARGC and ARGV#:
> ABC
> X;Y;Z
> 123
arguments as exposed by ARGV:
> ABC
> X
> Y
> Z
> 123
This problem is especially severe in macros, where the PARSE_ARGV
variant of cmake_parse_arguments()
is not available. To make matters worse, ARGV#
are not true variables in macros, and therefore cannot be accessed using ${ARGV${n}}
. This makes the strategy used in the first loop in the script above impossible in macros. As far as I can tell, there is no way to access the individual arguments reliably from within a macro, unless their number is fixed.
IMHO, either the behaviour of ARGV
and ARGN
should be corrected (possibly via a Policy) to escape semicolons in the individual arguments, or a second set of variables should be exposed that contain the arguments correctly escaped.