[CMake] How to set path to library header files?

Angeliki Chrysochou angeliki.chrysochou at gmail.com
Tue Dec 2 14:53:34 EST 2014


Hi Bill..

Apparently, from his first email his top directory is src:

Here are the current CMakeLists.txt files.

Top level (../src):
cmake_minimum_required(VERSION 2.8.4)
project(src)
project(src)
add_subdirectory(mylib)
add_subdirectory(prog)

So this would probably work:

include_directories(${CMAKE_SOURCE_DIR}/mylib)

If he prefers to include it via mylib/myfunc.h then this should work (given
his top level CMakeLists.txt is indeed in src/):

include_directories(${CMAKE_SOURCE_DIR})

The file structure:
.
|-- bin/
|-- include/
|   `-- mylib/
|-- lib/
`-- src/
    |-- CMakeLists.txt
    |-- mylib/
    |   |-- CMakeLists.txt
    |   |-- myfunc.cpp
    |   `-- myfunc.h
    `-- prog/
        |-- CMakeLists.txt
        `-- prog.cpp

Cheers!

On Tue, Dec 2, 2014 at 8:09 PM, Bill Hoffman <bill.hoffman at kitware.com>
wrote:

> On 12/2/2014 1:33 PM, Angeliki Chrysochou wrote:
>
>>
>> you should add in ./src/prog/CMakeLists.txt in include_directories the
>> correct path to myfunc.h. Assuming CMAKE_SOURCE_DIR is "." (this is
>> where your top level CMakeLists.txt is located):
>>
>> include_directories(${CMAKE_SOURCE_DIR}/src/mylib)
>>
> I don't think that will work.  Two reasons:
>
> CMAKE_SOURCE_DIR is the top level source directory for the project, not
> the current one.  Also, he wants to include the file like this:
>
> #include "mylib/myfunc.h"
>
> So, the include needs to go to src  and not src/mylib.
>
> -Bill
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141202/95adcdd9/attachment.html>


More information about the CMake mailing list