簡體   English   中英

如何避免使用 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文檔說您可以使用FETCHCONTENT_UPDATES_DISCONNECTED緩存變量獲得您想要的內容:

FETCHCONTENT_UPDATES_DISCONNECTED

...這...禁用更新階段。 因此,如果之前沒有下載過內容,啟用此選項后仍會下載內容。 這可以加快配置階段......默認情況下它是OFF的。

因此,將這個全局設置為ON ,或者僅對於 Catch2,將變量FETCHCONTENT_UPDATES_DISCONNECTED_Catch2設置為ON

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM