cmake_language(EVAL CODE) called inside a macro doesn't see the macro's ARG* variables
I can't decide if this should be considered a bug or not, but it was something that was at least unexpected upon first encountering it. The following example best demonstrates the issue:
macro(mac)
message("Direct:")
message("ARGC = ${ARGC}")
message("ARGV0 = ${ARGV0}")
message("ARGV1 = ${ARGV1}")
message("\nIndirect:")
cmake_language(EVAL CODE [=[
message("ARGC = ${ARGC}")
message("ARGV0 = ${ARGV0}")
message("ARGV1 = ${ARGV1}")
]=])
endmacro()
mac(one two)
Running this with cmake -P
gives the following output:
Direct:
ARGC = 2
ARGV0 = one
ARGV1 = two
Indirect:
ARGC =
ARGV0 =
ARGV1 =
If we change the macro to a function instead, then the Indirect:
case shows the same output as the Direct:
case. This seems like it should work for macros too, but I'm guessing that the way macros paste in their ARG*
variables rather than evaluating them like a function does is the underlying reason for the difference.
Either this is a bug and we should fix it, or we should document it as a limitation for the cmake_language(EVAL CODE)
command and also mention it in the docs for the macro()
command. At the moment, I'm leaning towards it being a bug, but maybe it's a limitation of the way macros are currently implemented.