[CMake] lexical scoping

Brandon Van Every bvanevery at gmail.com
Fri Nov 2 14:39:40 EDT 2007


On Nov 2, 2007 2:26 PM, Ken Martin <ken.martin at kitware.com> wrote:
>
> the macro command is like a cpp macro so scoping does not make a lot of
> sense for it. What would/could make sense is a function command that creates
> a function. (think of the difference in a macro versus a function in c,
> macros have no inherent scope they are just string replacements, functions
> do have scope built in). With a function command we could probably figure
> out some way to create variables that are scoped to the function only. Most
> of the places we are using macros really could/should be functions.

Yes please!  95% of MACROs I've written are really trying to be functions.

> My main
> question would be if we had a function, how would you want variables
> handled.
>
> 1) all set commands create "local" variables to the function (a mess for
> functions that do an include of other cmake code)
> 2) a special set command or signature that creates a local variable scoped
> to the current function

SET and SETLOCAL is one possibility.  I could live with it.
SET and SETGLOBAL is another possibility.  It would require breaking
backwards compatibility.

> 3) a mode to switch the behavior of set (yuck)

No.  For stability of developing a build system, that's completely ridiculous.


Cheers,
Brandon Van Every


More information about the CMake mailing list