On 06/28/2010 08:55 AM, Michael Wild wrote:
> 
> On 28. Jun, 2010, at 7:03 , Andreas Mohr wrote:
> 
>> Hello,
>>
>> On Sun, Jun 27, 2010 at 05:09:41PM -0400, cmake-requ...@cmake.org wrote:
>>> Your remarks focus on old-fashioned macros so it is possible you are not
>>> aware of functions? As far as I know, most or all macros can be replaced by
>>> functions which do have the nice property of not polluting the global
>>> namespace.  So newly developed build systems should use functions wherever
>>> possible, and certainly for old CMake-based build systems I am associated
>>> with I am trying to move to functions as time permits.
>>
>> That's all fine and dandy (and you've written some nice prose about
>> it :), but I've just been reading man cmakecommands of Debian cmake
>> 2.8.1-5(!) from top to bottom and bottom to top, and nowhere does it
>> mention _any_ underlying difference between macros and functions.

As for me, I wouldn't say so. The documentation of MACRO() states:

"Note that the parameters to a macro and values such as ARGN are not
variables in the usual CMake sense. They are string replacements much
like the c preprocessor would do with a macro. If you want true CMake
variables you should look at the function command."

So, one could conclude that there's indeed a difference between macros
and functions particularly in regard to variables, i.e. one of this
thread's concerns.

>> Not even I knew about this difference, despite having almost a month-full
>> of rather very internal CMake experience (Google searches in the couple
>> hundreds, vcproj2cmake adaptation of a _large_ project etc.).
>>
>> Suggestion for the sake of world peace: I'll submit a patch for that man
>> page, ok? :)
>>
>> Andreas Mohr
>>
> 
> You are right, the docs don't mention that FUNCTION introduces a new scope, 
> [...]

They do, but not for FUNCTION() where such facts would be expected;
it's rather hidden in the section of SET() w.r.t. PARENT_SCOPE:

"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)."

> [...] which should be fixed. [...]

Yes, mentioning the scoping capabilities of FUNCTION() right in the
latter's documentation, perhaps in connection with a reference to
SET()'s PARENT_SCOPE option, would be adequate and helpful, IMO.
Besides, ADD_SUBDIRECTORY()'s documentation doesn't note the
introduction of a new scope, too.

> [...] But it should be clear from the traditional use of the names. Macros 
> are textual replacements (just as in C), functions have their own local scope 
> (again, just as in C).   

Regards,

Michael
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
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

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to