cmake-方針(7)

簡介

CMake 方針引進了行為變更,同時保留了對現有專案版本的相容性。方針是棄用機制,而非功能開關。每個方針都記載了已棄用的 OLD 行為和偏好的 NEW 行為。專案必須隨著時間更新以使用 NEW 行為,但其現有版本將繼續使用 OLD 行為。

更新專案

When policies are newly introduced by a version of CMake, their OLD behaviors are immediately deprecated by that version of CMake and later. Projects should be updated to use the NEW behaviors of the policies as soon as possible.

使用 cmake_minimum_required() 命令記錄專案已更新的最新 CMake 版本。例如:

cmake_minimum_required(VERSION 3.10...4.2)

This uses the <min>...<max> syntax to enable the NEW behaviors of policies introduced in CMake 4.2 and earlier while only requiring a minimum version of CMake 3.10. The project is expected to work with both the OLD and NEW behaviors of policies introduced between those versions.

Transition Schedule

To help projects port to the NEW behaviors of policies on their own schedule, CMake offers a transition period:

  • If a policy is not set by a project, CMake uses its OLD behavior, but may warn that the policy has not been set.

    • Users running CMake may silence the warning without modifying a project by setting the CMAKE_POLICY_DEFAULT_CMP<NNNN> variable as a cache entry on the cmake(1) command line:

      cmake -DCMAKE_POLICY_DEFAULT_CMP0990=OLD ...
      
    • Projects may silence the warning by using the cmake_policy() command to explicitly set the policy to OLD or NEW behavior:

      if(POLICY CMP0990)
        cmake_policy(SET CMP0990 NEW)
      endif()
      

      備註

      A policy should almost never be set to OLD, except to silence warnings in an otherwise frozen or stable codebase, or temporarily as part of a larger migration path.

  • If a policy is set to OLD by a project, CMake versions released at least 2 years after the version that introduced a policy may issue a warning that the policy's OLD behavior will be removed from a future version of CMake.

  • If a policy is not set to NEW by a project, CMake versions released at least 6 years after the version that introduced a policy, and whose major version number is higher, may issue an error that the policy's OLD behavior has been removed.

支援的方針

The following policies are supported.

CMake 4.2 引進的方針

CMake 4.1 引進的方針

CMake 4.0 引進的方針

CMake 3.31 引進的方針

CMake 3.30 引進的方針

CMake 3.29 引進的方針

CMake 3.28 引進的方針

CMake 3.27 引進的方針

CMake 3.26 引進的方針

CMake 3.25 引進的方針

CMake 3.24 引進的方針

CMake 3.23 引進的方針

CMake 3.22 引進的方針

CMake 3.21 引進的方針

CMake 3.20 引進的方針

CMake 3.19 引進的方針

CMake 3.18 引進的方針

CMake 3.17 引進的方針

CMake 3.16 引進的方針

CMake 3.15 引進的方針

CMake 3.14 引進的方針

CMake 3.13 引進的方針

CMake 3.12 引進的方針

CMake 3.11 引進的方針

CMake 3.10 引進的方針

CMake 3.9 引進的方針

CMake 3.8 引進的方針

CMake 3.7 引進的方針

不支援的方針

The following policies are no longer supported. Projects' calls to cmake_minimum_required(VERSION) or cmake_policy(VERSION) must set them to NEW. Their OLD behaviors have been removed from CMake.

CMake 3.4 引進、CMake 4.0 移除的方針

CMake 3.3 引進、CMake 4.0 移除的方針

CMake 3.2 引進、CMake 4.0 移除的方針

CMake 3.1 引進、CMake 4.0 移除的方針

CMake 3.0 引進、CMake 4.0 移除的方針

CMake 2.8 引進、CMake 4.0 移除的方針

CMake 2.6 引進、CMake 4.0 移除的方針