How to have individual include directories for each subdirectory?

17 Views Asked by At

I have the following directory structure:

Root
| - CMakeLists.txt
| - a
| - | - a1.c
| - | - a2.c
| - | - include
| - | - | - a1.h
| - | - | - a2.h
| - b
| - | - b.c
| - | - include
| - | - | - b.h
| - include
| - | - <symlink to a/include>
| - | - <symlink to b/include>
| - | - gen.h
| - main
| - | - main.c

I'd like for each c file to be able to access the include directory in the root and the include directory in each of their sub-folders. So a1.c & a2.c can #include <a1.h> & #include <a2.h> directly, but any other file outside of the a sub-directory (like b.c or main.c) needs to use a more complete path #include <a/a1.h>

Note that a2.c & b.c are dependent on each-other (meaning that a2.c uses code defined in b.c & vice-versa), so using libraries is not an option (given that a2.c won't be able to be compiled unless linked against b.o & vice-versa).

At the moment, I have a target defined for main.elf which uses code from both a & b, but using target_include_directories will add the include directories for all the source files and include_directories won't add them to any.

Does CMake provide a way to do this?

0

There are 0 best solutions below