[ENH] return() command: add capability to propagate variables to parent scope
Currently, the only possibility to propagate information to the parent scope is to use set(PARENT_SCOPE)
or unset(PARENT_SCOPE)
commands.
In many situations, it is painful because a large majority of commands work only with local variables. Moreover, with the introduction of command block()
, it becomes more complex to propagate information because the update must cross two scopes.
To solve this problem, I propose to extend the return()
command by supporting a list of variables which must be propagated to the result scope.
The proposed syntax, to be compatible with block()
command, is:
return([PROPAGATE <var-name>...])
With this capability, it is possible to write something like this:
function(MY_FUNC)
set(MY_VAR ...)
block()
string(TOUPPER "${MY_VAR}" MY_VAR)
if(MY_VAR STREQUAL ...)
return(PROPAGATE MY_VAR)
endif()
endblock()
string(APPEND MY_VAR ...)
return(PROPAGATE MY_VAR)
endfunction()
One open question: should this behavior of return()
supported in all cases or only in cases involving commands creating variable scope (i.e. function()
and add_subdirectory()
)?
I think a policy must be created for this new retun()
syntax because, currently, this command accepts any arguments and ignore them.