I wrote an example code below:
set(var "ABC") macro(Moo arg) message("arg = ${arg}") set(arg "abc") message("# After change the value of arg.") message("arg = ${arg}") endmacro() message("=== Call macro ===") Moo(${var}) function(Foo arg) message("arg = ${arg}") set(arg "abc") message("# After change the value of arg.") message("arg = ${arg}") endfunction() message("=== Call function ===") Foo(${var})
and conclusion:
=== Call macro === arg = ABC
Thus, it seems that arg assigned the value of var when calling Foo and ${arg} simply replaced by a string with ${var} when calling Moo .
Therefore, I think that the two quotes above are very easy to confuse, although official documents also say that:
They are string replacements in much the same way that a C preprocessor would do with a macro. If you want true CMake variables and / or better control of the CMake scope, you should take a look at the function command.
Yantao Xie Jun 19 '14 at 2:48 a.m. 2014-06-19 02:48
source share