CMAKE dependency on upstream C++ Header-only library

200 views Asked by At

I have a relatively simple header-only C++ library with the following structure

- apps
  - app
    - CMakeLists.txt
    - app.cpp
- include
CMakeLists.txt

The library itself is in the root of the project and app1 is added afterwards. My intention here is to use the header-only library as a target referencing include directories and link dependencies.

Here's the root CMakeLists.txt file:

project(myLib)

find_package( OpenGL REQUIRED )
find_package( GLEW REQUIRED )
find_package( Eigen3 REQUIRED )

# add the target
add_library( ${PROJECT_NAME} INTERFACE )
target_include_directories( ${PROJECT_NAME} INTERFACE . )
target_link_directories( ${PROJECT_NAME} INTERFACE OpenGL::OpenGL GLEW::glew Eigen3::Eigen )

# add apps
add_subdirectory(apps)

And the CMakeLists.txt file of the app:

project(app)

# find Qt5
find_package(Qt5 COMPONENTS Gui Widgets OpenGL REQUIRED)

# add the exec
add_executable( ${PROJECT_NAME} app.cpp )
target_include_directories( ${PROJECT_NAME} PRIVATE . )
target_link_libraries( ${PROJECT_NAME} myLib Qt5::Gui Qt5::Widgets Qt5::OpenGL )

Since app1 is downstream from myLib I thought I can just add myLib to the link libraries of the app and it would configure everything automatically. This did not work and app could not see the include directories of myLib.

Any ideas how to fix this, or an explanation if the approach is wrong to begin with?

Thank you

0

There are 0 answers