[CMake] namespace support

Michael Wild themiwi at gmail.com
Thu Feb 3 04:06:05 EST 2011


On 02/03/2011 09:59 AM, Peter Kümmel wrote:
> On 03.02.2011 00:56, Michael Jackson wrote:
>>
>> On Feb 2, 2011, at 6:38 PM, Peter Kümmel wrote:
>>
>>> On 02.02.2011 16:39, Michael Jackson wrote:
>>>>
>>>> On Feb 2, 2011, at 10:21 AM, Peter Kümmel wrote:
>>>>
>>>>> On 02.02.2011 16:17, Michael Wild wrote:
>>>>>>> namespace(a)
>>>>>>>      include_directories(a)
>>>>>>>      add_library(a MODULE a/a.cpp)
>>>>>>> endnamespace()
>>>>>>>
>>>>>> Put a CMakeLists.txt file in a/ and b/ and do the
>>>>>> include_directories()
>>>>>
>>>>> Exactly this is what I don't wanna do and why I've asked ;)
>>>>>
>>>>> Seems it becomes a feature request.
>>>>>
>>>>> Peter
>>>>>
>>>>>> and add_library() calls in there. That's the only way to have
>>>>>> separate
>>>>>> include directories since there is no corresponding target property
>>>>>> (which admittedly would be nice to have).
>>>>>>
>>>>>> Michael
>>>>
>>>> Could you create some sort of function call for adding your simple
>>>> executables?
>>>>
>>>> function(ADD_MY_LIBRARY path name include_dirs)
>>>>    include_directories(${include_dirs})
>>>>    add_library(${name} MODULE ${path}
>>>> endfunction()
>>>>
>>>> I _think_ functions have their own scope. I could be wrong.
>>>
>>> Thanks, I will try it, until now I only used macros.
>>>
>>> Peter
>>>
>>
>> The subtle difference between a macro and a function is to think of a
>> macro as something like a C/C++ preprocessor #define statement. What
>> ever is in the macro will be substituted at the place in the code
>> where you called it. A function on the other hand really is like a "C"
>> function with its own scope. A "function" is really what you want in
>> this case.
>>
>> Mike J.
>>
> 
> I tried it with function and see no difference to the macro approach:
> each include path is in all projects.
> So function does not help.
> 
> Pete

Functions don't help, because include_directories() sets a the
INCLUDE_DIRECTORIES property of the current *directory*, so an
additional scope doesn't help. As nice as it would be to have a
corresponding target property, I really don't see the problem with
having these additional CMakeLists.txt files. They are very small; you
could even put all the code in a function and then just invoke that in
the CMakeLists.txt file, which would make them one-liners.


Michael


More information about the CMake mailing list