function(MyFunction IN_OUT_NAME) ... what to do here ... string(APPEND ${IN_OUT_NAME} " and that") ... what to do here ... endfunction()
下面的代码片段
set(MY_MESSAGE "this") MyFunction(MY_MESSAGE) message(${MY_MESSAGE})
this and that
不重复备注:
Modify a variable inside a function 是关于JavaScript而不是CMake
Is JavaScript a pass-by-reference or pass-by-value language? 是关于JavaScript而不是CMake
只需使用父作用域将值导出到父作用域。
function(MyFunction IN_OUT_NAME) string(APPEND ${IN_OUT_NAME} " and that") set(${IN_OUT_NAME} "${${IN_OUT_NAME}}" PARENT_SCOPE) endfunction() set(MY_MESSAGE "this") MyFunction(MY_MESSAGE) message(${MY_MESSAGE})