CMake从仅标头目标包含仅标头目标

时间:2019-03-05 20:33:02

标签: c++ cmake

我正在尝试设置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_alibrary_b实现的通用接口。最终将有更多的实现。因此,在c.hpp中,我包含了a.hpp标头,并在b.hpp实现中使用了c.cpp。一切都配置良好,但是当我进行编译时,出现错误,找不到a.hpp文件。如何获得target_link_libraries(target_c INTERFACE target_b)来包含target_a的标题?

0 个答案:

没有答案