cmake_minimum_required — CMake 4.2.6 Documentation

# cmake_minimum_required

Require a minimum version of cmake.

    cmake_minimum_required(VERSION <min>[...<policy_max>] [FATAL_ERROR])

Added in version 3.12: The optional `<policy_max>` version behavior; ignored in older CMake.

Sets the minimum required version of cmake for a project. Also updates the policy settings as explained below.

`<min>` and the optional `<policy_max>` are each CMake versions of the form `major.minor[.patch[.tweak]]`, and the `...` is literal.

If the running version of CMake is lower than the `<min>` required version it will stop processing the project and report an error. The optional `<policy_max>` version, if specified, must be at least the `<min>` version and sets the Policy Version. If the running version of CMake is older than 3.12, the extra `...` dots will be seen as version component separators, resulting in the `...<max>` part being ignored and preserving the pre-3.12 behavior of basing policies on `<min>`.

This command will set the value of the `CMAKE_MINIMUM_REQUIRED_VERSION` variable to `<min>`.

The `FATAL_ERROR` option is accepted but ignored by CMake 2.6 and higher. It should be specified so CMake versions 2.4 and lower fail with an error instead of just a warning.

Note

Call the `cmake_minimum_required()` command at the beginning of the top-level `CMakeLists.txt` file even before calling the `project()` command. It is important to establish version and policy settings before invoking other commands whose behavior they may affect. See also policy `CMP0000`.

Calling `cmake_minimum_required()` inside a `function()` limits some effects to the function scope when invoked. For example, the `CMAKE_MINIMUM_REQUIRED_VERSION` variable won't be set in the calling scope. Functions do not introduce their own policy scope though, so policy settings of the caller will be affected (see below). Due to this mix of things that do and do not affect the calling scope, calling `cmake_minimum_required()` inside a function is generally discouraged.

## Policy Version

`cmake_minimum_required(VERSION <min>[...<max>])` implicitly invokes

    cmake_policy(VERSION <min>[...<max>])

This specifies that the current CMake code is written for the given range of CMake versions, `<min>[...<max>]`. It sets the "policy version" to:

- the range's `<max>` version, if specified, or to

- the `<min>` version, or to

- the value of the `CMAKE_POLICY_VERSION_MINIMUM` variable if it is higher than the other two versions.

The policy version effectively requests behavior preferred as of a given CMake version and tells newer CMake versions to warn about their new policies. All policies known to the running version of CMake and introduced in that version or earlier will be set to use `NEW` behavior. All policies introduced in later versions will be unset (unless the `CMAKE_POLICY_DEFAULT_CMP<NNNN>` variable sets a default). This effectively requests behavior preferred as of a given CMake version and tells newer CMake versions to warn about their new policies.

Changed in version 4.0: Compatibility with versions of CMake older than 3.5 is removed. Calls to `cmake_minimum_required(VERSION)` or `cmake_policy(VERSION)` that do not specify at least 3.5 as their policy version (optionally via `...<max>`) will produce an error in CMake 4.0 and above.

Changed in version 3.31: Compatibility with versions of CMake older than 3.10 is deprecated. Calls to `cmake_minimum_required(VERSION)` or `cmake_policy(VERSION)` that do not specify at least 3.10 as their policy version (optionally via `...<max>`) will produce a deprecation warning in CMake 3.31 and above.

Changed in version 3.27: Compatibility with versions of CMake older than 3.5 is deprecated. Calls to `cmake_minimum_required(VERSION)` or `cmake_policy(VERSION)` that do not specify at least 3.5 as their policy version (optionally via `...<max>`) will produce a deprecation warning in CMake 3.27 and above.

Changed in version 3.19: Compatibility with versions of CMake older than 2.8.12 is deprecated. Calls to `cmake_minimum_required(VERSION)` or `cmake_policy(VERSION)` that do not specify at least 2.8.12 as their policy version (optionally via `...<max>`) will produce a deprecation warning in CMake 3.19 and above.

## See Also

- `cmake_policy()`