Skip to content
Latchkey

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 output
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.

CMakeLists.txt
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.

.github/workflows/ci.yml
- uses: lukka/get-cmake@latest
  with:
    cmakeVersion: '3.29.0'
- run: cmake --version

How to prevent it

  • Raise cmake_minimum_required to 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →