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

Chris Johnson cxjohnson at gmail.com
Wed Dec 3 15:22:06 EST 2014


I think I've made it work by adding 1 ugly hack and 1 reasonable directive
to each library's CMakeLists.txt, which is at least far preferable to
adding several new include paths to potentially hundreds of programs which
refer to those libraries.

The hack is a function which is defined in my global CMake "include" file,
which when called simply (well, not so simply -- it's a hack!) creates a
subdirectory of the library's name in the BUILD directory and then copies
the *.h files from the SOURCE directory to it.

Then I add
    # Headers used from build location:
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
to my existing target_include_directories().

While this appears to work in early testing, I'd sure like a better
solution.  It's pretty much best practice to install one's private library
header files in a subdirectory of /usr/include, /usr/local/include, etc.
So having to jump through hoops to support that paradigm is kind of strange.

Thanks,
..chris


On Wed, Dec 3, 2014 at 10:56 AM, Bill Hoffman <bill.hoffman at kitware.com>
wrote:

> On 12/2/2014 5:19 PM, Chris Johnson wrote:
>
>> 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.
>>
> The include directories will be copied out of the library and chained
> along, but they need to be explicitly set somewhere.   Although you could
> get an install to happen in the middle of a build with custom commands and
> targets, I would not recommend it.   Just get the include paths correctly
> specified and things should work.
>
> --
> Bill Hoffman
> Kitware, Inc.
> 28 Corporate Drive
> Clifton Park, NY 12065
> bill.hoffman at kitware.com
> http://www.kitware.com
> 518 881-4905 (Direct)
> 518 371-3971 x105
> Fax (518) 371-4573
> --
>
> 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/20141203/b755d9ba/attachment.html>


More information about the CMake mailing list