Following situation: You have your own CMake Library, that depends on nanogui (probably same for other libs)
$ tree
.
├── CMakeLists.txt
├── src
│ └── main.cpp
└── ext
└── CustomLibrary
├── CMakeLists.txt
├── include
│ ├── libComponentA.h
│ └── libComponentB.h
├── ext
│ └── nanogui
└── src
├── libComponentA.cpp
└── libComponentB.cpp
In your main project (the integration project), you have a dependency on your CustomLibrary
:
project(Integration)
...snip...
# My Lib
add_subdirectory(ext/CustomLibrary)
include_directories(ext/CustomLibrary/include)
add_executable(${MAIN_TARGET} src/main.cpp)
target_link_libraries(${MAIN_TARGET} CustomLibrary)
You know that your CustomLibrary
compiles, because you have tested that.
But strangely, it doesn't compile when integrated into another CMake project.
It always bugs you about not finding certain header files (includes), that should've already been included by your library.
What did it for me is to replace include_directories(lib/nanogui/include)
in your library with target_include_directories(${APP_LIB} PUBLIC lib/nanogui/include)
This way, the includes get propagated to the parent.