[CMake] lexical scoping
David Cole
david.cole at kitware.com
Sat Nov 3 10:42:47 EDT 2007
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)
function(fname same args as macro)
endfunction(fname)
- local/endlocal pairs should be nestable
- any SET within the local scope would made only in the local scope unless
the "CACHE" arg is used
- perhaps a "PARENT_SCOPE" keyword could be used with SET to set something
back out in the containing scope
- function would be identical to macro except it would have an implied
"local"/"endlocal" with the scope_name the same as the function name
- it would be nice for functions to have an easy to use return value
On 11/3/07, Miguel A. Figueroa-Villanueva <miguelf at ieee.org> wrote:
>
> On 11/3/07, Alexander Neundorf wrote:
> > On Friday 02 November 2007, KSpam wrote:
> > > Brandon,
> > >
> > > You missed the part where Bill mentioned that variable_scope would
> take
> > >
> > > multiple arguments. Your example:
> > > > variable_scope_begin(scratch_preamble)
> > > > variable_scope_begin(got_match)
> > > > variable_scope_begin(not_trail)
> > > > variable_scope_begin(empty)
> > > > # [...]
> > > > # my actual code, blah blah blah
> > > > # [...]
> > > > variable_scope_end(scratch_preamble)
> > > > variable_scope_end(got_match)
> > > > variable_scope_end(not_trail)
> > > > variable_scope_end(empty)
> > >
> > > would reduce to:
> > >
> > > variable_scope_begin(scratch_preamble got_match not_trail empty)
> > > # [...]
> > > # my actual code, blah blah blah
> > > # [...]
> > > variable_scope_end(scratch_preamble got_match not_trail empty)
> >
> > How about naming it "declare_local_vars(<vars>)" or just "local(<vars>)"
> > instead of variable_scope_begin() and have it end always at endmacro() ?
>
> I like both alternative names better, but can't rely on endmacro() for
> ending since this causes an unnecessary limitation. That is, you'd
> want to use this in FindXXX.cmake modules and other scripts not only
> macros.
>
> --Miguel
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071103/96f456a3/attachment-0001.html
More information about the CMake
mailing list