[CMake] lexical scoping

Alexander Neundorf a.neundorf-work at gmx.net
Sun Nov 4 05:10:02 EST 2007


On Saturday 03 November 2007, Bill Hoffman wrote:
> David Cole wrote:
> > After all the discussion / suggestions that have been part of this
> > thread, I like the following best:
> >
> > local(scope_name)
> >   set(var1 "value1")
> >   set(var2 "value2")
> > endlocal(scope_name)
>
> I would prefer to declare the variables that are part of the scope.  I
> think you would want to reference and set global variables from within a
> scope.  The PARENT_SCOPE maybe needed as well.
>
> local(scope_name var1 var2 ... varN)
>
> endlocal(scope_name)

I like that. 
Three questions: 
-why is a scopename required ?
-will local variables be "inherited" to called macros ?
-will they be "inherited" to included cmake files ?

I.e. how will this behave:

set(foo "foo")

macro(m1)
  set(foo "bar")
endmacro(m1)

macro(m2)
  local(myscope foo)
  set(foo "localfoo") # global foo unchanged
  m1()              # will m1 change the global foo or the local one from m1 ?
endmacro(m2)


Alex


More information about the CMake mailing list