From 94ff184a6319e1216f93920c4c2792000d58317f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Jul 2025 09:35:13 -0400 Subject: [PATCH 1/3] Add deprecation warnings for policies CMP0143 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.26 and below to encourage projects to port away from setting policies to OLD. --- Source/cmMakefile.cxx | 2 +- Tests/RunCMake/VSSolution/CMP0143-OLD-stderr.txt | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/VSSolution/CMP0143-OLD-stderr.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 786ef74744..2b60760e3a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4077,7 +4077,7 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id, } // Deprecate old policies. - if (status == cmPolicies::OLD && id <= cmPolicies::CMP0142 && + if (status == cmPolicies::OLD && id <= cmPolicies::CMP0143 && !(this->GetCMakeInstance()->GetIsInTryCompile() && ( // Policies set by cmCoreTryCompile::TryCompileCode. diff --git a/Tests/RunCMake/VSSolution/CMP0143-OLD-stderr.txt b/Tests/RunCMake/VSSolution/CMP0143-OLD-stderr.txt new file mode 100644 index 0000000000..ea6ac868a3 --- /dev/null +++ b/Tests/RunCMake/VSSolution/CMP0143-OLD-stderr.txt @@ -0,0 +1,8 @@ +^CMake Deprecation Warning at CMakeLists\.txt:[0-9]+ \(cmake_minimum_required\): + The OLD behavior for policy CMP0143 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\.$ From f7380d8c4ab77f1300870f795ac7cada4b800990 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Jul 2025 09:41:30 -0400 Subject: [PATCH 2/3] export: Increase maximum policy version in exported files to 4.0 The files generated by `install(EXPORT)`, `export()`, and `install_jar_exports()` commands are known to work with policies as of CMake 4.0, so enable them in sufficiently new CMake versions. --- Modules/UseJava/javaTargets.cmake.in | 2 +- Source/cmExportCMakeConfigGenerator.cxx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/UseJava/javaTargets.cmake.in b/Modules/UseJava/javaTargets.cmake.in index 4aa6560d78..68643c4434 100644 --- a/Modules/UseJava/javaTargets.cmake.in +++ b/Modules/UseJava/javaTargets.cmake.in @@ -1,5 +1,5 @@ cmake_policy(PUSH) -cmake_policy(VERSION 2.8.12...3.31) +cmake_policy(VERSION 2.8.12...4.0) #---------------------------------------------------------------- # Generated CMake Java target import file. diff --git a/Source/cmExportCMakeConfigGenerator.cxx b/Source/cmExportCMakeConfigGenerator.cxx index ce9610a1a0..4d26d358a1 100644 --- a/Source/cmExportCMakeConfigGenerator.cxx +++ b/Source/cmExportCMakeConfigGenerator.cxx @@ -173,7 +173,7 @@ void cmExportCMakeConfigGenerator::GeneratePolicyHeaderCode(std::ostream& os) // Isolate the file policy level. // Support CMake versions as far back as the // RequiredCMakeVersion{Major,Minor,Patch}, but also support using NEW - // policy settings for up to CMake 3.31 (this upper limit may be reviewed + // policy settings for up to CMake 4.0 (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. @@ -182,7 +182,7 @@ void cmExportCMakeConfigGenerator::GeneratePolicyHeaderCode(std::ostream& os) "cmake_policy(VERSION " << this->RequiredCMakeVersionMajor << '.' << this->RequiredCMakeVersionMinor << '.' - << this->RequiredCMakeVersionPatch << "...3.31)\n"; + << this->RequiredCMakeVersionPatch << "...4.0)\n"; /* clang-format on */ } From 8071304f2e3a900291983940505d6276f4078c4c Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Jul 2025 09:42:26 -0400 Subject: [PATCH 3/3] Configure CMake itself with policies through CMake 4.0 --- 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 cab0fcba38..19e2425f8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file LICENSE.rst or https://cmake.org/licensing for details. -cmake_minimum_required(VERSION 3.13...3.31 FATAL_ERROR) +cmake_minimum_required(VERSION 3.13...4.0 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 b0740686f9..ed62602bc9 100644 --- a/Source/Checks/Curses/CMakeLists.txt +++ b/Source/Checks/Curses/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.13...3.31 FATAL_ERROR) +cmake_minimum_required(VERSION 3.13...4.0 FATAL_ERROR) project(CheckCurses C) set(CURSES_NEED_NCURSES TRUE) diff --git a/Utilities/Doxygen/CMakeLists.txt b/Utilities/Doxygen/CMakeLists.txt index 68918f101e..22712b71ab 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.31 FATAL_ERROR) + cmake_minimum_required(VERSION 3.13...4.0 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 c89d412421..e3ff6453a1 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.31 FATAL_ERROR) + cmake_minimum_required(VERSION 3.13...4.0 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)