[CMake] INCLUDE_DIRECTORIES in sub-directories doesn't work?

Sean Soria sean.soria at gmail.com
Tue Nov 25 18:47:30 EST 2008


Okay, I tried it out just to make sure.  It includes the foo directory
for both main.c and foo/bar.c.  I only want it for foo/bar.c (and any
other file in foo/).

On Tue, Nov 25, 2008 at 3:10 PM, Sean Soria <sean.soria at gmail.com> wrote:
> That would add the included directories to every source in the
> project.  I want it included _only_ for the foo directory.
>
> On Tue, Nov 25, 2008 at 2:59 PM, THE HIGHHAT <thehighhat at gmail.com> wrote:
>> On Tue, Nov 25, 2008 at 3:43 PM, Sean Soria <sean.soria at gmail.com> wrote:
>>> No, this doesn't work either:
>>> CMakeLists.txt:
>>> ADD_SUBDIRECTORY(foo)
>>> ADD_EXECUTABLE(hello main.c foo/main.c)
>>>
>>> foo/CMakeLists.txt:
>>> SET_PROPERTY(SOURCE main.c PROPERTY INCLUDE_DIRECTORIES
>>> ${CMAKE_CURRENT_SOURCE_DIR})
>>>
>>> On Tue, Nov 25, 2008 at 2:26 PM, Sean Soria <sean.soria at gmail.com> wrote:
>>>> Include doesn't seem to do what I would expect either.  I want to add
>>>> include directories for any files found in foo.  it seems
>>>> include_directories doesn't do it because there must be a target in
>>>> that directory.  would setting the source property do it?
>>>>
>>>> On Tue, Nov 25, 2008 at 2:10 PM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
>>>>> Sean Soria wrote:
>>>>>>
>>>>>> I had them switched originally and just double checked.  This also doesn't
>>>>>> work:
>>>>>> CMakeLists.txt:
>>>>>> ADD_SUBDIRECTORY(foo)
>>>>>> ADD_EXECUTABLE(hello main.c foo/main.c)
>>>>>>
>>>>>> foo/CMakeLists.txt:
>>>>>> INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
>>>>>>
>>>>>
>>>>> The problem is the add_subdirectory.  Although the docs are not clear on
>>>>> this include_directories is essentially a directory property.  It sets the
>>>>> include directories for all targets in that directory.  You could use
>>>>> include instead.
>>>>>
>>>>> include(foo/includes.cmake)
>>>>>
>>>>>
>>>>> -Bill
>>>>>
>>>>>
>>>>
>>> _______________________________________________
>>> CMake mailing list
>>> CMake at cmake.org
>>> http://www.cmake.org/mailman/listinfo/cmake
>>>
>>
>> Use the cache to overcome scope issues....
>>
>>
>> CMakeLists.txt:
>>
>> add_subdirectory ( foo )
>> include_directories ( ${NESTED_DIRS} )
>> add_executable ( hello main.c )
>>
>>
>> foo/CMakeLists.txt:
>>
>> set ( NESTED_DIRS  ${CMAKE_CURRENT_SOURCE_DIR}  CACHE INTERNAL "DIRS" )
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>


More information about the CMake mailing list