我正在尝试在我的项目中应用现代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
有关此问题的任何建议吗?
答案 0 :(得分:1)
在Mathieu Ropert的帮助下,我已经按照以下步骤解决了这个问题:
INTERFACE
之前)的TARGET_LINK_LIBRARIES(mylib PUBLIC
fmt :: fmt-header-only)。add_subdirectory(mylib)
(进行更改的内容)。我将最终版本推送到repo:https://bitbucket.org/ngrodzitski/cmake-issue-fmt-20180410。