cmake - 使用 {fmt} 作为 CMake 依赖项的问题

标签 cmake fmt

我正在尝试在我的项目中应用现代 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 的帮助下,我通过以下步骤解决了这个问题:

  • TARGET_LINK_LIBRARIES(mylib INTERFACE fmt::fmt-header-only) 在 mylib/CMakeLists.txt ( PUBLIC 之前)。
  • 将以下内容添加到根 CMakeLists.txt:add_subdirectory(mylib) (那是什么改变了)。

  • 我将最终版本推送到仓库:https://bitbucket.org/ngrodzitski/cmake-issue-fmt-20180410 .

    关于cmake - 使用 {fmt} 作为 CMake 依赖项的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49750471/

    相关文章:

    c++ - 如何在 CMake 中使用 OpenGL/Angle 编译 QtGui 示例?

    c++ - 带有多个标志的 target_compile_definitions

    cmake 忽略 findPackage for protobuf 中的确切选项

    cmake - 与CMake等价的Makefile

    c++ - {fmt}在字符串中仅替换一个位置参数几个位置参数

    c++ - 如何将非可变值传递给 fmt::format?

    c++ - 在C++ {fmt}中格式化琐碎结构的扩展计划?

    c++ - Assimp 无法在 Code::Blocks 中正确构建 - "TVITEMEXW not declared in current scope"

    c++ - 使用 {fmt} 和 source_location 创建基于可变参数模板的日志功能

    python - Python 中 % 或 .format 运算符的 C++ 等价物是什么?