cmake-policies.7.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. .. cmake-manual-description: CMake Policies Reference
  2. cmake-policies(7)
  3. *****************
  4. .. only:: html
  5. .. contents::
  6. Introduction
  7. ============
  8. Policies in CMake are used to preserve backward compatible behavior
  9. across multiple releases. When a new policy is introduced, newer CMake
  10. versions will begin to warn about the backward compatible behavior. It
  11. is possible to disable the warning by explicitly requesting the OLD, or
  12. backward compatible behavior using the :command:`cmake_policy` command.
  13. It is also possible to request ``NEW``, or non-backward compatible behavior
  14. for a policy, also avoiding the warning. Each policy can also be set to
  15. either ``NEW`` or ``OLD`` behavior explicitly on the command line with the
  16. :variable:`CMAKE_POLICY_DEFAULT_CMP<NNNN>` variable.
  17. Note that policies are not reliable feature toggles. A policy should
  18. almost never be set to ``OLD``, except to silence warnings in an otherwise
  19. frozen or stable codebase, or temporarily as part of a larger migration
  20. path. The ``OLD`` behavior of each policy is undesirable and will be
  21. replaced with an error condition in a future release.
  22. The :command:`cmake_minimum_required` command does more than report an
  23. error if a too-old version of CMake is used to build a project. It
  24. also sets all policies introduced in that CMake version or earlier to
  25. ``NEW`` behavior. To manage policies without increasing the minimum required
  26. CMake version, the :command:`if(POLICY)` command may be used:
  27. .. code-block:: cmake
  28. if(POLICY CMP0990)
  29. cmake_policy(SET CMP0990 NEW)
  30. endif()
  31. This has the effect of using the ``NEW`` behavior with newer CMake releases which
  32. users may be using and not issuing a compatibility warning.
  33. The setting of a policy is confined in some cases to not propagate to the
  34. parent scope. For example, if the files read by the :command:`include` command
  35. or the :command:`find_package` command contain a use of :command:`cmake_policy`,
  36. that policy setting will not affect the caller by default. Both commands accept
  37. an optional ``NO_POLICY_SCOPE`` keyword to control this behavior.
  38. The :variable:`CMAKE_MINIMUM_REQUIRED_VERSION` variable may also be used
  39. to determine whether to report an error on use of deprecated macros or
  40. functions.
  41. All Policies
  42. ============
  43. .. toctree::
  44. :maxdepth: 1
  45. /policy/CMP0000
  46. /policy/CMP0001
  47. /policy/CMP0002
  48. /policy/CMP0003
  49. /policy/CMP0004
  50. /policy/CMP0005
  51. /policy/CMP0006
  52. /policy/CMP0007
  53. /policy/CMP0008
  54. /policy/CMP0009
  55. /policy/CMP0010
  56. /policy/CMP0011
  57. /policy/CMP0012
  58. /policy/CMP0013
  59. /policy/CMP0014
  60. /policy/CMP0015
  61. /policy/CMP0016
  62. /policy/CMP0017
  63. /policy/CMP0018
  64. /policy/CMP0019
  65. /policy/CMP0020
  66. /policy/CMP0021
  67. /policy/CMP0022
  68. /policy/CMP0023
  69. /policy/CMP0024
  70. /policy/CMP0025
  71. /policy/CMP0026
  72. /policy/CMP0027
  73. /policy/CMP0028
  74. /policy/CMP0029
  75. /policy/CMP0030
  76. /policy/CMP0031
  77. /policy/CMP0032
  78. /policy/CMP0033
  79. /policy/CMP0034
  80. /policy/CMP0035
  81. /policy/CMP0036
  82. /policy/CMP0037
  83. /policy/CMP0038
  84. /policy/CMP0039
  85. /policy/CMP0040
  86. /policy/CMP0041
  87. /policy/CMP0042
  88. /policy/CMP0043
  89. /policy/CMP0044
  90. /policy/CMP0045
  91. /policy/CMP0046
  92. /policy/CMP0047
  93. /policy/CMP0048
  94. /policy/CMP0049
  95. /policy/CMP0050
  96. /policy/CMP0051
  97. /policy/CMP0052
  98. /policy/CMP0053
  99. /policy/CMP0054
  100. /policy/CMP0055
  101. /policy/CMP0056
  102. /policy/CMP0057
  103. /policy/CMP0058
  104. /policy/CMP0059
  105. /policy/CMP0060
  106. /policy/CMP0061
  107. /policy/CMP0062