Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid update checks with CMake FetchContent?

Tags:

c++

cmake

catch2

all.

I decided to use the new cmake macro to download external dependencies. I took the sample code from the documentation for the Catch2 library.

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()

The solution works great, except for the ability to restart the cmake when I am offline (no wifi and mobile network only me and my laptop). I get the following error:

[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!

Is it possible to download dependency one time, check revision and don't try to connect each time to remote server?

like image 518
e.proydakov Avatar asked Oct 14 '22 21:10

e.proydakov


1 Answers

The documentation for FetchContent_Populate says you can get exactly what you want with the FETCHCONTENT_UPDATES_DISCONNECTED cache variable:

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.

So set this one to ON globally, or for Catch2 only, set the variable FETCHCONTENT_UPDATES_DISCONNECTED_Catch2 to ON.

like image 148
einpoklum Avatar answered Oct 18 '22 14:10

einpoklum