CMake "Unknown CMake command" - Missing Module or Old Version
CMake hit a command it does not know. Either it comes from a module you never include()d, a package you never find_package()d, or a feature added in a CMake newer than the one running.
What this error means
Configure fails at a specific line saying the command is unknown. The same CMakeLists.txt configures with a newer CMake or once the providing module is included.
CMake Error at CMakeLists.txt:14 (FetchContent_Declare):
Unknown CMake command "FetchContent_Declare".Common causes
Command’s module not included
Commands like FetchContent_Declare, pkg_check_modules, or write_basic_package_version_file only exist after you include() their module (FetchContent, FindPkgConfig, CMakePackageConfigHelpers).
CMake too old for the command
A command introduced in a newer CMake is unknown on an older one shipped by the runner image, so configure fails on a line that works locally.
How to fix it
Include the module that defines it
Add the matching include() before the first use of the command.
include(FetchContent)
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git GIT_TAG 10.2.1)Install a newer CMake in CI
When the command needs a newer CMake than the image ships, pin a current version.
- uses: lukka/get-cmake@latest
with:
cmakeVersion: '3.29.0'
- run: cmake --versionHow to prevent it
- Raise
cmake_minimum_requiredto the version that defines the commands you use. - Pin a known CMake version in CI rather than the distro default.
include()modules at the top so command availability is obvious.