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 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().
cmake_minimum_required(VERSION 3.16)
project(myapp CXX)Configure the top-level project directory
- Run CMake against the directory that holds the top-level
CMakeLists.txt, not a sub-component. - Use
cmake -S . -B buildfrom the project root so the source dir is unambiguous.
How to prevent it
- Start every top-level
CMakeLists.txtwithcmake_minimum_required. - Set a realistic minimum (e.g. 3.16+) to avoid deprecated-compatibility warnings.
- Always use
-S/-Bso the configured source directory is explicit.