[cmake-developers] Review request: set_emptyvar_PARENT_SCOPE

Daniele E. Domenichelli daniele.domenichelli at gmail.com
Mon Nov 11 17:33:59 EST 2013


On 11/11/13 17:52, Matthew Woehlke wrote:
> On 2013-11-11 05:13, Daniele E. Domenichelli wrote:
> WCTS, how does one now unset a variable in parent scope?
> 
> I recall some time back there was talk of adding PARENT_SCOPE to 
> unset(). If set() can no longer be used for this purpose, maybe unset() 
> should gain a PARENT_SCOPE option first / at the same time?

According to

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=261c2482

it seems that unset() already supports that...

Anyway, AFAIK you should always have been able to use
set(var PARENT_SCOPE) to unset a variable on the parent scope. But
actually I noticed that my patch broke it, so I just pushed a patch to
restore this behaviour, and added some unit tests to check it.


So, to summarize:

 set(VAR PARENT_SCOPE)
 unset(VAR PARENT_SCOPE)

will unset the variable in the parent scope

 set(VAR "" PARENT_SCOPE)

will instead set an empty variable in the parent scope.


This also means that one can use

 set(VAR ${VAR} PARENT_SCOPE)

to set VAR in the parent scope if the variable in the current scope is
defined and is not empty, otherwise to unset it, or

 set(VAR "${VAR}" PARENT_SCOPE)

to always set a variable VAR in the parent scope, using the value of the
variable in current scope, if it is defined, or an empty string if VAR
is not defined in current scope. This is actually the same exact
behaviour of set(VAR ${FOO}) and set(VAR "${FOO}") for the current scope


Does this seem good enough?


Cheers,
 Daniele



More information about the cmake-developers mailing list