On 3. Jun, 2010, at 17:19 , Doug Reiland wrote:

> Is there a way to an updated variable from parent scope?
> 
> For example,
> I am in a sub-directory
> 
> set(FOO 2 PARENT_SCOPE)
> 
> ...
> 
> <still in sub-directory>
> retrieve FOO from PARENT_SCOPE
> 
> I know sub-directory would get a copy of FOO, if it existed, when it
> was entered.

You have to set the variable in both scopes... Inconvenient, I know. I usually 
do:

set(FOO 2)
set(FOO "${FOO}" PARENT_SCOPE)

> 
> I played with set/get_property() for this, but which worked ok until I
> wanted to store a list
> 
> set(FOO a b c PARENT_SCOPE)
> set_property(GLOBAL APPEND PROPERTY FOO-LIST FOO)
> get_property(my-foo-list GLOBAL PROPERTY FOO-LIST)
> foreach (e ${my-foo-list})
>        message("TEST ${${e}}")
>        message(TEST2="${e}")
> endforeach()
> 
> This outputs:
> TEST
> TEST2="FOO"

That's because you are setting the variable in the parent scope, so it is not 
available in your local scope when setting the global FOO-LIST property, and as 
you write it now, you set it to the string FOO, not to that variable's content. 
Use

set(FOO a b c)
set_property(GLOBAL APPEND PROPERTY FOO-LIST "${FOO}")

instead. What is important: properties are completely unrelated to variables. 
There is zero overlap.

Michael
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to