Fetching from github with depth setting

When calling FetchContent_Declare to github, is there a way to tell CMake to do a shallow clone (using depth option) or specify the depth of what to fetch from github?

Sometimes there are huge repos with dependencies of a project from which one is only interested in the “current version” for a branch. Having to pull the complete repo adds time to the build and it’s usually a waste of CPU and bandwidth.

Thanks,

The better way is probably to use a tarball instead (note that the auto-generated tarballs are not deterministic, so hash checking may fail over time and they also do not include submodules).

But if that doesn’t work, there is GIT_SHALLOW 1 (it’s a bool, not a depth) that you can use if you use a refname (branch or tag) as shallow clones do not support full hashes unless they are also directly named by a ref.

OK that makes sense. Can you please tell me how to use this on FetchContent_Declare ?
I’ve look for this on the documentation but haven’t found it… I’m probably missing it…

It’s in the documentation for ExternalProject_add.

OK, found it. Yet, if I add it like this:

FetchContent_Declare(
        gecko_sdk
        GIT_REPOSITORY https://github.com/SiliconLabs/gecko_sdk.git
        GIT_TAG v4.0.2
        GIT_SHALLOW 1
    )

The repo keeps being fully downloaded just like if it wasn’t that GIT_SHALLOW 1 there.

Odd. @craig.scott?

I think this is a known issue. Unfortunately, the actual implementation of this is not straightforward. See discussions in Issue 17770, which I think is probably the most relevant. Potentially also relevant might be issues 16144 and 20314 if git submodules are involved.

In this particular case, no concerns about the sub-modules.

Going through issue 17770 it seems that this is exactly it. Sorry to hear that’s not easy to fix…
For what’s worth, please consider my up vote on getting this fixed. It would shave a LOT of time (and bandwidth) from builds using it. :slight_smile: