Working around target needing many include directories

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Working around target needing many include directories

Israel Israeli
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.


#include "file_b.h"

#include "Lib\dirA\file_a.h"


//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?


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: