[CMake] lexical scoping

KSpam keesling_spam at cox.net
Fri Nov 2 18:59:10 EDT 2007


Brandon,

> > Of course, if we could get braces into the mix, it would reduce to:
> >
> >         variable_scope(scratch_preamble got_match not_trail empty)
> >         {
> >                 # [...]
> >                 # my actual code, blah blah blah
> >                 # [...]
> >         }
>
> Why is this better than implementing functions?

I never claimed that it would be better than implementing functions.  For that 
matter, I do not think they would be mutually exclusive.  If changes are 
going to be made, it would benefit us all to consider many alternatives.  
There are pros/cons to each approach.

The nice thing about variable_scope is that it gives you more flexibility for 
the variable within a file, macro, or function.  It allows you to layer 
scopes on top of each other.  You get a nice "stack" of values for a 
particular variable name depending on scope.  This can be a very powerful 
construct, and it allows for recursion.  Furthermore, variable_scope and 
functions are orthogonal features.  I would personally like the synergy that 
comes from having both constructs at my disposal.

On the other hand "SETLOCAL" might be a bit easier for a novice to use.

> > I will trade typing a few more characters for variable safety any day.
>
> You can do that now with verbose variable prefixes.

Ah ... you can do ANYTHING if you are willing to sweat hard enough.  You could 
generate your CMake environment from Python (done that) ... you could write 
macros upon macros (done that) ... you could even create custom CMake plugins 
(done that) ...

The bottom line is not what is possible, but rather how can we make this build 
system easier to use, more flexible, and more powerful without users having 
to resort to hacks.  Verbose variable prefixes is a hack (one that I 
unfortunately use quite often).

Justin


More information about the CMake mailing list