← All notes

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

Sources

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

Permanent ID: iil:note:58pwx5de

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.},
}

Markdown

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.

All artifact files (JSON index)

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.