[CMake] Working around target needing many include directories

Israel Israeli embedded.team103 at gmail.com
Tue Apr 9 10:03:39 EDT 2019


We are using a library that adds all of it's subdirectories to the include
search path (hundreds of directories and thousands of files). This is done
because they change their folder structure constantly (but we don't care as
we are upgrading every once in a while and can adjust).
We don't want this for our usage as the file names are very generic and can
cause name clashes (`Queue.h` for example) with other third party libs.

We want to rewrite their build system (which is not cmake originally, but
that is a different story) so that this addition of include directories is
private.

Namely simple write:

target_include_directories(Lib PRIVATE ${LIB_SUBDIRECTORIES})

Here is the problem and question:
When building the lib like this, everything works great, but when our
project that depends on the library is built, there are preprocessor errors
- we include files from the library which in turn include other lib files
with non relative includes - and in our target build step the compiler does
not have the include directories needed to resolve the non relative include.
Example:

Lib
    dirA
      file_a.h
    dirB
     file_b.h

//file_a.h
#include "file_b.h"

//main.cpp
#include "Lib\dirA\file_a.h"

App
    main.cpp

//CMake builds `Lib` okay.
//CMake fails to build `App` due to non-relative include in `file_a.h`


Is there a way to have it both ways? Build the library with all include
paths, and in target depending on it - not add all of them?
Can precompiled headers do this?
Is there a pure cmake solution?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190409/990e25fb/attachment-0001.html>


More information about the CMake mailing list