# cmake offline build - how to pre-populate source dependencies in the build tree

**URL:** https://discourse.cmake.org/t/cmake-offline-build-how-to-pre-populate-source-dependencies-in-the-build-tree/13173
**Category:** Usage
**Tags:** tool:cmake
**Created:** [December 10, 2024, 6:56pm UTC](https://discourse.cmake.org/t/cmake-offline-build-how-to-pre-populate-source-dependencies-in-the-build-tree/13173 "2024-12-10T18:56:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![s837jhc](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@s837jhc](https://discourse.cmake.org/u/s837jhc)
#### Post date: [December 10, 2024, 6:56pm UTC](https://discourse.cmake.org/t/cmake-offline-build-how-to-pre-populate-source-dependencies-in-the-build-tree/13173/1 "2024-12-10T18:56:08Z")

</div>

I am trying to build a project while offline. The project is [sol2](https://github.com/ThePhD/sol2), but the question is more general. Using that project as an example to talk to in a response here is fine, but I am more interested in the general “cmake way” to do this (e.g., say starting simple with a CMakeLists.txt that references a small number of C files which need an external package of header files to build).

I will have all source tarballs available ahead of time before the offline build starts.

Where should I put source tarballs (pre-populate a source directory - presumably eventually copied / linked in the .build tree) so that FetchContent and find\_package can find them? I have tried reading some cmake documentation [[1]], but I need something more plain (or documentation to explain the documentation perhaps).

I am running cmake with -DFETCHCONTENT\_FULLY\_DISCONNECTED:BOOL=ON

[[1]]  
[Using Dependencies Guide](https://cmake.org/cmake/help/latest/guide/using-dependencies/index.html#guide:Using%20Dependencies%20Guide)  
FetchContent  
find\_package

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 10, 2024, 8:26pm UTC](https://discourse.cmake.org/t/cmake-offline-build-how-to-pre-populate-source-dependencies-in-the-build-tree/13173/2 "2024-12-10T20:26:48Z")

</div>

Since you’ve mentioned source tarballs, I’m assuming you’re trying to have all your dependencies provided via FetchContent, and that your project is re-routing any `find_package()` calls for those dependencies to FetchContent by one of the documented mechanisms.

For your scenario, don’t set `FETCHCONTENT_FULLY_DISCONNECTED` to true. That option is basically useless and doesn’t do what people think it does. It is explicitly disallowed to set it to true on the first run. It can only be set to true after the first run has done an initial population. For subsequent runs, if you’ve provided a `URL_HASH` with your `URL` downloads, or if you’re using a tag or commit hash with `GIT_TAG`, the behavior will already avoid connecting to a remote because it will already have what it needs locally.

Currently, the only way to force FetchContent to use sources you’ve already downloaded somewhere is to set the `FETCHCONTENT_SOURCE_DIR_<uppercaseDepName>` variables. For each dependency, set the corresponding variable to point to wherever you have the sources already downloaded. You must have already unpacked them, you can’t point it at a tarball. FetchContent expects it to be a directory name containing the dependency’s sources.

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [February 24, 2025, 4:51pm UTC](https://discourse.cmake.org/t/cmake-offline-build-how-to-pre-populate-source-dependencies-in-the-build-tree/13173/3 "2025-02-24T16:51:01Z")

</div>

Partially related to [file(DOWNLOAD) offline mode](https://discourse.cmake.org/t/file-download-offline-mode/8916)
