cmake/Help/command/cmake_minimum_required.rst

89 lines
3.2 KiB
ReStructuredText
Raw Normal View History

2014-08-03 19:52:23 +02:00
cmake_minimum_required
----------------------
2019-11-11 23:01:05 +01:00
Require a minimum version of cmake.
.. code-block:: cmake
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
cmake_minimum_required(VERSION <min>[...<policy_max>] [FATAL_ERROR])
.. versionadded:: 3.12
The optional ``<policy_max>`` version.
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
Sets the minimum required version of cmake for a project.
Also updates the policy settings as explained below.
2021-09-14 00:13:48 +02:00
``<min>`` and the optional ``<policy_max>`` are each CMake versions of the
form ``major.minor[.patch[.tweak]]``, and the ``...`` is literal.
2018-08-09 18:06:22 +02:00
If the running version of CMake is lower than the ``<min>`` required
version it will stop processing the project and report an error.
2021-09-14 00:13:48 +02:00
The optional ``<policy_max>`` version, if specified, must be at least the
``<min>`` version and affects policy settings as described in `Policy Settings`_.
2018-08-09 18:06:22 +02:00
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>``.
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
This command will set the value of the
:variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable to ``<min>``.
2015-11-17 17:22:37 +01:00
The ``FATAL_ERROR`` option is accepted but ignored by CMake 2.6 and
2014-08-03 19:52:23 +02:00
higher. It should be specified so CMake versions 2.4 and lower fail
with an error instead of just a warning.
2015-08-17 11:37:30 +02:00
.. note::
Call the ``cmake_minimum_required()`` command at the beginning of
the top-level ``CMakeLists.txt`` file even before calling the
:command:`project` command. It is important to establish version
and policy settings before invoking other commands whose behavior
they may affect. See also policy :policy:`CMP0000`.
Calling ``cmake_minimum_required()`` inside a :command:`function`
2021-09-14 00:13:48 +02:00
limits some effects to the function scope when invoked. For example,
the :variable:`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 Settings`:
2016-07-09 11:21:54 +02:00
Policy Settings
^^^^^^^^^^^^^^^
The ``cmake_minimum_required(VERSION)`` command implicitly invokes the
:command:`cmake_policy(VERSION)` command to specify that the current
2018-08-09 18:06:22 +02:00
project code is written for the given range of CMake versions.
All policies known to the running version of CMake and introduced
in the ``<min>`` (or ``<max>``, if specified) version or earlier will
be set to use ``NEW`` behavior. All policies introduced in later
versions will be unset. This effectively requests behavior preferred
2016-07-09 11:21:54 +02:00
as of a given CMake version and tells newer CMake versions to warn
about their new policies.
2018-08-09 18:06:22 +02:00
When a ``<min>`` version higher than 2.4 is specified the command
2019-11-11 23:01:05 +01:00
implicitly invokes
.. code-block:: cmake
2016-07-09 11:21:54 +02:00
2018-08-09 18:06:22 +02:00
cmake_policy(VERSION <min>[...<max>])
2016-07-09 11:21:54 +02:00
2018-08-09 18:06:22 +02:00
which sets CMake policies based on the range of versions specified.
When a ``<min>`` version 2.4 or lower is given the command implicitly
2019-11-11 23:01:05 +01:00
invokes
.. code-block:: cmake
2016-07-09 11:21:54 +02:00
2018-08-09 18:06:22 +02:00
cmake_policy(VERSION 2.4[...<max>])
2016-07-09 11:21:54 +02:00
which enables compatibility features for CMake 2.4 and lower.
2023-05-23 16:38:00 +02:00
2023-08-26 19:55:20 +02:00
.. include:: DEPRECATED_POLICY_VERSIONS.txt
2023-05-23 16:38:00 +02:00
See Also
^^^^^^^^
* :command:`cmake_policy`