From a9ffded98cb0a8cdfe95bd21069de215810c0b6f Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 3 Feb 2022 10:36:37 -0500 Subject: Add deprecation warnings for policies CMP0097 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.16 and below to encourage projects to port away from setting policies to OLD. --- Source/cmMakefile.cxx | 6 ++++-- Tests/ExternalProject/CMakeLists.txt | 2 ++ .../TARGETS-FILE_RPATH_CHANGE-new_rpath-stderr.txt | 18 +++++++++++++++--- Tests/RunCMake/project/CMP0096-OLD-stderr.txt | 10 ++++++++++ Tests/RunCMake/project/VersionMax-stderr.txt | 10 ++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/project/CMP0096-OLD-stderr.txt create mode 100644 Tests/RunCMake/project/VersionMax-stderr.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 68e61bb..4b1635b 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4395,12 +4395,14 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, } // Deprecate old policies. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0094 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0097 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. id == cmPolicies::CMP0065 || id == cmPolicies::CMP0083 || - id == cmPolicies::CMP0091))) { + id == cmPolicies::CMP0091)) && + (!this->IsSet("CMAKE_WARN_DEPRECATED") || + this->IsOn("CMAKE_WARN_DEPRECATED"))) { this->IssueMessage(MessageType::DEPRECATION_WARNING, cmPolicies::GetPolicyDeprecatedWarning(id)); } diff --git a/Tests/ExternalProject/CMakeLists.txt b/Tests/ExternalProject/CMakeLists.txt index 59e3bcc..8a85045 100644 --- a/Tests/ExternalProject/CMakeLists.txt +++ b/Tests/ExternalProject/CMakeLists.txt @@ -444,7 +444,9 @@ if(do_git_tests) set_property(TARGET ${proj} PROPERTY FOLDER "GIT") set(proj TS1-GIT-all-GIT_SUBMODULES-via-CMP0097-OLD) + set(CMAKE_WARN_DEPRECATED FALSE) # we are testing CMP0097 OLD behavior cmake_policy(SET CMP0097 OLD) + unset(CMAKE_WARN_DEPRECATED) ExternalProject_Add(${proj} GIT_REPOSITORY "${local_git_repo}" GIT_SUBMODULES "" diff --git a/Tests/RunCMake/install/TARGETS-FILE_RPATH_CHANGE-new_rpath-stderr.txt b/Tests/RunCMake/install/TARGETS-FILE_RPATH_CHANGE-new_rpath-stderr.txt index 2561263..8b0970a 100644 --- a/Tests/RunCMake/install/TARGETS-FILE_RPATH_CHANGE-new_rpath-stderr.txt +++ b/Tests/RunCMake/install/TARGETS-FILE_RPATH_CHANGE-new_rpath-stderr.txt @@ -1,3 +1,15 @@ +^CMake Deprecation Warning at TARGETS-FILE_RPATH_CHANGE-new_rpath.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0095 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\): + TARGETS-FILE_RPATH_CHANGE-new_rpath.cmake:[0-9]+ \(A_CMP0095\) + CMakeLists.txt:[0-9]+ \(include\)( ++ CMake Warning \(dev\) at TARGETS-FILE_RPATH_CHANGE-new_rpath\.cmake:[0-9]+ \(install\): Policy CMP0095 is not set: RPATH entries are properly escaped in the intermediary CMake install script\. Run "cmake --help-policy CMP0095" for @@ -8,8 +20,8 @@ CMake Warning \(dev\) at TARGETS-FILE_RPATH_CHANGE-new_rpath\.cmake:[0-9]+ \(ins intermediary cmake_install\.cmake script\. Call Stack \(most recent call first\): 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 Warning \(dev\) at TARGETS-FILE_RPATH_CHANGE-new_rpath\.cmake:[0-9]+ \(install\): Policy CMP0095 is not set: RPATH entries are properly escaped in the intermediary CMake install script\. Run "cmake --help-policy CMP0095" for @@ -20,4 +32,4 @@ CMake Warning \(dev\) at TARGETS-FILE_RPATH_CHANGE-new_rpath\.cmake:[0-9]+ \(ins intermediary cmake_install\.cmake script\. Call Stack \(most recent call first\): 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\.)+$ diff --git a/Tests/RunCMake/project/CMP0096-OLD-stderr.txt b/Tests/RunCMake/project/CMP0096-OLD-stderr.txt new file mode 100644 index 0000000..beb7a84 --- /dev/null +++ b/Tests/RunCMake/project/CMP0096-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0096-OLD.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0096 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\)$ diff --git a/Tests/RunCMake/project/VersionMax-stderr.txt b/Tests/RunCMake/project/VersionMax-stderr.txt new file mode 100644 index 0000000..b789640 --- /dev/null +++ b/Tests/RunCMake/project/VersionMax-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at VersionMax.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0096 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\)$ -- cgit v0.12 From a5a9687799ae8a591e4537c9b73718045c709778 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 3 Feb 2022 10:38:21 -0500 Subject: export: Increase maximum policy version in exported files to 3.22 The files generatd by `install(EXPORT)` and `export()` commands are known to work with policies as of CMake 3.22, so enable them in sufficiently new CMake versions. --- Source/cmExportFileGenerator.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 412d104..bb0229f 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -933,13 +933,13 @@ void cmExportFileGenerator::GeneratePolicyHeaderCode(std::ostream& os) // Isolate the file policy level. // Support CMake versions as far back as 2.6 but also support using NEW - // policy settings for up to CMake 3.21 (this upper limit may be reviewed + // policy settings for up to CMake 3.22 (this upper limit may be reviewed // and increased from time to time). This reduces the opportunity for CMake // warnings when an older export file is later used with newer CMake // versions. /* clang-format off */ os << "cmake_policy(PUSH)\n" - << "cmake_policy(VERSION 2.6...3.21)\n"; + << "cmake_policy(VERSION 2.6...3.22)\n"; /* clang-format on */ } -- cgit v0.12 From 9a48012f93376cefe94f1e61260ebbb1e1c2fed6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 3 Feb 2022 10:39:32 -0500 Subject: Configure CMake itself with policies through CMake 3.22 --- CMakeLists.txt | 2 +- Utilities/Doxygen/CMakeLists.txt | 2 +- Utilities/Sphinx/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2ab30e..ffb93b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. -cmake_minimum_required(VERSION 3.1...3.21 FATAL_ERROR) +cmake_minimum_required(VERSION 3.1...3.22 FATAL_ERROR) set(CMAKE_USER_MAKE_RULES_OVERRIDE_C ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideC.cmake) set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/Source/Modules/OverrideCXX.cmake) diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index 72cfc05..d32947b 100644 --- a/Utilities/Doxygen/CMakeLists.txt +++ b/Utilities/Doxygen/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT CMake_SOURCE_DIR) set(CMakeDeveloperReference_STANDALONE 1) - cmake_minimum_required(VERSION 3.1...3.21 FATAL_ERROR) + cmake_minimum_required(VERSION 3.1...3.22 FATAL_ERROR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) diff --git a/Utilities/Sphinx/CMakeLists.txt b/Utilities/Sphinx/CMakeLists.txt index 073e5ff..b8b244d 100644 --- a/Utilities/Sphinx/CMakeLists.txt +++ b/Utilities/Sphinx/CMakeLists.txt @@ -3,7 +3,7 @@ if(NOT CMake_SOURCE_DIR) set(CMakeHelp_STANDALONE 1) - cmake_minimum_required(VERSION 3.1...3.21 FATAL_ERROR) + cmake_minimum_required(VERSION 3.1...3.22 FATAL_ERROR) get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH) get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH) include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake) -- cgit v0.12