From 9c5e981e607fdab1f7982c2ea555d69b3dca027f Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 6 Feb 2024 16:49:14 -0500 Subject: Add deprecation warnings for policies CMP0128 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.22 and below to encourage projects to port away from setting policies to OLD. --- Source/cmMakefile.cxx | 5 +++-- .../CMakeDependentOption/Regex-CMP0127-OLD-stderr.txt | 9 +++++++++ Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt | 11 +++++++++++ Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/CMakeDependentOption/Regex-CMP0127-OLD-stderr.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 509f28b..cfaac11 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4657,13 +4657,14 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, } // Deprecate old policies. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0126 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0128 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. id == cmPolicies::CMP0065 || id == cmPolicies::CMP0083 || id == cmPolicies::CMP0091 || id == cmPolicies::CMP0104 || - id == cmPolicies::CMP0123 || id == cmPolicies::CMP0126)) && + id == cmPolicies::CMP0123 || id == cmPolicies::CMP0126 || + id == cmPolicies::CMP0128)) && (!this->IsSet("CMAKE_WARN_DEPRECATED") || this->IsOn("CMAKE_WARN_DEPRECATED"))) { this->IssueMessage(MessageType::DEPRECATION_WARNING, diff --git a/Tests/RunCMake/CMakeDependentOption/Regex-CMP0127-OLD-stderr.txt b/Tests/RunCMake/CMakeDependentOption/Regex-CMP0127-OLD-stderr.txt new file mode 100644 index 0000000..1953091 --- /dev/null +++ b/Tests/RunCMake/CMakeDependentOption/Regex-CMP0127-OLD-stderr.txt @@ -0,0 +1,9 @@ +^CMake Deprecation Warning at [^ +]*/Tests/RunCMake/CMakeDependentOption/Regex-CMP0127-OLD\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0127 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\.$ diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt index 320c2ba..4b3774f 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnMatch-stderr.txt @@ -1,3 +1,14 @@ +^CMake Deprecation Warning at CMP0128WarnMatch-(C|CXX)\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0128 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\) ++ CMake Warning \(dev\) in CMakeLists\.txt: Policy CMP0128 is not set: Selection of language standard and extension flags improved\. Run "cmake --help-policy CMP0128" for policy details\. Use diff --git a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt index 068cba9..37a0767 100644 --- a/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt +++ b/Tests/RunCMake/CompileFeatures/CMP0128WarnUnset-stderr.txt @@ -1,3 +1,14 @@ +^CMake Deprecation Warning at CMP0128WarnUnset-(C|CXX)\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0128 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\) ++ CMake Warning \(dev\) in CMakeLists\.txt: Policy CMP0128 is not set: Selection of language standard and extension flags improved\. Run "cmake --help-policy CMP0128" for policy details\. Use -- cgit v0.12