GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - SpontanCombust/cmake-fetchcontent-offline: CMake module that lets you automatically disable FetchContent updates if you're currently not connected to the internet.

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
README.md
README.md
 
 
fetchcontent-offline.cmake
fetchcontent-offline.cmake
 
 

Repository files navigation

cmake-fetchcontent-offline

CMake module that lets you automatically disable FetchContent updates if you're currently not connected to the internet.

Why?

Every time a cmake project that is using the FetchContent module is configured it fails critically if you for some reason don't have access to the internet at the moment. That is unless you configure FETCHCONTENT_FULLY_DISCONNECTED and/or FETCHCONTENT_UPDATES_DISCONNECTED variables. Using them isn't the best however as if you wanted to actually update your dependencies you'd have to temporarily set these variables back to false. This module ensures that when you're online dependency checking and populating process happens as usual and when you're offline dependency downloads and updates are disabled and don't cause the configuration to fail by themselves.

How-To

Method A.

  1. Download the module file paste it in your project tree, for example into project_root/cmake/modules/
  2. Make the module discoverable by your CMakeLists.txt
#add the module to the module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules") 
# include the module
include(fetchcontent-offline) 
  1. Call FetchContent_DisconnectedIfOffline()
# make sure to have the FetchContent module included before that
include(FetchContent)
# invoke the function supplied by the module, place it before any calls to FetchContent_MakeAvailable and such
FetchContent_DisconnectedIfOffline() 

Method B.

Use FetchContent itself to download the module once and then use it.

include(FetchContent)

# declare the dependency
FetchContent_Declare(
    FetchContentOffline
    GIT_REPOSITORY https://github.com/SpontanCombust/cmake-fetchcontent-offline
)
# make sure it will be downloaded once and never updated
set(FETCHCONTENT_UPDATES_DISCONNECTED_FETCHCONTENTOFFLINE ON)
# fetch the dependency
FetchContent_MakeAvailable(FetchContentOffline)

# make the module discoverble, use dependency's cached path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${fetchcontentoffline_SOURCE_DIR}")
include(fetchcontent-offline)

FetchContent_DisconnectedIfOffline()

Module contents

Functions:

  • FetchContent_DisconnectedIfOffline()

Cache variables:

  • FETCHCONTENT_OFFLINE_MODE

After calling FetchContent_DisconnectedIfOffline() a FETCHCONTENT_OFFLINE_MODE variable is set. You can explicitly check its value to perform some arbitrary operation.

FetchContent_DisconnectedIfOffline()

if(FETCHCONTENT_OFFLINE_MODE)
    message("Hello offline mode!")
else()
    message("Hello online mode!")
endif()

About

CMake module that lets you automatically disable FetchContent updates if you're currently not connected to the internet.

Topics

cmakefetchcontent

Resources

Readme
MIT license
Activity

Stars

4 stars

Watchers

1 watching

Forks

1 fork
Report repository

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.