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

I am trying to build a project while offline. The project is 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
FetchContent
find_package

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.

1 Like