我正在尝试在我的项目中应用现代 CMake 实践。
我想出了一个关于 {fmt} library 的问题依赖性。
一个项目的结构如下(简要):
dev/
|
+--- fmt/ *unpacked archive of 4.1.0 version*
|
+--- mylib/
| |
| +--- mylib.hpp
| |
| +--- CMakeLists.txt
| ***************************
| * ...
| * add_library(mylib INTERFACE)
| * TARGET_LINK_LIBRARIES(mylib PUBLIC fmt-header-only)
| * set(MYLIB_HEADERS_ALL mylib.hpp )
| * ...
| ***************************
|
+--- sample/
| |
| +--- main.cpp
| |
| +--- CMakeLists.txt
| ***************************
| * set(SAMPLE sample.hello_world)
| * add_executable(${SAMPLE} main.cpp)
| * TARGET_LINK_LIBRARIES(${SAMPLE} PRIVATE mylib)
| * install(TARGETS ${SAMPLE} DESTINATION bin)
| ***************************
|
+--- CMakeLists.txt
***************************
* include_directories(${CMAKE_CURRENT_SOURCE_DIR})
* add_subdirectory(fmt EXCLUDE_FROM_ALL)
* add_subdirectory(sample/hello_world)
***************************
当我尝试构建它时,我收到一个错误:
PATH/mylib/mylib.hpp:6:10: fatal error: fmt/format.hpp: No such file or directory
#include <fmt/format.hpp>
^~~~~~~~~~~~~~~~
compilation terminated.
完整复制可以在这里找到:
https://bitbucket.org/ngrodzitski/cmake-issue-fmt-20180410
关于这个问题有什么建议吗?
最佳答案
在 Mathieu Ropert 的帮助下,我通过以下步骤解决了这个问题:
INTERFACE
fmt::fmt-header-only) 在 mylib/CMakeLists.txt ( PUBLIC
之前)。 add_subdirectory(mylib)
(那是什么改变了)。 我将最终版本推送到仓库:https://bitbucket.org/ngrodzitski/cmake-issue-fmt-20180410 .
关于cmake - 使用 {fmt} 作为 CMake 依赖项的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49750471/