[CMake] getting "new/updated" variable from PARENT SCOPE
Michael Wild
themiwi at gmail.com
Fri Jun 4 01:42:54 EDT 2010
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
More information about the CMake
mailing list