[英]Adding library dependencies to interface libraries in cmake
我有以下 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)
但是fmt
不會與test_exe
鏈接,除非我明確地將它添加到依賴項中。 我是否錯誤地定義了mylib
的依賴項?
錯誤如下,如果我將fmt::header-only
添加到test_exe
的鏈接庫,它就會消失
fatal error: 'fmt/format.h' file not found
#include <fmt/format.h>
^~~~~~~~~~~~~~
add_dependencies(mylib fmt::fmt-header-only)
只需確保在構建mylib
之前目標fmt::fmt-header-only
是最新的。 它不鏈接fmt::fmt-header-only
、 INTERFACE
庫與否。 鏈接是通過target_link_libraries
完成的
target_link_libraries(mylib INTERFACE fmt::fmt-header-only)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.