cmake_minimum_required.rst 2.7 KB

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