Skip to content

Instantly share code, notes, and snippets.

@whateverforever
Created January 25, 2019 16:38
Show Gist options
  • Save whateverforever/49f7309176abdbdcfd20745c7bd17a35 to your computer and use it in GitHub Desktop.
Save whateverforever/49f7309176abdbdcfd20745c7bd17a35 to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment