Since the code is present early, you can link against its targets (e.g., target_link_libraries(my_app GTest::gtest) ) without worrying about whether the library exists yet.
The download_project() function is a specialized CMake macro designed to download and unpack external source code (like GitHub repositories or ZIP archives) rather than waiting for the build step. cmake download_project
By fetching code at configuration time, you can immediately use add_subdirectory() to include that external code into your project. This allows the external project's targets to be available to your main build as if they were part of your own source tree. Key Benefits Since the code is present early, you can
include(DownloadProject.cmake) download_project( PROJ googletest GIT_REPOSITORY https://github.com GIT_TAG v1.14.0 ) # Now the source is available to be added add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) Use code with caution. Modern Alternative: FetchContent FetchContent — CMake 4.3.2 Documentation This allows the external project's targets to be
It avoids the complexity of a "superbuild" pattern, where you have to separate your project into multiple independent CMake runs. How to Use download_project
To use this pattern, you typically include the DownloadProject.cmake module in your project's cmake/ folder and call it like this:
For modern C++ developers, managing external dependencies directly within a build system is a major productivity booster. While CMake now provides built-in tools like FetchContent , the download_project pattern—originally popularized by the Crascit/DownloadProject module—remains a foundational concept for "configure-time" dependency management. What is download_project ?