[CMake] lexical scoping

Hendrik Sattler post at hendrik-sattler.de
Sun Nov 4 15:35:39 EST 2007


Am Sonntag 04 November 2007 schrieb Alexander Neundorf:
> On Sunday 04 November 2007, Philip Lowman wrote:
> > Brandon Van Every wrote:
> > > And strongly consider SETLOCAL, SET_LOCAL, SET_CACHE or whatever.
> >
> > Absolutely.  Here's what I would recommend...
> >
> > SET() should always set a global variable to maintain complete backwards
> > compatibility.  SETCACHE() could be added to keep things consistent as
> > Brandon suggests.  Trying to make SET be able to set everything is just
> > going to over complicate the command... it's already complicated enough
> > as it is.  What really needs to happen is to break it into three
> > commands: one for globals, one for locals, and one for cache.
> >
> > SETLOCAL() would be used to define local variables that are local to a
> > scoped region.  Scoped regions would include:
>
> What about functions like STRING() or FILE(READ) which can return values in
> variables ?

And what about the ability to escape a scope? It doesn't make much sense if 
the only way is to use the global scope for that.
I'd prefer being able to differ between variable declaration and assigning a 
value to a variable.
I'd suggest to keep the current SET syntax unless a variable was declared for 
a specific scope _before_ a SET command, e.g. with
IF(foo)
declare_local(bar)
set(bar "a message")
ENDIF(foo)

The other syntax can stay the same this way (the CACHE keyword should be 
ignored for such cases) and you can easily access the parent scope unless you 
use the same variable name (which is just the same in other programming 
languages).

HS


More information about the CMake mailing list