mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 19:43:23 +08:00
CMP0011: Remove support for OLD behavior
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
CMP0011
|
CMP0011
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
|
||||||
|
.. include:: REMOVED_PROLOGUE.txt
|
||||||
|
|
||||||
Included scripts do automatic :command:`cmake_policy` PUSH and POP.
|
Included scripts do automatic :command:`cmake_policy` PUSH and POP.
|
||||||
|
|
||||||
In CMake 2.6.2 and below, CMake Policy settings in scripts loaded by
|
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``.
|
their default cmake_policy ``PUSH`` and ``POP``.
|
||||||
|
|
||||||
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.6.3
|
.. |INTRODUCED_IN_CMAKE_VERSION| replace:: 2.6.3
|
||||||
.. |WARNS_OR_DOES_NOT_WARN| replace:: warns
|
.. |WARNED_OR_DID_NOT_WARN| replace:: warned
|
||||||
.. include:: STANDARD_ADVICE.txt
|
.. include:: REMOVED_EPILOGUE.txt
|
||||||
|
|
||||||
.. include:: DEPRECATED.txt
|
|
||||||
|
@@ -2789,8 +2789,8 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file,
|
|||||||
this->VersionRangeMax);
|
this->VersionRangeMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the version check file. Pass NoPolicyScope because we do
|
// Load the version check file.
|
||||||
// our own policy push/pop independent of CMP0011.
|
// Pass NoPolicyScope because we do our own policy push/pop.
|
||||||
bool suitable = false;
|
bool suitable = false;
|
||||||
if (this->ReadListFile(version_file, NoPolicyScope)) {
|
if (this->ReadListFile(version_file, NoPolicyScope)) {
|
||||||
// Check the output variables.
|
// Check the output variables.
|
||||||
|
@@ -601,9 +601,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
cmMakefile* Makefile;
|
cmMakefile* Makefile;
|
||||||
bool NoPolicyScope;
|
bool NoPolicyScope;
|
||||||
bool CheckCMP0011 = false;
|
|
||||||
bool ReportError = true;
|
bool ReportError = true;
|
||||||
void EnforceCMP0011();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
||||||
@@ -621,48 +619,15 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
|
|||||||
this->Makefile->GetState()->CreateIncludeFileSnapshot(
|
this->Makefile->GetState()->CreateIncludeFileSnapshot(
|
||||||
this->Makefile->StateSnapshot, filenametoread);
|
this->Makefile->StateSnapshot, filenametoread);
|
||||||
if (!this->NoPolicyScope) {
|
if (!this->NoPolicyScope) {
|
||||||
// Check CMP0011 to determine the policy scope type.
|
this->Makefile->PushPolicy();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmMakefile::IncludeScope::~IncludeScope()
|
cmMakefile::IncludeScope::~IncludeScope()
|
||||||
{
|
{
|
||||||
if (!this->NoPolicyScope) {
|
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.
|
// Pop the scope we pushed for the script.
|
||||||
this->Makefile->PopPolicy();
|
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);
|
this->Makefile->PopSnapshot(this->ReportError);
|
||||||
|
|
||||||
@@ -671,36 +636,6 @@ cmMakefile::IncludeScope::~IncludeScope()
|
|||||||
this->Makefile->Backtrace = this->Makefile->Backtrace.Pop();
|
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 cmMakefile::ReadDependentFile(const std::string& filename,
|
||||||
bool noPolicyScope)
|
bool noPolicyScope)
|
||||||
{
|
{
|
||||||
|
@@ -47,7 +47,7 @@ class cmMakefile;
|
|||||||
3, NEW) \
|
3, NEW) \
|
||||||
SELECT(POLICY, CMP0011, \
|
SELECT(POLICY, CMP0011, \
|
||||||
"Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \
|
"Included scripts do automatic cmake_policy PUSH and POP.", 2, 6, 3, \
|
||||||
WARN) \
|
NEW) \
|
||||||
SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \
|
SELECT(POLICY, CMP0012, "if() recognizes numbers and boolean constants.", \
|
||||||
2, 8, 0, WARN) \
|
2, 8, 0, WARN) \
|
||||||
SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \
|
SELECT(POLICY, CMP0013, "Duplicate binary directories are not allowed.", 2, \
|
||||||
|
@@ -200,11 +200,6 @@ cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmStateSnapshot::HasDefinedPolicyCMP0011()
|
|
||||||
{
|
|
||||||
return !this->Position->Policies->IsEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
cmValue cmStateSnapshot::GetDefinition(std::string const& name) const
|
cmValue cmStateSnapshot::GetDefinition(std::string const& name) const
|
||||||
{
|
{
|
||||||
assert(this->Position->Vars.IsValid());
|
assert(this->Position->Vars.IsValid());
|
||||||
|
@@ -46,7 +46,6 @@ public:
|
|||||||
void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
|
void SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
|
||||||
cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id,
|
cmPolicies::PolicyStatus GetPolicy(cmPolicies::PolicyID id,
|
||||||
bool parent_scope = false) const;
|
bool parent_scope = false) const;
|
||||||
bool HasDefinedPolicyCMP0011();
|
|
||||||
void PushPolicy(cmPolicies::PolicyMap const& entry, bool weak);
|
void PushPolicy(cmPolicies::PolicyMap const& entry, bool weak);
|
||||||
bool PopPolicy();
|
bool PopPolicy();
|
||||||
bool CanPopPolicyScope();
|
bool CanPopPolicyScope();
|
||||||
|
@@ -10,28 +10,13 @@ function(check msg lhs rhs)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Test using a development framework that sets policies for us.
|
|
||||||
|
|
||||||
cmake_policy(SET CMP0011 OLD)
|
|
||||||
|
|
||||||
# Put the test modules in the search path.
|
# Put the test modules in the search path.
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
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.
|
# Make sure an included file cannot change policies.
|
||||||
include(Bar)
|
include(Bar)
|
||||||
cmake_policy(GET CMP0180 cmp)
|
cmake_policy(GET CMP0180 cmp)
|
||||||
check(CMP0180 "OLD" "${cmp}")
|
check(CMP0180 "" "${cmp}")
|
||||||
|
|
||||||
# Allow the included file to change policies.
|
# Allow the included file to change policies.
|
||||||
include(Bar NO_POLICY_SCOPE)
|
include(Bar NO_POLICY_SCOPE)
|
||||||
|
@@ -1,2 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.31)
|
|
||||||
cmake_policy(SET CMP0180 OLD)
|
|
@@ -25,7 +25,6 @@ set (GENERATE_CONTENT "if (\"${CMAKE_TAPI}\")
|
|||||||
endif()\n\n")
|
endif()\n\n")
|
||||||
|
|
||||||
string (APPEND GENERATE_CONTENT [[
|
string (APPEND GENERATE_CONTENT [[
|
||||||
cmake_policy (SET CMP0011 NEW)
|
|
||||||
cmake_policy (SET CMP0057 NEW)
|
cmake_policy (SET CMP0057 NEW)
|
||||||
|
|
||||||
macro (CHECK_FILE test_msg path)
|
macro (CHECK_FILE test_msg path)
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
cmake_policy(SET CMP0011 NEW)
|
|
||||||
|
|
||||||
set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupFileSet.vcxproj.filters")
|
set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupFileSet.vcxproj.filters")
|
||||||
if(NOT EXISTS "${vcFiltersFile}")
|
if(NOT EXISTS "${vcFiltersFile}")
|
||||||
set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")
|
set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
cmake_policy(SET CMP0011 NEW)
|
|
||||||
|
|
||||||
set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupTree.vcxproj.filters")
|
set(vcFiltersFile "${RunCMake_TEST_BINARY_DIR}/SourceGroupTree.vcxproj.filters")
|
||||||
if(NOT EXISTS "${vcFiltersFile}")
|
if(NOT EXISTS "${vcFiltersFile}")
|
||||||
set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")
|
set(RunCMake_TEST_FAILED "Filters file ${vcFiltersFile} does not exist.")
|
||||||
|
Reference in New Issue
Block a user