Setting CMake macro arguments within macro scope
cmake
Solution
Use a function instead:
function(test arg)
message("output: ${arg}")
set(arg "overwritten")
message("output: ${arg}")
endfunction(test)
From CMake docs on macro:
Note that the parameters to a macro and values such as ARGN are not variables in the usual CMake sense. They are string replacements much like the c preprocessor would do with a macro. If you want true CMake variables you should look at the function command.
Keep in mind though that unlike macros, functions introduce a new scope. So whenever you `set` a variable in a function, you have to give `PARENT_SCOPE` as a parameter to make the change visible to the caller.
Problem
Are the arguments of a cmake-macro read-only within and during the scope of the macro? Considers the following code: ``` macro(test arg) message("output: ${arg}") set(arg "overwritten") message("output: ${arg}") endmacro(test) test("original") ``` The output is ``` output: original output: original ``` Is there a way to change this behaviour?