小编Art*_*uto的帖子

是否可以使用 FetchContent 或等效项通过 CMake 添加没有 CMakeLists.txt 的库?

我有一个需要使用两个库的小项目,即 ASIO(独立)和 nlohmann/json。

将 json 库添加到我的 CMake 项目非常简单:

include(FetchContent)

FetchContent_Declare(json
  GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
  GIT_TAG v3.9.1)

FetchContent_GetProperties(json)
if(NOT json_POPULATED)
  FetchContent_Populate(json)
  add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
Run Code Online (Sandbox Code Playgroud)

但是,由于 ASIO 没有 CMakeLists.txt,它似乎不起作用。是否有解决方法,或者我是否绝对需要在外部安装 ASIO?

可能值得一提的是,这两个库都是仅头文件,所以我只需要 cmake 来获取库并添加适当的包含路径。

c++ cmake

5
推荐指数
1
解决办法
1577
查看次数

标签 统计

c++ ×1

cmake ×1