cmake_minimum_required.rst 2.8 KB

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