Documentation of how to use variables in macros is confusing, possible incorrect
Referring to https://cmake.org/cmake/help/v3.5/command/macro.html?highlight=macro, I see two problems:
PROBLEM 1:
Therefore you will NOT be able to use commands like:
if(ARGV1) # ARGV1 is not a variable
if(DEFINED ARGV2) # ARGV2 is not a variable
if(ARGC GREATER 2) # ARGC is not a variable
foreach(loop_var IN LISTS ARGN) # ARGN is not a variable
But then, in a subsequent example on the same macro documentation page, it uses foreach(arg IN LISTS ARGN)
that it just said above that "you will NOT be able to use" foreach(loop_var IN LISTS ARGN)
:
macro(_BAR)
foreach(arg IN LISTS ARGN)
[...]
endforeach()
endmacro()
PROBLEM 2: Also, in the following example, where are the "existing variables"? How would x, y, and z get mapped to "a", "b", and "c". Is there something missing from this example?
Note that if you have a variable with the same name in the scope from which the macro is called, using unreferenced names will use the existing variable instead of the arguments. For example:
macro(_BAR)
foreach(arg IN LISTS ARGN)
[...]
endforeach()
endmacro()
function(_FOO)
_bar(x y z)
endfunction()
_foo(a b c)
Will loop over a;b;c and not over x;y;z as one might be expecting. If you want true CMake variables and/or better CMake scope control you should look at the function command.