gpt4 book ai didi

c++ - 如何避免使用 CMake FetchContent 进行更新检查?

转载 作者:行者123 更新时间:2023-12-04 03:27:16 32 4
gpt4 key购买 nike

全部。
我决定使用新的 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!
是否可以一次下载依赖项,检查版本并且不要每次都尝试连接到远程服务器?

最佳答案

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

FETCHCONTENT_UPDATES_DISCONNECTED

... This ... disables theupdate stage. Therefore, if content has not been downloadedpreviously, it will still be downloaded when this option is enabled.This can speed up the configure stage... It is OFF by default.


因此,将其全局设置为 ON ,或者仅针对 Catch2,将变量 FETCHCONTENT_UPDATES_DISCONNECTED_Catch2 设置为 ON

关于c++ - 如何避免使用 CMake FetchContent 进行更新检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67408357/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com