Cmake Download Repository |verified| May 2026

Before FetchContent existed, ExternalProject_Add was the go-to tool. The key difference is that ExternalProject performs the download and build at "build time" rather than "configure time." When to use it

If managing many URLs and Git tags becomes overwhelming, consider a C++ package manager that integrates with CMake:

Developers don't need to pre-install libraries on their OS. cmake download repository

Avoid using GIT_TAG master or main . If the repository updates, your build might break unexpectedly. Always point to a specific version or a specific commit hash for reproducibility. Manage Local Caching

Large repositories with long histories can slow down your build significantly. Use GIT_SHALLOW TRUE in your declaration to only download the latest commit. Prefer Git Tags or Hashes If the repository updates, your build might break

Works well with find_package() and handles the downloading/patching for you.

To use it, you first include the module, declare the repository details, and then make the content available. Use GIT_SHALLOW TRUE in your declaration to only

include(ExternalProject) ExternalProject_Add( ext_png_lib GIT_REPOSITORY https://github.com GIT_TAG v1.6.37 INSTALL_COMMAND "" # Skips the install step ) Use code with caution. 3. Comparing Download Methods FetchContent ExternalProject Configure Time Build Time Target Visibility Visible immediately Not visible until built Best For CMake-based libraries Non-CMake or large builds Ease of Use 4. Best Practices for Downloading Repositories