【问题标题】:How to avoid update checks with CMake FetchContent?如何避免使用 CMake FetchContent 进行更新检查?
【发布时间】:2021-07-28 04:37:09
【问题描述】:

全部。

我决定使用新的 cmake 宏来下载外部依赖项。 我从 Catch2 库的文档中获取了示例代码。

include(FetchContent)

FetchContent_Declare(
    Catch2
    GIT_REPOSITORY https://github.com/catchorg/Catch2.git
    GIT_TAG        v2.13.4
)
FetchContent_GetProperties(Catch2)
if(NOT Catch2_POPULATED)
    FetchContent_Populate(Catch2)
    add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})
endif()

该解决方案效果很好,除了能够在我离线时重新启动 cmake(没有 wifi 和移动网络,只有我和我的笔记本电脑)。 我收到以下错误:

[0/7] Performing update step for 'catch2-populate'
fatal: «https://github.com/catchorg/Catch2.git/» недоступно: Could not resolve host: github.com
CMake Error at /Users/evgeny.proydakov/repository/ihft/build/_deps/catch2-subbuild/catch2-populate-prefix/tmp/catch2-populate-gitupdate.cmake:97 (execute_process):
  execute_process failed command indexes:

    1: "Child return code: 128"

FAILED: catch2-populate-prefix/src/catch2-populate-stamp/catch2-populate-update 
cd /Users/evgeny.proydakov/repository/ihft/build/_deps/catch2-src && /usr/local/Cellar/cmake/3.20.1/bin/cmake -P /Users/evgeny.proydakov/repository/ihft/build/_deps/catch2-subbuild/catch2-populate-prefix/tmp/catch2-populate-gitupdate.cmake
ninja: build stopped: subcommand failed.

CMake Error at /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1012 (message):
  Build step for catch2 failed: 1
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1141:EVAL:2 (__FetchContent_directPopulate)
  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1141 (cmake_language)
  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1184 (FetchContent_Populate)
  .cmake/icmake.cmake:46 (FetchContent_MakeAvailable)
  CMakeLists.txt:10 (include)

-- Configuring incomplete, errors occurred!

是否可以一次下载依赖,检查版本,不要每次都尝试连接远程服务器?

【问题讨论】:

    标签: c++ cmake catch2


    【解决方案1】:

    FetchContent_Populatedocumentation 表示您可以通过 FETCHCONTENT_UPDATES_DISCONNECTED 缓存变量获得您想要的内容:

    FETCHCONTENT_UPDATES_DISCONNECTED

    ...这...禁用 更新阶段。因此,如果内容尚未下载 以前,启用此选项后仍会下载它。 这可以加快配置阶段...默认为OFF

    所以将这个全局设置为ON,或者仅对于Catch2,将变量FETCHCONTENT_UPDATES_DISCONNECTED_Catch2设置为ON

    【讨论】:

      猜你喜欢
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 2020-03-16
      • 1970-01-01
      相关资源
      最近更新 更多