[CMake] lexical scoping ... back to the future !

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Wed Feb 22 20:00:50 EST 2012


Hi François,

Would the use of function be helpful ?

See http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:function
and http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:set

"If PARENT_SCOPE is present, the variable will be set in the scope above
the current scope. Each new directory or function creates a new scope. This
command will set the value of a variable into the parent directory or
calling function (whichever is applicable to the case at hand)."

I created a small example showing that variable set within a function don't
interfere with the parent scope if not explicitly required.

git clone git://gist.github.com/1888836.git
cmake -P 1888836/cmake-illustrate-function-scope.cmake

Hth
Jc

On Wed, Feb 22, 2012 at 7:07 PM, François Mauger <mauger at lpccaen.in2p3.fr>wrote:

> Hi CMakers,
>
> In november 2007, there was a long thread titled "lexical scoping".
> The discussion was really interesting and was suggesting that some
> "local scoping" features for variables could be implemented in CMake...
> particularly from macros, which are probably the practical case that
> causes most issues when users implement several nested levels of macro
> invocations with many intermediate temporary variables that unfortunately
> aggregate in the global scope. It is really easy to face such problem in a
> rather large project driven with Cmake (a dependency driver invoking the
> find_package command in a foreach loop must be done from a macro AFAIK).
> Unless I missed something in the jungle of CMake threads and doc, I'm
> afraid I was not able to find some satisfactory solution other than hacks
> (using very long variable names to "emulate" some pseudo local scopes).
> this is tedious and bug prone.
>
> Browsing the last 4 years of archives and some additionnal docs, I was not
> able to find a single trace of such new feature : implementing "local
> scoping" in CMake (whatever "local scoping" could rationally mean).
>
> What is the current situation on users' side ? Is there any pressure for
> "local scoping" ? Maybe too few people ask for it so CMake developpers do
> not consider it as a priority... or no clear definition
> of "local scoping" has been patterned ?
> more what is the view of the CMake devel team ? do they consider this idea
> as a good one or not ?
>
> Thanks a lot for hints and advices.
>
> Best regards
> frc
> --
> François Mauger
> LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN
> Département de Physique -- Université de Caen Basse-Normandie
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/**
> opensource/opensource.html<http://www.kitware.com/opensource/opensource.html>
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/**CMake_FAQ<http://www.cmake.org/Wiki/CMake_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/**listinfo/cmake<http://www.cmake.org/mailman/listinfo/cmake>
>



-- 
+1 919 869 8849
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120222/2bbe473b/attachment-0001.htm>


More information about the CMake mailing list