From 3c0dbb66f5dd728c9ab3c3fb403f6a21df92d955 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 7 Nov 2024 17:42:57 -0500 Subject: [PATCH] CMP0011: Remove support for OLD behavior --- Help/policy/CMP0011.rst | 9 +-- Source/cmFindPackageCommand.cxx | 4 +- Source/cmMakefile.cxx | 67 +------------------ Source/cmPolicies.h | 2 +- Source/cmStateSnapshot.cxx | 5 -- Source/cmStateSnapshot.h | 1 - Tests/PolicyScope/CMakeLists.txt | 17 +---- Tests/PolicyScope/FindFoo.cmake | 2 - .../AppleTextStubs/LibraryWithVersions.cmake | 1 - .../SourceGroupFileSet-check.cmake | 2 - .../SourceGroupTreeCMakeLists-check.cmake | 2 - 11 files changed, 10 insertions(+), 102 deletions(-) delete mode 100644 Tests/PolicyScope/FindFoo.cmake diff --git a/Help/policy/CMP0011.rst b/Help/policy/CMP0011.rst index 976b3c3c84..98614b9cb2 100644 --- a/Help/policy/CMP0011.rst +++ b/Help/policy/CMP0011.rst @@ -1,6 +1,9 @@ CMP0011 ------- +.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0 +.. include:: REMOVED_PROLOGUE.txt + Included scripts do automatic :command:`cmake_policy` PUSH and POP. In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by @@ -19,7 +22,5 @@ The ``NEW`` behavior for this policy is to allow the commands to do their default cmake_policy ``PUSH`` and ``POP``. .. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.6.3 -.. |WARNS_OR_DOES_NOT_WARN| replace:: warns -.. include:: STANDARD_ADVICE.txt - -.. include:: DEPRECATED.txt +.. |WARNED_OR_DID_NOT_WARN| replace:: warned +.. include:: REMOVED_EPILOGUE.txt diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 69cc2d6c97..1e36526291 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -2789,8 +2789,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file, this->VersionRangeMax); } - // Load the version check file. Pass NoPolicyScope because we do - // our own policy push/pop independent of CMP0011. + // Load the version check file. + // Pass NoPolicyScope because we do our own policy push/pop. bool suitable = false; if (this->ReadListFile(version_file, NoPolicyScope)) { // Check the output variables. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a639564193..5befafabd5 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -601,9 +601,7 @@ public: private: cmMakefile* Makefile; bool NoPolicyScope; - bool CheckCMP0011 = false; bool ReportError = true; - void EnforceCMP0011(); }; cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, @@ -621,48 +619,15 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, this->Makefile->GetState()->CreateIncludeFileSnapshot( this->Makefile->StateSnapshot, filenametoread); if (!this->NoPolicyScope) { - // Check CMP0011 to determine the policy scope type. - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011)) { - case cmPolicies::WARN: - // We need to push a scope to detect whether the script sets - // any policies that would affect the includer and therefore - // requires a warning. We use a weak scope to simulate OLD - // behavior by allowing policy changes to affect the includer. - this->Makefile->PushPolicy(true); - this->CheckCMP0011 = true; - break; - case cmPolicies::OLD: - // OLD behavior is to not push a scope at all. - this->NoPolicyScope = true; - break; - case cmPolicies::NEW: - // NEW behavior is to push a (strong) scope. - this->Makefile->PushPolicy(); - break; - } + this->Makefile->PushPolicy(); } } cmMakefile::IncludeScope::~IncludeScope() { if (!this->NoPolicyScope) { - // If we need to enforce policy CMP0011 then the top entry is the - // one we pushed above. If the entry is empty, then the included - // script did not set any policies that might affect the includer so - // we do not need to enforce the policy. - if (this->CheckCMP0011 && - !this->Makefile->StateSnapshot.HasDefinedPolicyCMP0011()) { - this->CheckCMP0011 = false; - } - // Pop the scope we pushed for the script. this->Makefile->PopPolicy(); - - // We enforce the policy after the script's policy stack entry has - // been removed. - if (this->CheckCMP0011) { - this->EnforceCMP0011(); - } } this->Makefile->PopSnapshot(this->ReportError); @@ -671,36 +636,6 @@ cmMakefile::IncludeScope::~IncludeScope() this->Makefile->Backtrace = this->Makefile->Backtrace.Pop(); } -void cmMakefile::IncludeScope::EnforceCMP0011() -{ - // We check the setting of this policy again because the included - // script might actually set this policy for its includer. - switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0011)) { - case cmPolicies::WARN: - // Warn because the user did not set this policy. - { - auto e = cmStrCat( - cmPolicies::GetPolicyWarning(cmPolicies::CMP0011), - "\n" - "The included script\n" - " ", - this->Makefile->GetBacktrace().Top().FilePath, - "\n" - "affects policy settings. " - "CMake is implying the NO_POLICY_SCOPE option for compatibility, " - "so the effects are applied to the including context."); - this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, e); - } - break; - case cmPolicies::OLD: - case cmPolicies::NEW: - // The script set this policy. We assume the purpose of the - // script is to initialize policies for its includer, and since - // the policy is now set for later scripts, we do not warn. - break; - } -} - bool cmMakefile::ReadDependentFile(const std::string& filename, bool noPolicyScope) { diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 429b12e0c9..95ee43432e 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -47,7 +47,7 @@ class cmMakefile; 3, NEW) \ SELECT(POLICY, CMP0011, \ "Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \ - WARN) \ + NEW) \ SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \ 2, 8, 0, WARN) \ SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \ diff --git a/Source/cmStateSnapshot.cxx b/Source/cmStateSnapshot.cxx index 0e48ab24cd..91b827c588 100644 --- a/Source/cmStateSnapshot.cxx +++ b/Source/cmStateSnapshot.cxx @@ -200,11 +200,6 @@ cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id, return status; } -bool cmStateSnapshot::HasDefinedPolicyCMP0011() -{ - return !this->Position->Policies->IsEmpty(); -} - cmValue cmStateSnapshot::GetDefinition(std::string const& name) const { assert(this->Position->Vars.IsValid()); diff --git a/Source/cmStateSnapshot.h b/Source/cmStateSnapshot.h index 1796d760b1..a8cafcd068 100644 --- a/Source/cmStateSnapshot.h +++ b/Source/cmStateSnapshot.h @@ -46,7 +46,6 @@ public: void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status); cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id, bool parent_scope = false) const; - bool HasDefinedPolicyCMP0011(); void PushPolicy(cmPolicies::PolicyMap const& entry, bool weak); bool PopPolicy(); bool CanPopPolicyScope(); diff --git a/Tests/PolicyScope/CMakeLists.txt b/Tests/PolicyScope/CMakeLists.txt index fbcfe937b2..15e553ca2e 100644 --- a/Tests/PolicyScope/CMakeLists.txt +++ b/Tests/PolicyScope/CMakeLists.txt @@ -10,28 +10,13 @@ function(check msg lhs rhs) endfunction() #----------------------------------------------------------------------------- -# Test using a development framework that sets policies for us. - -cmake_policy(SET CMP0011 OLD) - # Put the test modules in the search path. list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) -# The included file should set policies for us. -find_package(Foo) - -# Check policies set by the package. -cmake_policy(GET CMP0180 cmp) -check(CMP0180 "OLD" "${cmp}") -cmake_policy(GET CMP0179 cmp) -check(CMP0179 "NEW" "${cmp}") -cmake_policy(GET CMP0011 cmp) -check(CMP0011 "NEW" "${cmp}") - # Make sure an included file cannot change policies. include(Bar) cmake_policy(GET CMP0180 cmp) -check(CMP0180 "OLD" "${cmp}") +check(CMP0180 "" "${cmp}") # Allow the included file to change policies. include(Bar NO_POLICY_SCOPE) diff --git a/Tests/PolicyScope/FindFoo.cmake b/Tests/PolicyScope/FindFoo.cmake deleted file mode 100644 index 843c650714..0000000000 --- a/Tests/PolicyScope/FindFoo.cmake +++ /dev/null @@ -1,2 +0,0 @@ -cmake_minimum_required(VERSION 3.31) -cmake_policy(SET CMP0180 OLD) diff --git a/Tests/RunCMake/AppleTextStubs/LibraryWithVersions.cmake b/Tests/RunCMake/AppleTextStubs/LibraryWithVersions.cmake index 28c175df31..110a61cda7 100644 --- a/Tests/RunCMake/AppleTextStubs/LibraryWithVersions.cmake +++ b/Tests/RunCMake/AppleTextStubs/LibraryWithVersions.cmake @@ -25,7 +25,6 @@ set (GENERATE_CONTENT "if (\"${CMAKE_TAPI}\") endif()\n\n") string (APPEND GENERATE_CONTENT [[ -cmake_policy (SET CMP0011 NEW) cmake_policy (SET CMP0057 NEW) macro (CHECK_FILE test_msg path) diff --git a/Tests/RunCMake/VS10Project/SourceGroupFileSet-check.cmake b/Tests/RunCMake/VS10Project/SourceGroupFileSet-check.cmake index fb2eecc864..3b4cc58eb7 100644 --- a/Tests/RunCMake/VS10Project/SourceGroupFileSet-check.cmake +++ b/Tests/RunCMake/VS10Project/SourceGroupFileSet-check.cmake @@ -1,5 +1,3 @@ -cmake_policy(SET CMP0011 NEW) - set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupFileSet.vcxproj.filters") if(NOT EXISTS "${vcFiltersFile}") set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.") diff --git a/Tests/RunCMake/VS10Project/SourceGroupTreeCMakeLists-check.cmake b/Tests/RunCMake/VS10Project/SourceGroupTreeCMakeLists-check.cmake index 28d0d297c9..3e92bb8b6c 100644 --- a/Tests/RunCMake/VS10Project/SourceGroupTreeCMakeLists-check.cmake +++ b/Tests/RunCMake/VS10Project/SourceGroupTreeCMakeLists-check.cmake @@ -1,5 +1,3 @@ -cmake_policy(SET CMP0011 NEW) - set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupTree.vcxproj.filters") if(NOT EXISTS "${vcFiltersFile}") set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")