1cmake_minimum_required
2----------------------
3
4Require a minimum version of cmake.
5
6.. code-block:: cmake
7
8  cmake_minimum_required(VERSION <min>[...<policy_max>] [FATAL_ERROR])
9
10.. versionadded:: 3.12
11  The optional ``<policy_max>`` version.
12
13Sets the minimum required version of cmake for a project.
14Also updates the policy settings as explained below.
15
16``<min>`` and the optional ``<policy_max>`` are each CMake versions of the
17form ``major.minor[.patch[.tweak]]``, and the ``...`` is literal.
18
19If the running version of CMake is lower than the ``<min>`` required
20version it will stop processing the project and report an error.
21The optional ``<policy_max>`` version, if specified, must be at least the
22``<min>`` version and affects policy settings as described in `Policy Settings`_.
23If the running version of CMake is older than 3.12, the extra ``...``
24dots will be seen as version component separators, resulting in the
25``...<max>`` part being ignored and preserving the pre-3.12 behavior
26of basing policies on ``<min>``.
27
28This command will set the value of the
29:variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable to ``<min>``.
30
31The ``FATAL_ERROR`` option is accepted but ignored by CMake 2.6 and
32higher.  It should be specified so CMake versions 2.4 and lower fail
33with an error instead of just a warning.
34
35.. note::
36  Call the ``cmake_minimum_required()`` command at the beginning of
37  the top-level ``CMakeLists.txt`` file even before calling the
38  :command:`project` command.  It is important to establish version
39  and policy settings before invoking other commands whose behavior
40  they may affect.  See also policy :policy:`CMP0000`.
41
42  Calling ``cmake_minimum_required()`` inside a :command:`function`
43  limits some effects to the function scope when invoked.  For example,
44  the :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable won't be set
45  in the calling scope.  Functions do not introduce their own policy
46  scope though, so policy settings of the caller *will* be affected
47  (see below).  Due to this mix of things that do and do not affect the
48  calling scope, calling ``cmake_minimum_required()`` inside a function
49  is generally discouraged.
50
51.. _`Policy Settings`:
52
53Policy Settings
54^^^^^^^^^^^^^^^
55
56The ``cmake_minimum_required(VERSION)`` command implicitly invokes the
57:command:`cmake_policy(VERSION)` command to specify that the current
58project code is written for the given range of CMake versions.
59All policies known to the running version of CMake and introduced
60in the ``<min>`` (or ``<max>``, if specified) version or earlier will
61be set to use ``NEW`` behavior.  All policies introduced in later
62versions will be unset.  This effectively requests behavior preferred
63as of a given CMake version and tells newer CMake versions to warn
64about their new policies.
65
66When a ``<min>`` version higher than 2.4 is specified the command
67implicitly invokes
68
69.. code-block:: cmake
70
71  cmake_policy(VERSION <min>[...<max>])
72
73which sets CMake policies based on the range of versions specified.
74When a ``<min>`` version 2.4 or lower is given the command implicitly
75invokes
76
77.. code-block:: cmake
78
79  cmake_policy(VERSION 2.4[...<max>])
80
81which enables compatibility features for CMake 2.4 and lower.
82