diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 9250620c2..d75ea2395 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -45,11 +45,25 @@ static bool stringToId(const char* input, cmPolicies::PolicyID& pid) return true; } +static const char* idToString(cmPolicies::PolicyID id) +{ + switch(id) + { +#define POLICY_CASE(ID) \ + case cmPolicies::ID: \ + return #ID; + CM_FOR_EACH_POLICY_ID(POLICY_CASE) +#undef POLICY_CASE + case cmPolicies::CMPCOUNT: + return 0; + } + return 0; +} + class cmPolicy { public: cmPolicy(cmPolicies::PolicyID iD, - const char *idString, const char *shortDescription, unsigned int majorVersionIntroduced, unsigned int minorVersionIntroduced, @@ -57,7 +71,6 @@ public: cmPolicies::PolicyStatus status) { this->ID = iD; - this->IDString = idString; this->ShortDescription = shortDescription; this->MajorVersionIntroduced = majorVersionIntroduced; this->MinorVersionIntroduced = minorVersionIntroduced; @@ -89,7 +102,6 @@ public: } cmPolicies::PolicyID ID; - std::string IDString; std::string ShortDescription; unsigned int MajorVersionIntroduced; unsigned int MinorVersionIntroduced; @@ -417,14 +429,14 @@ cmPolicies::~cmPolicies() } void cmPolicies::DefinePolicy(cmPolicies::PolicyID iD, - const char *idString, + const char *, const char *shortDescription, unsigned int majorVersionIntroduced, unsigned int minorVersionIntroduced, unsigned int patchVersionIntroduced, cmPolicies::PolicyStatus status) { - this->Policies[iD] = new cmPolicy(iD, idString, + this->Policies[iD] = new cmPolicy(iD, shortDescription, majorVersionIntroduced, minorVersionIntroduced, @@ -536,7 +548,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile *mf, else { cmPolicies::PolicyStatus status = cmPolicies::WARN; - if(!GetPolicyDefault(mf, i->second->IDString, &status) || + if(!GetPolicyDefault(mf, idToString(i->first), &status) || !mf->SetPolicy(i->second->ID, status)) { return false; @@ -569,18 +581,6 @@ bool cmPolicies::GetPolicyID(const char *id, cmPolicies::PolicyID &pid) return stringToId(id, pid); } -std::string cmPolicies::GetPolicyIDString(cmPolicies::PolicyID pid) -{ - std::map::iterator pos = - this->Policies.find(pid); - if (pos == this->Policies.end()) - { - return ""; - } - return pos->second->IDString; -} - - ///! return a warning string for a given policy std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id) { @@ -589,9 +589,9 @@ std::string cmPolicies::GetPolicyWarning(cmPolicies::PolicyID id) std::ostringstream msg; msg << - "Policy " << pos->second->IDString << " is not set: " + "Policy " << idToString(id) << " is not set: " "" << pos->second->ShortDescription << " " - "Run \"cmake --help-policy " << pos->second->IDString << "\" for " + "Run \"cmake --help-policy " << idToString(id) << "\" for " "policy details. " "Use the cmake_policy command to set the policy " "and suppress this warning."; @@ -607,13 +607,13 @@ std::string cmPolicies::GetRequiredPolicyError(cmPolicies::PolicyID id) std::ostringstream error; error << - "Policy " << pos->second->IDString << " is not set to NEW: " + "Policy " << idToString(id) << " is not set to NEW: " "" << pos->second->ShortDescription << " " - "Run \"cmake --help-policy " << pos->second->IDString << "\" for " + "Run \"cmake --help-policy " << idToString(id) << "\" for " "policy details. " "CMake now requires this policy to be set to NEW by the project. " "The policy may be set explicitly using the code\n" - " cmake_policy(SET " << pos->second->IDString << " NEW)\n" + " cmake_policy(SET " << idToString(id) << " NEW)\n" "or by upgrading all policies with the code\n" " cmake_policy(VERSION " << pos->second->GetVersionString() << ") # or later\n" @@ -641,7 +641,7 @@ cmPolicies::GetPolicyStatus(cmPolicies::PolicyID id) std::string cmPolicies::GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id) { - std::string pid = this->GetPolicyIDString(id); + std::string pid = idToString(id); std::ostringstream e; e << "Policy " << pid << " may not be set to OLD behavior because this " << "version of CMake no longer supports it. " @@ -672,7 +672,7 @@ cmPolicies::DiagnoseAncientPolicies(std::vector const& ancient, i = ancient.begin(); i != ancient.end(); ++i) { cmPolicy const* policy = this->Policies[*i]; - e << " " << policy->IDString << ": " << policy->ShortDescription << "\n"; + e << " " << idToString(*i) << ": " << policy->ShortDescription << "\n"; } e << "However, this version of CMake no longer supports the OLD " << "behavior for these policies. " diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index e9881ace4..df04fdfdb 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -254,7 +254,6 @@ public: ///! convert a string policy ID into a number bool GetPolicyID(const char *id, /* out */ cmPolicies::PolicyID &pid); - std::string GetPolicyIDString(cmPolicies::PolicyID pid); ///! Get the default status for a policy cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);