Merge topic 'policy-refactor'
8329fc01
cmPolicies: Replace unused include.5447ca1a
cmMakefile: Remove CMP0001 handling to callers.d0dcce15
cmMakefile: Simplify computation of ancient policy status.658bfc5c
cmMakefile: Remove redundant condition from policy status computation.f4a25874
cmMakefile: Inline internal policy status method.3c45471c
cmPolicies: Enable RVO for internal method.71e69fc9
cmPolicies: Store only state that users can set.84e18056
cmMakefile: Convert recursion to loop.
This commit is contained in:
commit
cb21c548db
|
@ -93,6 +93,22 @@ bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
|
||||||
this->SetError("SET failed to set policy.");
|
this->SetError("SET failed to set policy.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(args[1] == "CMP0001" &&
|
||||||
|
(status == cmPolicies::WARN || status == cmPolicies::OLD))
|
||||||
|
{
|
||||||
|
if(!(this->Makefile->GetState()
|
||||||
|
->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
|
||||||
|
{
|
||||||
|
// Set it to 2.4 because that is the last version where the
|
||||||
|
// variable had meaning.
|
||||||
|
this->Makefile->AddCacheDefinition
|
||||||
|
("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
|
||||||
|
"For backwards compatibility, what version of CMake "
|
||||||
|
"commands and "
|
||||||
|
"syntax should this version of CMake try to support.",
|
||||||
|
cmState::STRING);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4736,53 +4736,30 @@ const char* cmMakefile::GetDefineFlagsCMP0059() const
|
||||||
cmPolicies::PolicyStatus
|
cmPolicies::PolicyStatus
|
||||||
cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
|
cmMakefile::GetPolicyStatus(cmPolicies::PolicyID id) const
|
||||||
{
|
{
|
||||||
// Get the current setting of the policy.
|
cmPolicies::PolicyStatus status = cmPolicies::GetPolicyStatus(id);
|
||||||
cmPolicies::PolicyStatus cur = this->GetPolicyStatusInternal(id);
|
|
||||||
|
|
||||||
// If the policy is required to be set to NEW but is not, ignore the
|
if(status == cmPolicies::REQUIRED_ALWAYS ||
|
||||||
// current setting and tell the caller.
|
status == cmPolicies::REQUIRED_IF_USED)
|
||||||
if(cur != cmPolicies::NEW)
|
|
||||||
{
|
{
|
||||||
if(cur == cmPolicies::REQUIRED_ALWAYS ||
|
return status;
|
||||||
cur == cmPolicies::REQUIRED_IF_USED)
|
|
||||||
{
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
cmPolicies::PolicyStatus def = cmPolicies::GetPolicyStatus(id);
|
|
||||||
if(def == cmPolicies::REQUIRED_ALWAYS ||
|
|
||||||
def == cmPolicies::REQUIRED_IF_USED)
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The current setting is okay.
|
cmLocalGenerator* lg = this->LocalGenerator;
|
||||||
return cur;
|
while(lg)
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
cmPolicies::PolicyStatus
|
|
||||||
cmMakefile::GetPolicyStatusInternal(cmPolicies::PolicyID id) const
|
|
||||||
{
|
|
||||||
// Is the policy set in our stack?
|
|
||||||
for(PolicyStackType::const_reverse_iterator psi = this->PolicyStack.rbegin();
|
|
||||||
psi != this->PolicyStack.rend(); ++psi)
|
|
||||||
{
|
{
|
||||||
if(psi->IsDefined(id))
|
cmMakefile const* mf = lg->GetMakefile();
|
||||||
|
for(PolicyStackType::const_reverse_iterator psi =
|
||||||
|
mf->PolicyStack.rbegin(); psi != mf->PolicyStack.rend(); ++psi)
|
||||||
{
|
{
|
||||||
return psi->Get(id);
|
if(psi->IsDefined(id))
|
||||||
|
{
|
||||||
|
status = psi->Get(id);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
lg = lg->GetParent();
|
||||||
}
|
}
|
||||||
|
return status;
|
||||||
// If we have a parent directory, recurse up to it.
|
|
||||||
if(this->LocalGenerator->GetParent())
|
|
||||||
{
|
|
||||||
cmMakefile* parent = this->LocalGenerator->GetParent()->GetMakefile();
|
|
||||||
return parent->GetPolicyStatusInternal(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The policy is not set. Use the default for this CMake version.
|
|
||||||
return cmPolicies::GetPolicyStatus(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -4839,25 +4816,6 @@ bool cmMakefile::SetPolicy(cmPolicies::PolicyID id,
|
||||||
previous_was_weak = psi->Weak;
|
previous_was_weak = psi->Weak;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special hook for presenting compatibility variable as soon as
|
|
||||||
// the user requests it.
|
|
||||||
if(id == cmPolicies::CMP0001 &&
|
|
||||||
(status == cmPolicies::WARN || status == cmPolicies::OLD))
|
|
||||||
{
|
|
||||||
if(!(this->GetState()
|
|
||||||
->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
|
|
||||||
{
|
|
||||||
// Set it to 2.4 because that is the last version where the
|
|
||||||
// variable had meaning.
|
|
||||||
this->AddCacheDefinition
|
|
||||||
("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
|
|
||||||
"For backwards compatibility, what version of CMake "
|
|
||||||
"commands and "
|
|
||||||
"syntax should this version of CMake try to support.",
|
|
||||||
cmState::STRING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -929,8 +929,6 @@ private:
|
||||||
typedef std::vector<PolicyStackEntry> PolicyStackType;
|
typedef std::vector<PolicyStackEntry> PolicyStackType;
|
||||||
PolicyStackType PolicyStack;
|
PolicyStackType PolicyStack;
|
||||||
std::vector<PolicyStackType::size_type> PolicyBarriers;
|
std::vector<PolicyStackType::size_type> PolicyBarriers;
|
||||||
cmPolicies::PolicyStatus
|
|
||||||
GetPolicyStatusInternal(cmPolicies::PolicyID id) const;
|
|
||||||
|
|
||||||
// CMP0053 == old
|
// CMP0053 == old
|
||||||
cmake::MessageType ExpandVariablesInStringOld(
|
cmake::MessageType ExpandVariablesInStringOld(
|
||||||
|
|
|
@ -255,6 +255,22 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf,
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(pid == cmPolicies::CMP0001 &&
|
||||||
|
(status == cmPolicies::WARN || status == cmPolicies::OLD))
|
||||||
|
{
|
||||||
|
if(!(mf->GetState()
|
||||||
|
->GetInitializedCacheValue("CMAKE_BACKWARDS_COMPATIBILITY")))
|
||||||
|
{
|
||||||
|
// Set it to 2.4 because that is the last version where the
|
||||||
|
// variable had meaning.
|
||||||
|
mf->AddCacheDefinition
|
||||||
|
("CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
|
||||||
|
"For backwards compatibility, what version of CMake "
|
||||||
|
"commands and "
|
||||||
|
"syntax should this version of CMake try to support.",
|
||||||
|
cmState::STRING);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -356,14 +372,6 @@ cmPolicies::PolicyMap::Get(cmPolicies::PolicyID id) const
|
||||||
{
|
{
|
||||||
status = cmPolicies::NEW;
|
status = cmPolicies::NEW;
|
||||||
}
|
}
|
||||||
else if (this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_ALWAYS])
|
|
||||||
{
|
|
||||||
status = cmPolicies::REQUIRED_ALWAYS;
|
|
||||||
}
|
|
||||||
else if (this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_IF_USED])
|
|
||||||
{
|
|
||||||
status = cmPolicies::REQUIRED_IF_USED;
|
|
||||||
}
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,19 +381,13 @@ void cmPolicies::PolicyMap::Set(cmPolicies::PolicyID id,
|
||||||
this->Status[(POLICY_STATUS_COUNT * id) + OLD] = (status == OLD);
|
this->Status[(POLICY_STATUS_COUNT * id) + OLD] = (status == OLD);
|
||||||
this->Status[(POLICY_STATUS_COUNT * id) + WARN] = (status == WARN);
|
this->Status[(POLICY_STATUS_COUNT * id) + WARN] = (status == WARN);
|
||||||
this->Status[(POLICY_STATUS_COUNT * id) + NEW] = (status == NEW);
|
this->Status[(POLICY_STATUS_COUNT * id) + NEW] = (status == NEW);
|
||||||
this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_ALWAYS] =
|
|
||||||
(status == REQUIRED_ALWAYS);
|
|
||||||
this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_IF_USED] =
|
|
||||||
(status == REQUIRED_IF_USED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmPolicies::PolicyMap::IsDefined(cmPolicies::PolicyID id) const
|
bool cmPolicies::PolicyMap::IsDefined(cmPolicies::PolicyID id) const
|
||||||
{
|
{
|
||||||
return this->Status[(POLICY_STATUS_COUNT * id) + OLD]
|
return this->Status[(POLICY_STATUS_COUNT * id) + OLD]
|
||||||
|| this->Status[(POLICY_STATUS_COUNT * id) + WARN]
|
|| this->Status[(POLICY_STATUS_COUNT * id) + WARN]
|
||||||
|| this->Status[(POLICY_STATUS_COUNT * id) + NEW]
|
|| this->Status[(POLICY_STATUS_COUNT * id) + NEW];
|
||||||
|| this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_ALWAYS]
|
|
||||||
|| this->Status[(POLICY_STATUS_COUNT * id) + REQUIRED_IF_USED];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmPolicies::PolicyMap::IsEmpty() const
|
bool cmPolicies::PolicyMap::IsEmpty() const
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#ifndef cmPolicies_h
|
#ifndef cmPolicies_h
|
||||||
#define cmPolicies_h
|
#define cmPolicies_h
|
||||||
|
|
||||||
#include "cmCustomCommand.h"
|
#include "cmStandardIncludes.h"
|
||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
|
@ -244,7 +244,6 @@ public:
|
||||||
REQUIRED_IF_USED,
|
REQUIRED_IF_USED,
|
||||||
REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
|
REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
|
||||||
};
|
};
|
||||||
#define POLICY_STATUS_COUNT 5
|
|
||||||
|
|
||||||
/// Policy identifiers
|
/// Policy identifiers
|
||||||
enum PolicyID
|
enum PolicyID
|
||||||
|
@ -288,6 +287,7 @@ public:
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#define POLICY_STATUS_COUNT 3
|
||||||
std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;
|
std::bitset<cmPolicies::CMPCOUNT * POLICY_STATUS_COUNT> Status;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue