mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
cmPolicies: Split parsing and impl of ApplyPolicyVersion
Also rename local variables to clarify their role during parsing.
This commit is contained in:
@@ -156,14 +156,13 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
|
|||||||
bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
|
bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
|
||||||
std::string const& version_min)
|
std::string const& version_min)
|
||||||
{
|
{
|
||||||
unsigned int majorVer = 2;
|
// Parse components of the minimum version.
|
||||||
unsigned int minorVer = 0;
|
unsigned int minMajor = 2;
|
||||||
unsigned int patchVer = 0;
|
unsigned int minMinor = 0;
|
||||||
unsigned int tweakVer = 0;
|
unsigned int minPatch = 0;
|
||||||
|
unsigned int minTweak = 0;
|
||||||
// parse the string
|
if (sscanf(version_min.c_str(), "%u.%u.%u.%u", &minMajor, &minMinor,
|
||||||
if (sscanf(version_min.c_str(), "%u.%u.%u.%u", &majorVer, &minorVer,
|
&minPatch, &minTweak) < 2) {
|
||||||
&patchVer, &tweakVer) < 2) {
|
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "Invalid policy version value \"" << version_min << "\". "
|
e << "Invalid policy version value \"" << version_min << "\". "
|
||||||
<< "A numeric major.minor[.patch[.tweak]] must be given.";
|
<< "A numeric major.minor[.patch[.tweak]] must be given.";
|
||||||
@@ -172,7 +171,7 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// it is an error if the policy version is less than 2.4
|
// it is an error if the policy version is less than 2.4
|
||||||
if (majorVer < 2 || (majorVer == 2 && minorVer < 4)) {
|
if (minMajor < 2 || (minMajor == 2 && minMinor < 4)) {
|
||||||
mf->IssueMessage(
|
mf->IssueMessage(
|
||||||
cmake::FATAL_ERROR,
|
cmake::FATAL_ERROR,
|
||||||
"Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. "
|
"Compatibility with CMake < 2.4 is not supported by CMake >= 3.0. "
|
||||||
@@ -183,16 +182,16 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
|
|||||||
|
|
||||||
// It is an error if the policy version is greater than the running
|
// It is an error if the policy version is greater than the running
|
||||||
// CMake.
|
// CMake.
|
||||||
if (majorVer > cmVersion::GetMajorVersion() ||
|
if (minMajor > cmVersion::GetMajorVersion() ||
|
||||||
(majorVer == cmVersion::GetMajorVersion() &&
|
(minMajor == cmVersion::GetMajorVersion() &&
|
||||||
minorVer > cmVersion::GetMinorVersion()) ||
|
minMinor > cmVersion::GetMinorVersion()) ||
|
||||||
(majorVer == cmVersion::GetMajorVersion() &&
|
(minMajor == cmVersion::GetMajorVersion() &&
|
||||||
minorVer == cmVersion::GetMinorVersion() &&
|
minMinor == cmVersion::GetMinorVersion() &&
|
||||||
patchVer > cmVersion::GetPatchVersion()) ||
|
minPatch > cmVersion::GetPatchVersion()) ||
|
||||||
(majorVer == cmVersion::GetMajorVersion() &&
|
(minMajor == cmVersion::GetMajorVersion() &&
|
||||||
minorVer == cmVersion::GetMinorVersion() &&
|
minMinor == cmVersion::GetMinorVersion() &&
|
||||||
patchVer == cmVersion::GetPatchVersion() &&
|
minPatch == cmVersion::GetPatchVersion() &&
|
||||||
tweakVer > cmVersion::GetTweakVersion())) {
|
minTweak > cmVersion::GetTweakVersion())) {
|
||||||
std::ostringstream e;
|
std::ostringstream e;
|
||||||
e << "An attempt was made to set the policy version of CMake to \""
|
e << "An attempt was made to set the policy version of CMake to \""
|
||||||
<< version_min << "\" which is greater than this version of CMake. "
|
<< version_min << "\" which is greater than this version of CMake. "
|
||||||
@@ -203,6 +202,16 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int polMajor = minMajor;
|
||||||
|
unsigned int polMinor = minMinor;
|
||||||
|
unsigned int polPatch = minPatch;
|
||||||
|
return cmPolicies::ApplyPolicyVersion(mf, polMajor, polMinor, polPatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
|
||||||
|
unsigned int minorVer,
|
||||||
|
unsigned int patchVer)
|
||||||
|
{
|
||||||
// now loop over all the policies and set them as appropriate
|
// now loop over all the policies and set them as appropriate
|
||||||
std::vector<cmPolicies::PolicyID> ancientPolicies;
|
std::vector<cmPolicies::PolicyID> ancientPolicies;
|
||||||
for (PolicyID pid = cmPolicies::CMP0000; pid != cmPolicies::CMPCOUNT;
|
for (PolicyID pid = cmPolicies::CMP0000; pid != cmPolicies::CMPCOUNT;
|
||||||
|
|||||||
@@ -290,6 +290,8 @@ public:
|
|||||||
///! Set a policy level for this listfile
|
///! Set a policy level for this listfile
|
||||||
static bool ApplyPolicyVersion(cmMakefile* mf,
|
static bool ApplyPolicyVersion(cmMakefile* mf,
|
||||||
std::string const& version_min);
|
std::string const& version_min);
|
||||||
|
static bool ApplyPolicyVersion(cmMakefile* mf, unsigned int majorVer,
|
||||||
|
unsigned int minorVer, unsigned int patchVer);
|
||||||
|
|
||||||
///! return a warning string for a given policy
|
///! return a warning string for a given policy
|
||||||
static std::string GetPolicyWarning(cmPolicies::PolicyID id);
|
static std::string GetPolicyWarning(cmPolicies::PolicyID id);
|
||||||
|
|||||||
Reference in New Issue
Block a user