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

Chris Johnson cxjohnson at gmail.com
Tue Dec 2 17:19:06 EST 2014


The target_link_libraries() directive is adequate for this job when the
header files for the library are simply referred to with no directory
prefix, i.e. #include "some file.h" instead of #include "my
lib/somefile.h".  Referencing the library with target_link_libraries()
appears to automatically add the necessary source directories of the
mentioned libraries to the include paths.



On Tue, Dec 2, 2014 at 4:00 PM, Chris Johnson <cxjohnson at gmail.com> wrote:

> Yes, by adding another directory between my top-level ./src/ directory and
> ./mylib, I can cause the example to fail.  I understand now that the
> include_directory() directive really has no hidden intelligence to it at
> all, as I had mistakenly believed.  It's just a path.
>
> However, I don't really want to have to go around to all my executables
> and add a bunch of relative paths based on which libraries they use, and
> where they are located in the tree.
>
> Is there some way that I can instead do something like force the install
> of the libraries to happen before the build of the programs which depend
> upon them?
>
> On Tue, Dec 2, 2014 at 3:53 PM, Chris Johnson <cxjohnson at gmail.com> wrote:
>
>> Well, this fixed my example.  But my real project still fails the same
>> way.  It is, of course, much more complex and the library directories are
>> often several layers down in subdirectory trees.  :-(
>>
>> On Tue, Dec 2, 2014 at 2:05 PM, Chris Johnson <cxjohnson at gmail.com>
>> wrote:
>>
>>> I'm using Make as my build tool.  Here's the failing compile line with
>>> the -I paths.  Indeed, they're not quite correct.  This is with the
>>> suggested include_directories() directive.
>>>
>>> [100%] Building CXX object prog/CMakeFiles/prog.dir/prog.cpp.o
>>> cd /sandbox/src/.build/prog && /usr/bin/c++    -I/sandbox/include
>>> -I/sandbox/src/src -I/sandbox/src/mylib    -o
>>> CMakeFiles/prog.dir/prog.cpp.o -c /sandbox/src/prog/prog.cpp
>>>
>>> Since the ../src/src path is wrong, I tried changing to
>>> include_directories(${CMAKE_SOURCE_DIR}) and that seems to work.  That
>>> seems to imply the top-level source is not part of the default include
>>> path, correct?
>>>
>>> Thanks,
>>> ..chris
>>>
>>>
>>> On Tue, Dec 2, 2014 at 1:10 PM, Bill Hoffman <bill.hoffman at kitware.com>
>>> wrote:
>>>
>>>> On 12/2/2014 1:04 PM, Chris Johnson wrote:
>>>>
>>>>> Adding this directive does not seem to change the results at all,
>>>>> actually.  Am I missing something?​
>>>>>
>>>>>
>>>> What build tool are you using?  Can you show a verbose compile line?
>>>> Then check the -I paths.  make VERBOSE=1 will do it for make.
>>>>
>>>> -Bill
>>>>
>>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141202/c9a20060/attachment.html>


More information about the CMake mailing list