CMake and handling subfolder header files

Viewed 19054

I'm trying to set up my project to build several dynamic libraries that encompass its complete functionality. There are subfolders for each library. The subfolder libraries are dependent on each other, so they must reference functions from each other. I seem to have managed to get CMake to run without errors on the project, but when I go to build, I have trouble with my headers finding each other. It seems at build time, the include path isn't set up correctly. How can I fix this? Are there additional steps I need to take to set up the include path correctly?

The structure looks something like this

root
    CMakeLists.txt
    bin
    lib
    lib0
        CMakeLists.txt
        lib0.h
        lib0.cpp
    lib1
        CMakeLists.txt
        lib1.h
        lib1.cpp
    ...

In the CMakeLists.txt for the root directory I have declarations like this:

set(ROOT /blah/blah/root)    

include_directories(${ROOT}/lib0)
include_directories(${ROOT}/lib1)

add_subdirectory(lib0)
add_subdirectory(lib1)

In the CMakeLists.txt for the subfolders, I have:

set(lib0_SOURCES "")
list(APPEND lib0_SOURCES lib0.cpp)
add_library(lib0_lib ${lib0_SOURCES})

And my headers for the libraries look like (suppose this is lib0.h):

#include "lib1/lib1.h"
...

CMake runs fine with no errors, but when I go to compile, I get an error like:

In file included from /blah/blah/root/lib0/lib0.cpp:1:0:
/blah/blah/root/lib0/lib0.h:1:30: fatal error: lib1/lib1.h: No such file or directory
3 Answers
Related