[CMake] Scope of a macro

Michael Wild themiwi at gmail.com
Wed Mar 4 02:43:09 EST 2009


On 4. Mar, 2009, at 7:11, Robert Dailey wrote:

> On Wed, Mar 4, 2009 at 12:02 AM, Michael Wild <themiwi at gmail.com>  
> wrote:
>
>> If you add a subdirectory, it inherits all variables and macros  
>> from the
>> parent directories. This is actually what one expects, otherwise  
>> you would
>> have to repeat the whole system detection (find_pacakge,  
>> find_library,
>> find_path etc.) in every subdirectory. The reverse, however is not  
>> true. By
>> default, variables (I'm not sure about macros) don't propagate into  
>> the
>> parent scope, unless one uses the PARENT_SCOPE option or adds the  
>> variable
>> to the cache which makes it global.
>
>
> That makes perfect sense and works as I would expect. However, I'm  
> seeing
> the behavior you state should not happen. That is, the macros  
> defined in the
> child directory are somehow propagating up to the parent.

Sorry, must have missed the bar/baz difference... Well, I figure it  
also makes some sense that macros and functions are global. Otherwise  
one would have very confusing things going on, like a macro by the  
same name doing completely unrelated things in different directories.

Michael


More information about the CMake mailing list