I'm trying to setup cmake so that I can have a header only library that depends on another header only library. My directory structure looks like this.
library_a
|_a.hpp
library_b
|_b.hpp
library_c
|_c.hpp
|_c.cpp
I have my CMakeLists.txt
setup as follows
Directory root:
add_subdirectory (library_a)
add_subdirectory (library_b)
add_subdirectory (library_c)
library_a
directory
add_library(target_a INTERFACE)
target_sources(target_a INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/a.hpp>)
target_include_directories(target_a INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
library_b
directory
add_library(target_b INTERFACE)
target_sources(target_b INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/b.hpp>)
target_include_directories(target_b INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_library(target_b INTERFACE target_a)
library_c
directory
add_library(target_c STATIC)
target_sources(korc_node_context
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/c.cpp>
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/c.hpp>)
target_include_directories(target_c INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(target_c INTERFACE target_b)
Target library_a
is meant to be the generic interface to the library_b
implementation. Eventually there will be more implementations. So in c.hpp
I include the a.hpp
header and use b.hpp
in the c.cpp
implementation. Everything configures fine but when I go to compile, I get an error that the a.hpp
file cannot be found. How can I get target_link_libraries(target_c INTERFACE target_b)
to include the headers from target_a
?