Browse Source

Remove compatibility with CMake versions older than 2.8.0

This compatibility has been deprecated since commit 5845c218d7
(Deprecate compatibility with CMake versions older than 2.8.12,
2020-06-12, v3.19.0-rc1~629^2).  The behavior itself has been
deprecated since CMake 2.8.0.

Issue: #26613
Brad King 1 year ago
parent
commit
785523a136

+ 8 - 0
Help/command/DEPRECATED_POLICY_VERSIONS.txt

@@ -1,3 +1,11 @@
+.. versionchanged:: 4.0
+
+  Compatibility with versions of CMake older than 2.8.0 is removed.
+  Calls to :command:`cmake_minimum_required(VERSION)` or
+  :command:`cmake_policy(VERSION)` that do not specify at least
+  2.8.0 as their policy version (optionally via ``...<max>``)
+  will produce an error in CMake 4.0 and above.
+
 .. versionchanged:: 3.31
 
   Compatibility with versions of CMake older than 3.10 is deprecated.

+ 10 - 0
Help/release/dev/remove-old-compatibility.rst

@@ -0,0 +1,10 @@
+remove-old-compatibility
+------------------------
+
+* Compatibility with versions of CMake older than 2.8.0 has been removed.
+  Calls to :command:`cmake_minimum_required` or :command:`cmake_policy`
+  that set the policy version to an older value now issue an error.
+  Note that calls to those commands can still support older versions of
+  CMake by using their ``VERSION`` arguments' ``<min>...<max>`` syntax.
+  This requires only the ``<min>`` version of CMake, but when running a
+  newer version, sets policies up to the ``<max>`` version.

+ 1 - 1
Source/cmMakefile.cxx

@@ -1744,7 +1744,7 @@ void cmMakefile::Configure()
         this->SetCheckCMP0000(true);
 
         // Implicitly set the version for the user.
-        cmPolicies::ApplyPolicyVersion(this, 2, 4, 0,
+        cmPolicies::ApplyPolicyVersion(this, 2, 8, 0,
                                        cmPolicies::WarnCompat::Off);
       }
     }

+ 16 - 4
Source/cmPolicies.cxx

@@ -294,12 +294,24 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
                                     unsigned int patchVer,
                                     WarnCompat warnCompat)
 {
-  // Warn about policy versions for which support will be removed.
-  if (warnCompat == WarnCompat::On &&
-      (majorVer < 3 || (majorVer == 3 && minorVer < 10)) &&
+  // Error on policy versions for which support has been removed.
+  if (majorVer < 2 || (majorVer == 2 && minorVer < 8)) {
+    if (IsFromLegacyInstallEXPORT(mf, majorVer, minorVer, patchVer)) {
       // Silently tolerate cmake_policy calls generated by install(EXPORT)
       // in CMake versions prior to 3.18.
-      !IsFromLegacyInstallEXPORT(mf, majorVer, minorVer, patchVer)) {
+      majorVer = 2;
+      minorVer = 8;
+      patchVer = 0;
+    } else {
+      mf->IssueMessage(MessageType::FATAL_ERROR,
+                       "Compatibility with CMake < 2.8.0 has been removed "
+                       "from CMake.\n" ADVICE_UPDATE_VERSION_ARGUMENT);
+      cmSystemTools::SetFatalErrorOccurred();
+      return false;
+    }
+  } else if ((majorVer < 3 || (majorVer == 3 && minorVer < 10)) &&
+             warnCompat == WarnCompat::On) {
+    // Warn about policy versions for which support will be removed.
     mf->IssueMessage(
       MessageType::DEPRECATION_WARNING,
       "Compatibility with CMake < 3.10 will be removed from "

+ 0 - 5
Tests/RunCMake/cmake_minimum_required/Before24-stderr.txt

@@ -1,5 +0,0 @@
-CMake Warning \(dev\) at Before24.cmake:1 \(cmake_minimum_required\):
-  Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.

+ 0 - 1
Tests/RunCMake/cmake_minimum_required/Before24.cmake

@@ -1 +0,0 @@
-cmake_minimum_required(VERSION 2.2)

+ 1 - 11
Tests/RunCMake/cmake_minimum_required/BeforeVersionDeprecated-stderr.txt

@@ -8,17 +8,7 @@
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
 +
-CMake Deprecation Warning at BeforeVersionDeprecated\.cmake:2 \(cmake_policy\):
-  Compatibility with CMake < 3\.10 will be removed from a future version of
-  CMake\.
-
-  Update the VERSION argument <min> value\.  Or, use the <min>\.\.\.<max> syntax
-  to tell CMake that the project requires at least <min> but has been updated
-  to work with policies introduced by <max> or earlier\.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-+
-CMake Deprecation Warning at BeforeVersionDeprecated\.cmake:6 \(cmake_policy\):
+CMake Deprecation Warning at BeforeVersionDeprecated\.cmake:5 \(cmake_policy\):
   Compatibility with CMake < 3\.10 will be removed from a future version of
   CMake\.
 

+ 0 - 1
Tests/RunCMake/cmake_minimum_required/BeforeVersionDeprecated.cmake

@@ -1,5 +1,4 @@
 cmake_minimum_required(VERSION 3.9)
-cmake_policy(VERSION 2.6)
 cmake_policy(PUSH)
 cmake_policy(VERSION 2.6) # simulate pre-3.18 install(EXPORT)-generated call
 cmake_policy(POP)

+ 0 - 0
Tests/RunCMake/cmake_minimum_required/CompatBefore24-result.txt → Tests/RunCMake/cmake_minimum_required/BeforeVersionRemoved-result.txt


+ 8 - 0
Tests/RunCMake/cmake_minimum_required/BeforeVersionRemoved-stderr.txt

@@ -0,0 +1,8 @@
+^CMake Error at BeforeVersionRemoved\.cmake:1 \(cmake_minimum_required\):
+  Compatibility with CMake < 2\.8\.0 has been removed from CMake\.
+
+  Update the VERSION argument <min> value\.  Or, use the <min>\.\.\.<max> syntax
+  to tell CMake that the project requires at least <min> but has been updated
+  to work with policies introduced by <max> or earlier\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:[0-9]+ \(include\)$

+ 1 - 0
Tests/RunCMake/cmake_minimum_required/BeforeVersionRemoved.cmake

@@ -0,0 +1 @@
+cmake_minimum_required(VERSION 2.6.4)

+ 0 - 15
Tests/RunCMake/cmake_minimum_required/CompatBefore24-stderr.txt

@@ -1,15 +0,0 @@
-^CMake Deprecation Warning at CompatBefore24\.cmake:1 \(cmake_minimum_required\):
-  Compatibility with CMake < 3\.10 will be removed from a future version of
-  CMake\.
-
-  Update the VERSION argument <min> value\.  Or, use the <min>\.\.\.<max> syntax
-  to tell CMake that the project requires at least <min> but has been updated
-  to work with policies introduced by <max> or earlier\.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-+
-CMake Error in CMakeLists.txt:
-  You have set CMAKE_BACKWARDS_COMPATIBILITY to a CMake version less than
-  2.4.  This version of CMake only supports backwards compatibility with
-  CMake 2.4 or later.  For compatibility with older versions please use any
-  CMake 2.8.x release or lower.

+ 0 - 2
Tests/RunCMake/cmake_minimum_required/CompatBefore24.cmake

@@ -1,2 +0,0 @@
-cmake_minimum_required(VERSION 2.4)
-set(CMAKE_BACKWARDS_COMPATIBILITY 2.2)

+ 0 - 6
Tests/RunCMake/cmake_minimum_required/PolicyBefore24-stderr.txt

@@ -1,6 +0,0 @@
-CMake Error at PolicyBefore24.cmake:2 \(cmake_policy\):
-  Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.  For
-  compatibility with older versions please use any CMake 2.8.x release or
-  lower.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)

+ 0 - 2
Tests/RunCMake/cmake_minimum_required/PolicyBefore24.cmake

@@ -1,2 +0,0 @@
-cmake_minimum_required(VERSION 2.4)
-cmake_policy(VERSION 2.2)

+ 0 - 0
Tests/RunCMake/cmake_minimum_required/PolicyBefore24-result.txt → Tests/RunCMake/cmake_minimum_required/PolicyBeforeVersionRemoved-result.txt


+ 8 - 0
Tests/RunCMake/cmake_minimum_required/PolicyBeforeVersionRemoved-stderr.txt

@@ -0,0 +1,8 @@
+^CMake Error at PolicyBeforeVersionRemoved\.cmake:1 \(cmake_policy\):
+  Compatibility with CMake < 2\.8\.0 has been removed from CMake\.
+
+  Update the VERSION argument <min> value\.  Or, use the <min>\.\.\.<max> syntax
+  to tell CMake that the project requires at least <min> but has been updated
+  to work with policies introduced by <max> or earlier\.
+Call Stack \(most recent call first\):
+  CMakeLists\.txt:[0-9]+ \(include\)$

+ 1 - 0
Tests/RunCMake/cmake_minimum_required/PolicyBeforeVersionRemoved.cmake

@@ -0,0 +1 @@
+cmake_policy(VERSION 2.6.4)

+ 2 - 3
Tests/RunCMake/cmake_minimum_required/RunCMakeTest.cmake

@@ -1,9 +1,8 @@
 include(RunCMake)
 
-run_cmake(Before24)
-run_cmake(CompatBefore24)
+run_cmake(BeforeVersionRemoved)
+run_cmake(PolicyBeforeVersionRemoved)
 run_cmake(Future)
-run_cmake(PolicyBefore24)
 run_cmake(BeforeVersionDeprecated)
 run_cmake(Range)
 run_cmake(RangeBad)