I would like to create a cmake macro which开发者_如何转开发 fills in a given variable with some values, for example:
macro ( fillList list )
set( list a b c )
endmacro()
fillList( list )
This doesn't seem to be possible with cmake. Any suggestions for achieving this in cmake?
Pass the name of the variable and use that:
macro(fillList list)
set(${list} a b c)
endmacro()
you can use PARENT_SCOPE
set(<variable> <value>... [PARENT_SCOPE])
If the PARENT_SCOPE option is given the variable will be set in the scope above the current scope. Each new directory or function creates a new scope. This command will set the value of a variable into the parent directory or calling function (whichever is applicable to the case at hand). The previous state of the variable's value stays the same in the current scope (e.g., if it was undefined before, it is still undefined and if it had a value, it is still that value).
精彩评论