我正在尝试设置cmake,以便我可以拥有依赖于另一个仅标头库的仅标头库。我的目录结构如下所示。
library_a
|_a.hpp
library_b
|_b.hpp
library_c
|_c.hpp
|_c.cpp
我的CMakeLists.txt
设置如下
目录根:
add_subdirectory (library_a)
add_subdirectory (library_b)
add_subdirectory (library_c)
library_a
目录
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
目录
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
目录
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)
目标library_a
是library_b
实现的通用接口。最终将有更多的实现。因此,在c.hpp
中,我包含了a.hpp
标头,并在b.hpp
实现中使用了c.cpp
。一切都配置良好,但是当我进行编译时,出现错误,找不到a.hpp
文件。如何获得target_link_libraries(target_c INTERFACE target_b)
来包含target_a
的标题?