5

全部。

我决定使用新的 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!

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

4

1 回答 1

3

文档说您可以使用缓存变量FetchContent_Populate获得您想要的内容:FETCHCONTENT_UPDATES_DISCONNECTED

FETCHCONTENT_UPDATES_DISCONNECTED

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

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

于 2021-05-05T20:40:23.397 回答