From 86d910ab73c83a949220ca7f0388f7aa5a32aa3c Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 3 Oct 2023 12:09:23 -0400 Subject: Add deprecation warnings for policies CMP0126 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.21 and below to encourage projects to port away from setting policies to OLD. --- Source/cmMakefile.cxx | 5 +++-- Tests/RunCMake/CMP0126/CMP0126-OLD-stderr.txt | 10 ++++++++++ Tests/RunCMake/CMP0126/CMP0126-OLD_CL-stderr.txt | 10 ++++++++++ Tests/RunCMake/ToolchainFile/CMP0126-OLD-stderr.txt | 13 ++++++++++++- Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake | 2 +- Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake | 2 +- Tests/RunCMake/UseSWIG/CMP0122-OLD-stderr.txt | 10 ++++++++++ Tests/RunCMake/find_file/NO_CACHE-stderr.txt | 10 ++++++++++ Tests/RunCMake/find_library/NO_CACHE-stderr.txt | 10 ++++++++++ Tests/RunCMake/find_path/NO_CACHE-stderr.txt | 10 ++++++++++ Tests/RunCMake/find_program/NO_CACHE-stderr.txt | 10 ++++++++++ .../foreach/foreach-var-scope-CMP0124-OLD-stderr.txt | 10 ++++++++++ 12 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 Tests/RunCMake/CMP0126/CMP0126-OLD-stderr.txt create mode 100644 Tests/RunCMake/CMP0126/CMP0126-OLD_CL-stderr.txt create mode 100644 Tests/RunCMake/UseSWIG/CMP0122-OLD-stderr.txt create mode 100644 Tests/RunCMake/find_file/NO_CACHE-stderr.txt create mode 100644 Tests/RunCMake/find_library/NO_CACHE-stderr.txt create mode 100644 Tests/RunCMake/find_path/NO_CACHE-stderr.txt create mode 100644 Tests/RunCMake/find_program/NO_CACHE-stderr.txt create mode 100644 Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD-stderr.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 80f8a77..40d769d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4630,12 +4630,13 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, } // Deprecate old policies. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0120 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0126 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. id == cmPolicies::CMP0065 || id == cmPolicies::CMP0083 || - id == cmPolicies::CMP0091 || id == cmPolicies::CMP0104)) && + id == cmPolicies::CMP0091 || id == cmPolicies::CMP0104 || + id == cmPolicies::CMP0123 || id == cmPolicies::CMP0126)) && (!this->IsSet("CMAKE_WARN_DEPRECATED") || this->IsOn("CMAKE_WARN_DEPRECATED"))) { this->IssueMessage(MessageType::DEPRECATION_WARNING, diff --git a/Tests/RunCMake/CMP0126/CMP0126-OLD-stderr.txt b/Tests/RunCMake/CMP0126/CMP0126-OLD-stderr.txt new file mode 100644 index 0000000..7d2608b --- /dev/null +++ b/Tests/RunCMake/CMP0126/CMP0126-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0126-OLD\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0126 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/CMP0126/CMP0126-OLD_CL-stderr.txt b/Tests/RunCMake/CMP0126/CMP0126-OLD_CL-stderr.txt new file mode 100644 index 0000000..1f2179c --- /dev/null +++ b/Tests/RunCMake/CMP0126/CMP0126-OLD_CL-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0126-OLD_CL\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0126 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/ToolchainFile/CMP0126-OLD-stderr.txt b/Tests/RunCMake/ToolchainFile/CMP0126-OLD-stderr.txt index f3c068a..efa7b32 100644 --- a/Tests/RunCMake/ToolchainFile/CMP0126-OLD-stderr.txt +++ b/Tests/RunCMake/ToolchainFile/CMP0126-OLD-stderr.txt @@ -1 +1,12 @@ -^try_compile CMP0126='OLD' VAR='2' +^CMake Deprecation Warning at CMP0126-OLD\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0126 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\) ++ +try_compile CMP0126='OLD' VAR='2' diff --git a/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake b/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake index a26c278..df14d15 100644 --- a/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake +++ b/Tests/RunCMake/UseSWIG/CMP0122-NEW-check.cmake @@ -1,5 +1,5 @@ -cmake_policy(VERSION 3.1) +cmake_policy(VERSION 3.5) file(STRINGS "${RunCMake_TEST_BINARY_DIR}/CMP0122-library-name.txt" prefixes) diff --git a/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake b/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake index 01657d0..6eb5c20 100644 --- a/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake +++ b/Tests/RunCMake/UseSWIG/CMP0122-OLD-check.cmake @@ -1,5 +1,5 @@ -cmake_policy(VERSION 3.1) +cmake_policy(VERSION 3.5) file(STRINGS "${RunCMake_TEST_BINARY_DIR}/CMP0122-library-name.txt" prefixes) diff --git a/Tests/RunCMake/UseSWIG/CMP0122-OLD-stderr.txt b/Tests/RunCMake/UseSWIG/CMP0122-OLD-stderr.txt new file mode 100644 index 0000000..84f2ee7 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/CMP0122-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at CMP0122-OLD\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0122 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/find_file/NO_CACHE-stderr.txt b/Tests/RunCMake/find_file/NO_CACHE-stderr.txt new file mode 100644 index 0000000..6da353b --- /dev/null +++ b/Tests/RunCMake/find_file/NO_CACHE-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at NO_CACHE\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0125 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/find_library/NO_CACHE-stderr.txt b/Tests/RunCMake/find_library/NO_CACHE-stderr.txt new file mode 100644 index 0000000..6da353b --- /dev/null +++ b/Tests/RunCMake/find_library/NO_CACHE-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at NO_CACHE\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0125 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/find_path/NO_CACHE-stderr.txt b/Tests/RunCMake/find_path/NO_CACHE-stderr.txt new file mode 100644 index 0000000..6da353b --- /dev/null +++ b/Tests/RunCMake/find_path/NO_CACHE-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at NO_CACHE\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0125 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/find_program/NO_CACHE-stderr.txt b/Tests/RunCMake/find_program/NO_CACHE-stderr.txt new file mode 100644 index 0000000..6da353b --- /dev/null +++ b/Tests/RunCMake/find_program/NO_CACHE-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at NO_CACHE\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0125 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/foreach/foreach-var-scope-CMP0124-OLD-stderr.txt b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD-stderr.txt new file mode 100644 index 0000000..7a49647 --- /dev/null +++ b/Tests/RunCMake/foreach/foreach-var-scope-CMP0124-OLD-stderr.txt @@ -0,0 +1,10 @@ +^CMake Deprecation Warning at foreach-var-scope-CMP0124-OLD\.cmake:[0-9]+ \(cmake_policy\): + The OLD behavior for policy CMP0124 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 c5f1af1ffe38cc235934988a7a0faccec90ff5d9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 3 Oct 2023 12:10:18 -0400 Subject: export: Increase maximum policy version in exported files to 3.27 The files generatd by `install(EXPORT)` and `export()` commands are known to work with policies as of CMake 3.27, 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 dae061b..5668e40 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -956,13 +956,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.26 (this upper limit may be reviewed + // policy settings for up to CMake 3.27 (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.8.3...3.26)\n"; + << "cmake_policy(VERSION 2.8.3...3.27)\n"; /* clang-format on */ } -- cgit v0.12 From be045c7c1659768032a818d4e175180c9293a203 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 3 Oct 2023 12:11:18 -0400 Subject: Configure CMake itself with policies through CMake 3.27 --- CMakeLists.txt | 2 +- Source/Checks/Curses/CMakeLists.txt | 2 +- Utilities/Doxygen/CMakeLists.txt | 2 +- Utilities/Sphinx/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2823ca4..a99cf50 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.13...3.26 FATAL_ERROR) +cmake_minimum_required(VERSION 3.13...3.27 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/Source/Checks/Curses/CMakeLists.txt b/Source/Checks/Curses/CMakeLists.txt index bc6b906..6f5f145 100644 --- a/Source/Checks/Curses/CMakeLists.txt +++ b/Source/Checks/Curses/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.13...3.26 FATAL_ERROR) +cmake_minimum_required(VERSION 3.13...3.27 FATAL_ERROR) project(CheckCurses C) set(CURSES_NEED_NCURSES TRUE) diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index 12b5407..52a31eb 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.13...3.26 FATAL_ERROR) + cmake_minimum_required(VERSION 3.13...3.27 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 694ba3c..4ffcdd7 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.13...3.26 FATAL_ERROR) + cmake_minimum_required(VERSION 3.13...3.27 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