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

e.p*_*kov 10 c++ cmake catch2

全部。

\n

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

\n
include(FetchContent)\n\nFetchContent_Declare(\n    Catch2\n    GIT_REPOSITORY https://github.com/catchorg/Catch2.git\n    GIT_TAG        v2.13.4\n)\nFetchContent_GetProperties(Catch2)\nif(NOT Catch2_POPULATED)\n    FetchContent_Populate(Catch2)\n    add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR})\nendif()\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
[0/7] Performing update step for 'catch2-populate'\nfatal: \xc2\xabhttps://github.com/catchorg/Catch2.git/\xc2\xbb \xd0\xbd\xd0\xb5\xd0\xb4\xd0\xbe\xd1\x81\xd1\x82\xd1\x83\xd0\xbf\xd0\xbd\xd0\xbe: Could not resolve host: github.com\nCMake Error at /Users/evgeny.proydakov/repository/ihft/build/_deps/catch2-subbuild/catch2-populate-prefix/tmp/catch2-populate-gitupdate.cmake:97 (execute_process):\n  execute_process failed command indexes:\n\n    1: "Child return code: 128"\n\nFAILED: catch2-populate-prefix/src/catch2-populate-stamp/catch2-populate-update \ncd /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\nninja: build stopped: subcommand failed.\n\nCMake Error at /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1012 (message):\n  Build step for catch2 failed: 1\nCall Stack (most recent call first):\n  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1141:EVAL:2 (__FetchContent_directPopulate)\n  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1141 (cmake_language)\n  /usr/local/Cellar/cmake/3.20.1/share/cmake/Modules/FetchContent.cmake:1184 (FetchContent_Populate)\n  .cmake/icmake.cmake:46 (FetchContent_MakeAvailable)\n  CMakeLists.txt:10 (include)\n\n-- Configuring incomplete, errors occurred!\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

ein*_*ica 7

的文档说你FetchContent_Populate可以通过缓存变量得到你想要的东西FETCHCONTENT_UPDATES_DISCONNECTED

FETCHCONTENT_UPDATES_DISCONNECTED

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

因此,将此变量设置为ON全局,或者仅对于 Catch2,将变量设置FETCHCONTENT_UPDATES_DISCONNECTED_Catch2ON