Skip to content
Latchkey

CMake "could not find cmake_minimum_required"

CMake requires every project to declare a minimum version up front. Without a cmake_minimum_required() call before project(), it cannot decide which policy behavior to use and warns or errors.

What this error means

Configure prints that no cmake_minimum_required command was found, or that it must be the first command. With recent CMake this is now an error rather than a deprecation warning.

CMake output
CMake Error in CMakeLists.txt:
  cmake_minimum_required(VERSION) should be called prior to this top-level
  project() call.  Please see the documentation for policy CMP0000 for more
  details.

Common causes

No (or misplaced) cmake_minimum_required

The top-level CMakeLists.txt either omits the call or places it after project(). CMake needs it first to set policy defaults.

CMake pointed at a subdirectory or wrong file

Running CMake against a directory whose CMakeLists.txt is an add_subdirectory fragment - not a top-level project - can trigger this because the fragment never calls it.

How to fix it

Add the call as the first command

Put a real minimum version at the very top of the top-level CMakeLists.txt, before project().

CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(myapp CXX)

Configure the top-level project directory

  1. Run CMake against the directory that holds the top-level CMakeLists.txt, not a sub-component.
  2. Use cmake -S . -B build from the project root so the source dir is unambiguous.

How to prevent it

  • Start every top-level CMakeLists.txt with cmake_minimum_required.
  • Set a realistic minimum (e.g. 3.16+) to avoid deprecated-compatibility warnings.
  • Always use -S/-B so the configured source directory is explicit.

Related guides

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