cmake_minimum_required.rst 2.5 KB

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