# How to create a tarball with all the sources from FetchContents?

**URL:** <https://discourse.cmake.org/t/how-to-create-a-tarball-with-all-the-sources-from-fetchcontents/6618>\
**Category:** Code\
**Created:** [October 6, 2022, 12:34pm UTC](https://discourse.cmake.org/t/how-to-create-a-tarball-with-all-the-sources-from-fetchcontents/6618 "2022-10-06T12:34:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojca](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mojca/32/610_2.png) [@mojca](https://discourse.cmake.org/u/mojca)\
**Post date:** [October 6, 2022, 12:34pm UTC](https://discourse.cmake.org/t/how-to-create-a-tarball-with-all-the-sources-from-fetchcontents/6618/1 "2022-10-06T12:34:55Z")

</div>

Over the course of a few months since we started a project we realized that `FetchContents` has beaten us a number of times when upstream projects that we depend on rewrote git history, added a few commits on top of their main branch (and we used `GIT_SHALLOW ON`, so `FetchContents` wasn’t able to find anything), …

I would like to be able to create a “self-contained fat tarball” that would pre-fetch all dependencies and pack them together with our source code into a tarball that could be compiled any time in the future, independent of whether or not the upstream sources still exist at their original location.

When using git sumbodules that can easily be achieved by recursively fetching all the submodules, but it seems somewhat more tricky to achieve the same with `FetchContents`.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [October 7, 2022, 5:43pm UTC](https://discourse.cmake.org/t/how-to-create-a-tarball-with-all-the-sources-from-fetchcontents/6618/2 "2022-10-07T17:43:39Z")

</div>

`GIT_SHALLOW` is incompatible with commit hashes. I would recommend forking and adding tags.

What we do is upload tarballs to our own infrastructure and fetch those instead. Much more reliable over time and allows for offline builds (by prefetching all network resources).

That said, maybe others have better experience to share about `FetchContent` in particular.
