如何避免使用 CMake FetchContent 进行更新检查?
How to avoid update checks with CMake FetchContent?
所有。
我决定使用新的 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_Populate
的 documentation 表示您可以使用 FETCHCONTENT_UPDATES_DISCONNECTED
缓存变量获得您想要的内容:
FETCHCONTENT_UPDATES_DISCONNECTED
... This ... disables the
update stage. Therefore, if content has not been downloaded
previously, 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
。
所有。
我决定使用新的 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_Populate
的 documentation 表示您可以使用 FETCHCONTENT_UPDATES_DISCONNECTED
缓存变量获得您想要的内容:
FETCHCONTENT_UPDATES_DISCONNECTED
... This ... disables the update stage. Therefore, if content has not been downloaded previously, 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
。