Add deprecation warnings for policies CMP0151 and below

The OLD behaviors of all policies are deprecated, but only by
documentation.  Add an explicit deprecation diagnostic for policies
introduced in CMake 3.27 and below to encourage projects to port
away from setting policies to OLD.
This commit is contained in:
Brad King
2025-12-17 19:38:59 -05:00
parent 12be5c60ff
commit 8a7657cf87
20 changed files with 213 additions and 5 deletions

View File

@@ -4085,7 +4085,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
}
// Deprecate old policies.
if (status == cmPolicies::OLD && id <= cmPolicies::CMP0143 &&
if (status == cmPolicies::OLD && id <= cmPolicies::CMP0151 &&
!(this->GetCMakeInstance()->GetIsInTryCompile() &&
(
// Policies set by cmCoreTryCompile::TryCompileCode.

View File

@@ -102,7 +102,9 @@ if (DEFINED with_qt_version)
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0151-old-build)
set(RunCMake_TEST_EXPECT_stderr ".") # ignore CMP0151 deprecation warnings
run_cmake_with_options(CMP0151-old ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=OLD)
unset(RunCMake_TEST_EXPECT_stderr)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout}")
run_cmake_command(CMP0151-old-build ${CMAKE_COMMAND} --build . --config Debug --verbose)
@@ -119,7 +121,9 @@ if (DEFINED with_qt_version)
if (RunCMake_GENERATOR MATCHES "(Ninja|Makefiles|Visual Studio)")
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0151Short-old-build)
set(RunCMake_TEST_EXPECT_stderr ".") # ignore CMP0151 deprecation warnings
run_cmake_with_options(CMP0151Short-old ${RunCMake_TEST_OPTIONS} -DCMAKE_AUTO${autogen_type}=ON -DCMAKE_POLICY_DEFAULT_CMP0151=OLD)
unset(RunCMake_TEST_EXPECT_stderr)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_EXPECT_stdout "${test_expect_stdout_short}")
run_cmake_command(CMP0151Short-old-build ${CMAKE_COMMAND} --build . --config Debug --verbose)

View File

@@ -0,0 +1,9 @@
^CMake Deprecation Warning at ([^
]*/Tests/RunCMake/CMP0150/)?OLD-build/Top/CMakeLists\.txt:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0150 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.$

View File

@@ -0,0 +1,23 @@
^CMake Deprecation Warning at CMP0145-Dart-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0145 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:5 \(include\)
+
CMake Deprecation Warning at [^
]*/Modules/Dart\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0145 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMP0145-Dart-OLD\.cmake:3 \(include\)
CMakeLists\.txt:5 \(include\)$

View File

@@ -15,4 +15,17 @@ CMake Warning \(dev\) at [^
Call Stack \(most recent call first\):
CMP0145-Dart-WARN\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-dev to suppress it\.$
This warning is for project developers\. Use -Wno-dev to suppress it\.
+
CMake Deprecation Warning at [^
]*/Modules/Dart\.cmake:[0-9]+6 \(cmake_policy\):
The OLD behavior for policy CMP0145 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMP0145-Dart-WARN\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0145-FindDart-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0145 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -105,7 +105,9 @@ if("${RunCMake_GENERATOR}" MATCHES "^Visual Studio (1[45678])( 20[0-9][0-9])?$")
endforeach()
foreach(expect_version IN LISTS kits)
set(RunCMake_TEST_VARIANT_DESCRIPTION "-CMP0149-OLD-${expect_version}")
set(RunCMake_TEST_EXPECT_stderr ".") # ignore CMP0149 deprecation warnings
run_cmake_with_options(VersionExists -DCMAKE_SYSTEM_VERSION=${expect_version} -DCMAKE_POLICY_DEFAULT_CMP0149=OLD)
unset(RunCMake_TEST_EXPECT_stderr)
endforeach()
if(kits MATCHES "(^|;)([0-9.]+)$")
set(expect_version "${CMAKE_MATCH_2}")

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CustomCommandParallelDisable\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0147 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -1,4 +1,15 @@
^----------
^CMake Deprecation Warning at CMP0144-OLD-CaseInsensitive\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0144 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
+
----------
FOO_ROOT : ''
ENV{FOO_ROOT}: ''

View File

@@ -1,4 +1,15 @@
^----------
^CMake Deprecation Warning at CMP0144-OLD-CaseSensitive\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0144 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)
+
----------
FOO_ROOT : ''
ENV{FOO_ROOT}: ''

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0145-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0145 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0146-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0146 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -1,4 +1,16 @@
^CMake Error at [^
^CMake Deprecation Warning at CMP0147-common\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0146 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMP0147-NEW\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
+
CMake Error at [^
]*/Modules/FindCUDA\.cmake:[0-9]+ \(message\):
The FindCUDA module does not work in Visual Studio with policy CMP0147\.
Call Stack \(most recent call first\):

View File

@@ -0,0 +1,22 @@
^CMake Deprecation Warning at CMP0147-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0147 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:3 \(include\)
+
CMake Deprecation Warning at CMP0147-common\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0146 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMP0147-OLD\.cmake:2 \(include\)
CMakeLists\.txt:3 \(include\)$

View File

@@ -0,0 +1,11 @@
^CMake Deprecation Warning at CMP0147-common\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0146 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMP0147-WARN\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0148-Interp-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0148 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0148-Libs-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0148 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0146-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0146 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0148-Interp-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0148 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$

View File

@@ -0,0 +1,10 @@
^CMake Deprecation Warning at CMP0148-Libs-OLD\.cmake:[0-9]+ \(cmake_policy\):
The OLD behavior for policy CMP0148 will be removed from a future version
of CMake\.
The cmake-policies\(7\) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances\. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD\.
Call Stack \(most recent call first\):
CMakeLists\.txt:[0-9]+ \(include\)$