[CMake] lexical scoping
Miguel A. Figueroa-Villanueva
miguelf at ieee.org
Sat Nov 3 13:07:31 EDT 2007
On 11/3/07, Bill Hoffman wrote:
> Miguel A. Figueroa-Villanueva wrote:
> > On 11/3/07, 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)
> >
> > Maybe I'm missing the point, so bare with me...
I new I was missing something ;)
> > I like David's proposal, since it would be the closest to a regular
> > language except that instead of the typical curly braces you have the
> > local/endlocal keywords. Making a function that implicitly creates a
> > scope would avoid the cumbersome typing.
> >
> I guess I think the code would be much clearer if you had to declare a
> variable local. I think that the convention of any set in a local scope
> creating a new variable would be confusing and cause plenty of errors.
> Remember you can add scope anywhere even around existing stuff. So lets
> say you have something like this:
>
>
> local_scope()
> ....
> set(a "-flag")
> set(CMAKE_CXX_FLAGS ${a} )
> # this is not going to set the variable that everyone expects!
> # it will create a local variable that won't be used at all by the
> # generators.
> end_scope()
>
I guess I'd have to go back to support Bill's idea of having to
declare the variable:
local(scope_name var1 var2 ... varN)
endlocal(scope_name)
The only thing I can think of to make it more pleasant to type (but
functionally equivalent) is to have it integrate with the
function/scoped_macro and set commands. Since we now have scope, then
allow SET(... LOCAL) and have a function command as mentioned before,
which has an implicit scope declaration.
macro(macro_name ...)
local(scope_name var1 var2 ... varN)
<code>
endlocal(scope_name)
endmacro(macro_name)
function(macro_name ...)
set(var1 <value> LOCAL)
endfunction(macro_name)
--Miguel
More information about the CMake
mailing list