cmake_minimum_required.rst 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 behavior; ignored in older CMake.
  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 sets the `Policy Version`_.
  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. For example,
  33. the :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable won't be set
  34. in the calling scope. Functions do not introduce their own policy
  35. scope though, so policy settings of the caller *will* be affected
  36. (see below). Due to this mix of things that do and do not affect the
  37. calling scope, calling ``cmake_minimum_required()`` inside a function
  38. is generally discouraged.
  39. .. _`Policy Version`:
  40. Policy Version
  41. ^^^^^^^^^^^^^^
  42. ``cmake_minimum_required(VERSION <min>[...<max>])`` implicitly invokes
  43. .. code-block:: cmake
  44. cmake_policy(VERSION <min>[...<max>])
  45. .. include:: include/POLICY_VERSION.rst
  46. .. include:: include/DEPRECATED_POLICY_VERSIONS.rst
  47. See Also
  48. ^^^^^^^^
  49. * :command:`cmake_policy`