Populate a CMake dependency at configure time with FetchContent
Answer: This module provides commands to populate content at configure time. Load this module in CMake with include(FetchContent). It was added in 3.11. ExternalProject_Add downloads at build time. FetchContent instead makes content available immediately, so configure can call add_subdirectory, include, or file.
Declare, then make available
Content population details should be defined separately from the command that performs the actual population. Call FetchContent_Declare first. Then call FetchContent_MakeAvailable. That command ensures the named dependencies have been populated. It uses an earlier call when one exists, or it populates them itself. During that population step, the command also adds the dependencies to the main build when it can.
The first details to be declared for a given dependency take precedence. The first call that tries to populate a dependency wins.
| FetchContent_Declare | FetchContent_MakeAvailable | |---|---| | declare content details | populate named dependencies | | before population | after FetchContent_Declare | | include(FetchContent) | include(FetchContent) |
Packages and find_package
Packages provide dependency information to CMake based buildsystems. Packages are found with the find_package command. The result of using find_package is either a set of IMPORTED targets, or a set of variables. FetchContent populates content at configure time. find_package finds packages that are already provided.
See also
Claims
- id: C1 claim: FetchContent populates content at configure time, unlike ExternalProject_Add which downloads at build time. source: S1 evidence: "Whereas :command:
ExternalProject_Adddownloads at build time"
- id: C2 claim: FetchContent_MakeAvailable populates named dependencies and can add them to the main build. source: S1 evidence: "The :command:
FetchContent_MakeAvailablecommand ensures the named"
- id: C3 claim: Installed or provided packages are found with the find_package command. source: S2 evidence: "Packages are found with the :command:
find_packagecommand."
Sources
- [S1] FetchContent. CMake docs. https://cmake.org/cmake/help/latest/module/FetchContent.html . License: BSD-3-Clause. Accessed 2026-11-19.
- [S2] cmake-packages(7). CMake docs. https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/cmake-packages.7.rst . License: BSD-3-Clause. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: CMake docs, FetchContent; CMake docs, cmake-packages(7). BSD-3-Clause; BSD-3-Clause. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: CMake docs, FetchContent; CMake docs, cmake-packages(7). BSD-3-Clause; BSD-3-Clause.
Cite this
iinventedlight. 2026. "Populate a CMake dependency at configure time with FetchContent." iinventedlight Library, iil:note:58pwx5de, version of 2026-11-19. https://iinventedlight.com/library/notes/cmake-fetchcontent/. License: CC-BY-4.0.
@misc{iil_note_58pwx5de,
author = {{iinventedlight}},
title = {{Populate a CMake dependency at configure time with FetchContent}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/cmake-fetchcontent/},
note = {Permanent ID iil:note:58pwx5de. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- cmake-fetchcontent.table.json (table; CC-BY-4.0)
- cmake-fetchcontent.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/cmake-fetchcontent.md.