簡體   English   中英

在 cmake 中為接口庫添加庫依賴項

[英]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-onlyINTERFACE庫與否。 鏈接是通過target_link_libraries完成的

target_link_libraries(mylib INTERFACE fmt::fmt-header-only)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM