【发布时间】:2016-08-10 17:21:32
【问题描述】:
我建立了一个CMake项目,其目录结构如下:
src/
--CMakeLists.txt
--libA/
----CMakeLists.txt
----foo.h
----foo.cpp
--main/
----CMakeLists.txt
----main.cpp
src/CMakeLists.txt 使用add_subdirectory 拉入libA 和main。 libA/CMakeLists.txt 使用add_library 定义一个名为libA 的库,它通过target_include_directories 导出foo.h。如果我现在使用target_link_library 在main 中链接libA,我可以通过#include <foo.h> 在main.cpp 中包含foo.h。
问题:是否可以为libA 的公共接口提供前缀,以便我可以(并且必须)在main.cpp 中写#include <libA/foo.h>?
【问题讨论】:
-
此链接可能会有所帮助:stackoverflow.com/questions/19460707/…
-
在
target_include_directories中包含根目录而不是libA有什么问题? -
@usr1234567 因为例如您希望可以选择在使用不提供前缀的子目录和使用具有该前缀的系统包之间切换。例如,在使用 Bullet 库时,不使用丑陋的
#ifdefs 来区分#include <btVector3.h>和#include <bullet/btVector3.h>会很方便。 -
@MateuszDrost 这可能很方便,但它的风格很糟糕。