[英]Adding library dependencies to interface libraries in cmake
I have the following cmake file我有以下 cmake 文件
cmake_minimum_required(VERSION 3.16)
find_package(fmt)
add_library(mylib INTERFACE )
add_dependencies(mylib fmt::fmt-header-only)
target_compile_features(mylib INTERFACE cxx_std_20)
target_include_directories(mylib INTERFACE .)
add_executable(test_exe test_exe.cpp)
target_link_libraries(test_exe PUBLIC mylib)
But fmt
is not linked against test_exe
unless I explicitly add it to the dependencies.但是
fmt
不会与test_exe
链接,除非我明确地将它添加到依赖项中。 Am I defining the dependencies of mylib
wrong?我是否错误地定义了
mylib
的依赖项?
The error is the following and it goes away if I add fmt::header-only
to the link libraries of test_exe
错误如下,如果我将
fmt::header-only
添加到test_exe
的链接库,它就会消失
fatal error: 'fmt/format.h' file not found
#include <fmt/format.h>
^~~~~~~~~~~~~~
add_dependencies(mylib fmt::fmt-header-only)
simply makes sure that the target fmt::fmt-header-only
is up to date before mylib
is built.只需确保在构建
mylib
之前目标fmt::fmt-header-only
是最新的。 It doesn't link fmt::fmt-header-only
, INTERFACE
library or not.它不链接
fmt::fmt-header-only
、 INTERFACE
库与否。 Linking is done via target_link_libraries
链接是通过
target_link_libraries
完成的
target_link_libraries(mylib INTERFACE fmt::fmt-header-only)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.