[CMake] Functions inherit parent variables?
Michael Hertling
mhertling at online.de
Wed Feb 29 22:54:07 EST 2012
On 03/01/2012 01:38 AM, Robert Dailey wrote:
> I ran a quick test:
>
>
> function( test )
> message( "SOME_TEST: ${SOME_TEST}" )
> endfunction()
>
> function( start )
> set( SOME_TEST "HELLO WORLD" )
> test()
> endfunction()
>
> start()
>
>
> Seems like a function has access to the calling scope's defined variables.
> I thought because functions created a new scope, that excluded access to
> variables defined in the outer scope (i.e. calling scope)
>
> Can someone explain?
The line "SOME_TEST: HELLO WORLD" is missing, I guess?
As usual with scoping mechanisms, there is access to the outer scope
from within the inner scope: Read access via ordinary dereferencing
and write access via PARENT_SCOPE. It's quite the same as in C/C++
with the { and } tokens; see also the C++ "::" operator.
Regards,
Michael
More information about the CMake
mailing list