MantisBT - CMake
View Issue Details
0015093CMakeCMakepublic2014-08-18 02:052016-06-10 14:31
abma 
Kitware Robot 
normalmajoralways
closedmoved 
CMake 2.8.12.2 
 
0015093: PARENT_SCOPE empties variables when recursived used
when a PARENT_SCOPE'd variable is set to a value of a PARENT_SCOPE'd variable, both are empty:

set(a "a" PARENT_SCOPE)
set(b "${a}" PARENT_SCOPE)


expected result:

a = "a"
b = "a"

but in real both are empty!
can be workarounded:

macro(MakeGlobalVar varname)
    set(${varname} ${ARGN} PARENT_SCOPE)
    set(${varname} ${ARGN})
endmacro()


MakeGlobalVar(a "a")
MakeGlobalVar(b "${a}")

No tags attached.
Issue History
2014-08-18 02:05abmaNew Issue
2014-08-18 04:17Marcel LooseNote Added: 0036627
2014-08-18 05:16abmaNote Added: 0036628
2014-08-18 09:35Ben BoeckelNote Added: 0036629
2016-06-10 14:29Kitware RobotNote Added: 0042609
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0036627)
Marcel Loose   
2014-08-18 04:17   
This is not a bug. You set variable a in the parent scope only! So, it is not set at the current scope. Hence, you assign an empty string to variable b, also in the parent scope. No surprise to me they're both empty.

Your workaround just sets the variable twice, once at the current scope and once at the parent scope.
(0036628)
abma   
2014-08-18 05:16   
from docs: "If PARENT_SCOPE is present, the variable will be set in the scope above the current scope."

i understand this, as when a variable is set "above" the current scope it will be present in current scope, too.

imo it should be noted in docs that its not valid in current scope then.
(0036629)
Ben Boeckel   
2014-08-18 09:35   
The previous value is "pulled" down into the current scope, including its state if it was previously undefined.
(0042609)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.