While both can download Git repositories, they serve different purposes: FetchContent ExternalProject_Add Configure time (when you run cmake .. ) Build time (when you run cmake --build . ) Visibility Targets are immediately available for linking Targets only exist after the build starts Best Use Case
: The specific version (tag, branch, or commit hash) to download. cmake download git repo
To download a repository, you must first include the module and then declare the repository details. While both can download Git repositories, they serve
Downloading Git repositories directly within CMake is a modern standard for managing C++ dependencies. It allows you to automate the process of fetching source code, ensuring that every developer on a team uses the exact same version of a library. To download a repository, you must first include
include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0 # Use a specific tag or commit hash for stability ) FetchContent_MakeAvailable(googletest) Use code with caution. : The URL of the remote Git repo.
FetchContent is the modern, idiomatic way to download a Git repository. It populates the content at configure time, allowing you to use its targets immediately in your build script via target_link_libraries() . Basic Implementation