cmake-macro-vs-function
cmake中,macro
类似于C中的宏函数,会进行参数替换,而function
类似于C中的函数,
参数是一个变量,可以进行赋值等操作。
示例:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19set(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})
输出:1
2
3
4
5
6
7
8=== Call macro ===
arg = ABC
# After change the value of arg.
arg = ABC
=== Call function ===
arg = ABC
# After change the value of arg.
arg = abc