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 thecmake(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 toOLD
orNEW
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'sOLD
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'sOLD
behavior has been removed.
支援的方針¶
The following policies are supported.
CMake 4.2 引進的方針¶
- CMP0204: A character set is always defined when targeting the MSVC ABI.
- CMP0203: _WINDLL is defined for shared libraries targeting the MSVC ABI.
- CMP0202: PDB file names always include their target's per-config POSTFIX.
- CMP0201: Python::NumPy does not depend on Python::Development.Module.
- CMP0200: Location and configuration selection for imported targets is more consistent.
- CMP0199: $<CONFIG> only matches the configuration of the consumed target.
- CMP0198: CMAKE_PARENT_LIST_FILE is not defined in CMakeLists.txt.
CMake 4.1 引進的方針¶
- CMP0197: MSVC link -machine: flag is not in CMAKE_*_LINKER_FLAGS.
- CMP0196: The CMakeDetermineVSServicePack module is removed.
- CMP0195: Swift modules in build trees use the Swift module directory structure.
- CMP0194: MSVC is not an assembler for language ASM.
- CMP0193:當安裝前綴為 '/' 時,GNUInstallDirs 將 CMAKE_INSTALL_* 快取為以 'usr/' 開頭。
- CMP0192:GNUInstallDirs 在特殊前綴中使用絕對的 SYSCONFDIR、LOCALSTATEDIR 和 RUNSTATEDIR。
- CMP0191:移除 FindCABLE 模組。
- CMP0190: FindPython enforce consistency in cross-compiling mode.
- CMP0189: TARGET_PROPERTY evaluates LINK_LIBRARIES properties transitively.
- CMP0188: The FindGCCXML module is removed.
- CMP0187: Include source file without an extension after the same name with an extension.
- CMP0186: Regular expressions match ^ at most once in repeated searches.
CMake 4.0 引進的方針¶
CMake 3.31 引進的方針¶
- CMP0180: project() always sets <PROJECT-NAME>_* as normal variables.
- CMP0179: De-duplication of static libraries on link lines keeps first occurrence.
- CMP0178: Test command lines preserve empty arguments.
- CMP0177: install() DESTINATION paths are normalized.
- CMP0176: execute_process() ENCODING is UTF-8 by default.
- CMP0175: add_custom_command() rejects invalid arguments.
- CMP0174: cmake_parse_arguments(PARSE_ARGV) defines a variable for an empty string after a single-value keyword.
- CMP0173: The CMakeFindFrameworks module is removed.
- CMP0172: The CPack module enables per-machine installation by default in the CPack WIX Generator.
- CMP0171: 'codegen' is a reserved target name.
CMake 3.30 引進的方針¶
- CMP0170:強制執行 FETCHCONTENT_FULLY_DISCONNECTED 的要求。
- CMP0169:棄用 FetchContent_Populate(depName) 單引數簽章。
- CMP0168: FetchContent implements steps directly instead of through a sub-build.
- CMP0167:移除 FindBoost 模組。
- CMP0166: TARGET_PROPERTY evaluates link properties transitively over private dependencies of static libraries.
- CMP0165:enable_language() 不得在 project() 之前被呼叫。
- CMP0164: add_library() rejects SHARED libraries when not supported by the platform.
- CMP0163: The GENERATED source file property is now visible in all directories.
- CMP0162: Visual Studio generators add UseDebugLibraries indicators by default.
CMake 3.29 引進的方針¶
- CMP0161: CPACK_PRODUCTBUILD_DOMAINS defaults to true.
- CMP0160: More read-only target properties now error when trying to set them.
- CMP0159: file(STRINGS) with REGEX updates CMAKE_MATCH_<n>.
- CMP0158: add_test() honors CMAKE_CROSSCOMPILING_EMULATOR only when cross-compiling.
- CMP0157: Swift compilation mode is selected by an abstraction.
- CMP0156: De-duplicate libraries on link lines based on linker capabilities.
CMake 3.28 引進的方針¶
- CMP0155: C++ sources in targets with at least C++20 are scanned for imports when supported.
- CMP0154: Generated files are private by default in targets using file sets.
- CMP0153: The exec_program command should not be called.
- CMP0152: file(REAL_PATH) resolves symlinks before collapsing ../ components.
CMake 3.27 引進的方針¶
- CMP0151: AUTOMOC include directory is a system include directory by default.
- CMP0150: ExternalProject_Add and FetchContent_Declare treat relative git repository paths as being relative to parent project's remote.
- CMP0149: Visual Studio generators select latest Windows SDK by default.
- CMP0148: The FindPythonInterp and FindPythonLibs modules are removed.
- CMP0147:Visual Studio 生成器會並行建置自訂命令。
- CMP0146:移除 FindCUDA 模組。
- CMP0145: The Dart and FindDart modules are removed.
- CMP0144:find_package 會使用大寫的 PACKAGENAME_ROOT 變數。
CMake 3.26 引進的方針¶
CMake 3.25 引進的方針¶
CMake 3.24 引進的方針¶
- CMP0139: The if() command supports path comparisons using PATH_EQUAL operator.
- CMP0138:CheckIPOSupported 使用來自呼叫專案的旗標。
- CMP0137:try_compile() 在專案模式中傳遞平臺變數。
- CMP0136: Watcom runtime library flags are selected by an abstraction.
- CMP0135: ExternalProject and FetchContent ignore timestamps in archives by default for the URL download method.
- CMP0134: Fallback to "HOST" Windows registry view when "TARGET" view is not usable.
- CMP0133: The CPack module disables SLA by default in the CPack DragNDrop Generator.
- CMP0132:首次執行時不要設定編譯器環境變數。
- CMP0131:LINK_LIBRARIES 支援 LINK_ONLY 生成器表達式。
- CMP0130: while() diagnoses condition evaluation errors.
CMake 3.23 引進的方針¶
CMake 3.22 引進的方針¶
CMake 3.21 引進的方針¶
CMake 3.20 引進的方針¶
- CMP0120:移除 WriteCompilerDetectionHeader 模組。
- CMP0119: LANGUAGE source file property explicitly compiles as language.
- CMP0118: GENERATED sources may be used across directories without manual marking.
- CMP0117: MSVC RTTI flag /GR is not added to CMAKE_CXX_FLAGS by default.
- CMP0116:Ninja 生成器會變換來自 add_custom_command() 的 DEPFILE。
- CMP0115: Source file extensions must be explicit.
CMake 3.19 引進的方針¶
- CMP0114: ExternalProject step targets fully adopt their steps.
- CMP0113: Makefile generators do not repeat custom commands from target dependencies.
- CMP0112: Target file component generator expressions do not add target dependencies.
- CMP0111: An imported target missing its location property fails during generation.
- CMP0110: add_test() supports arbitrary characters in test names.
- CMP0109:find_program() 需要執行權限但不需要讀取權限。
CMake 3.18 引進的方針¶
- CMP0108: A target cannot link to itself through an alias.
- CMP0107: An ALIAS target cannot overwrite another target.
- CMP0106:移除 Documentation 模組。
- CMP0105:裝置連結階段使用連結選項。
- CMP0104: CMAKE_CUDA_ARCHITECTURES now detected for NVCC, empty CUDA_ARCHITECTURES not allowed.
- CMP0103: Multiple export() with same FILE without APPEND is not allowed.
CMake 3.17 引進的方針¶
- CMP0102: mark_as_advanced() does nothing if a cache entry does not exist.
- CMP0101: target_compile_options honors BEFORE keyword in all scopes.
- CMP0100:讓 AUTOMOC 和 AUTOUIC 處理 .hh 標頭檔。
- CMP0099: Link properties are transitive over private dependencies of static libraries.
- CMP0098: FindFLEX runs flex in CMAKE_CURRENT_BINARY_DIR when executing.
CMake 3.16 引進的方針¶
CMake 3.15 引進的方針¶
- CMP0094:FindPython3、FindPython2 和 FindPython 會使用查找策略的 LOCATION。
- CMP0093:FindBoost 以 x.y.z 格式回報 Boost_VERSION。
- CMP0092:MSVC 警告旗標預設不在 CMAKE_{C,CXX}_FLAGS 中。
- CMP0091: MSVC runtime library flags are selected by an abstraction.
- CMP0090:export(PACKAGE) 預設不會填寫軟體包註冊表。
- CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang.
CMake 3.14 引進的方針¶
- CMP0088: FindBISON runs bison in CMAKE_CURRENT_BINARY_DIR when executing.
- CMP0087:install(SCRIPT | CODE) 支援生成器表達式。
- CMP0086: UseSWIG honors SWIG_MODULE_NAME via -module flag.
- CMP0085:IN_LIST 生成器表達式會處理空列表項目。
- CMP0084:find_package() 找不到 FindQt 模組。
- CMP0083:在連結執行檔時增添 PIE 選項。
- CMP0082: Install rules from add_subdirectory() are interleaved with those in caller.
CMake 3.13 引進的方針¶
- CMP0081: Relative paths not allowed in LINK_DIRECTORIES target property.
- CMP0080: BundleUtilities cannot be included at configure time.
- CMP0079: target_link_libraries allows use with targets in other directories.
- CMP0078: UseSWIG generates standard target names.
- CMP0077: option() honors normal variables.
- CMP0076: target_sources() command converts relative paths to absolute.
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 移除的方針¶
- CMP0063: Honor visibility properties for all target types.
- CMP0062: Disallow install() of export() result.
- CMP0061:CTest 預設不會告訴 make 忽略錯誤(-i)。
- CMP0060: Link libraries by full path even in implicit directories.
- CMP0059:不要將 DEFINITIONS 視為內建的目錄屬性。
- CMP0058: Ninja requires custom command byproducts to be explicit.
- CMP0057:支援新的 IN_LIST if() 運算子。
CMake 3.2 引進、CMake 4.0 移除的方針¶
CMake 3.1 引進、CMake 4.0 移除的方針¶
CMake 3.0 引進、CMake 4.0 移除的方針¶
- CMP0050:不允許 add_custom_command 的 SOURCE 簽章。
- CMP0049:不要在目標來源條目中展開變數。
- CMP0048:project() 命令管理 VERSION 變數。
- CMP0047: Use QCC compiler id for the qcc drivers on QNX.
- CMP0046: Error on non-existent dependency in add_dependencies.
- CMP0045: Error on non-existent target in get_target_property.
- CMP0044:區分大小寫的 Lang_COMPILER_ID 生成器表達式。
- CMP0043:忽略 COMPILE_DEFINITIONS_Config 屬性。
- CMP0042:預設啟用 MACOSX_RPATH。
- CMP0041: Error on relative include with generator expression.
- CMP0040:add_custom_command() 的 TARGET 簽名中的目標必須存在。
- CMP0039: Utility targets may not have link dependencies.
- CMP0038: Targets may not link directly to themselves.
- CMP0037: Target names should not be reserved and should match a validity pattern.
- CMP0036:不應該呼叫 build_name 命令。
- CMP0035:不應該呼叫 variable_requires 命令。
- CMP0034:不應該 utility_source 命令。
- CMP0033:不應該呼叫 export_library_dependencies 命令。
- CMP0032:不應該呼叫 output_required_files 命令。
- CMP0031:不應該呼叫 load_command 命令。
- CMP0030:不應該呼叫 use_mangled_mesa 命令。
- CMP0029: The subdir_depends command should not be called.
- CMP0028: Double colon in target name means ALIAS or IMPORTED target.
- CMP0027: Conditionally linked imported targets with missing include directories.
- CMP0026: Disallow use of the LOCATION target property.
- CMP0025: Compiler id for Apple Clang is now AppleClang.
- CMP0024:不允許引入匯出結果。
CMake 2.8 引進、CMake 4.0 移除的方針¶
- CMP0023: Plain and keyword target_link_libraries signatures cannot be mixed.
- CMP0022:INTERFACE_LINK_LIBRARIES 定義連結介面。
- CMP0021: Fatal error on relative paths in INCLUDE_DIRECTORIES target property.
- CMP0020:在 Windows 上自動將 Qt 執行檔連結到 qtmain 目標。
- CMP0019: Do not re-expand variables in include and link information.
- CMP0018:忽略 CMAKE_SHARED_LIBRARY_Lang_FLAGS 變數。
- CMP0017: Prefer files from the CMake module directory when including from there.
- CMP0016:若 target_link_libraries() 唯一的引數不是目標,則回報錯誤。
- CMP0015:link_directories() 會處理相對於來源目錄的路徑。
- CMP0014:輸入目錄中必須有 CMakeLists.txt。
- CMP0013:不允許重複的二進位目錄。
- CMP0012:if() 會識別數字和布林常數。
CMake 2.6 引進、CMake 4.0 移除的方針¶
- CMP0011: Included scripts do automatic cmake_policy PUSH and POP.
- CMP0010:不正確的變數參照語法是一個錯誤。
- CMP0009: FILE GLOB_RECURSE calls should not follow symlinks by default.
- CMP0008: Libraries linked by full-path must have a valid library file name.
- CMP0007:list 命令不再忽略空元素。
- CMP0006:安裝 MACOSX_BUNDLE 目標要求指定 BUNDLE DESTINATION。
- CMP0005: Preprocessor definition values are now escaped automatically.
- CMP0004:連結的程式庫名稱不得含有前導或後隨空白。
- CMP0003:以完整路徑連結的程式庫不再產生連結器的搜尋路徑。
- CMP0002:邏輯目標名稱必須在全域中唯一。
- CMP0001:不應再使用 CMAKE_BACKWARDS_COMPATIBILITY。
- CMP0000:必須指定最低要求的 CMake 版本。