summaryrefslogtreecommitdiffstats
path: root/Source/cmPolicies.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-03-16 16:42:36 (GMT)
committerBrad King <brad.king@kitware.com>2018-03-21 12:00:28 (GMT)
commit45408b5ea1e3654b5d4f6289ca1a0b5c0f1ac4e9 (patch)
tree73dd09488de4a0559bd3e3dd1828f8c75278f31c /Source/cmPolicies.cxx
parent6a41aa2abd75ceaa9081edc1c7f8510d2c17dd7e (diff)
downloadCMake-45408b5ea1e3654b5d4f6289ca1a0b5c0f1ac4e9.zip
CMake-45408b5ea1e3654b5d4f6289ca1a0b5c0f1ac4e9.tar.gz
CMake-45408b5ea1e3654b5d4f6289ca1a0b5c0f1ac4e9.tar.bz2
cmake_minimum_required: Optionally set policies with version range
Teach `cmake_minimum_required` and `cmake_policy(VERSION)` to support a version range of the form `<min>[...<max>]`. Define this to mean that version `<min>` is required, but known policies up to those introduced by `<max>` will be set to `NEW`. This will allow projects to easily specify a range of versions for which they have been updated.
Diffstat (limited to 'Source/cmPolicies.cxx')
-rw-r--r--Source/cmPolicies.cxx39
1 files changed, 38 insertions, 1 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index cf61edd..dba22b3 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -154,7 +154,8 @@ static bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
}
bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
- std::string const& version_min)
+ std::string const& version_min,
+ std::string const& version_max)
{
// Parse components of the minimum version.
unsigned int minMajor = 2;
@@ -205,6 +206,42 @@ bool cmPolicies::ApplyPolicyVersion(cmMakefile* mf,
unsigned int polMajor = minMajor;
unsigned int polMinor = minMinor;
unsigned int polPatch = minPatch;
+
+ if (!version_max.empty()) {
+ // Parse components of the maximum version.
+ unsigned int maxMajor = 0;
+ unsigned int maxMinor = 0;
+ unsigned int maxPatch = 0;
+ unsigned int maxTweak = 0;
+ if (sscanf(version_max.c_str(), "%u.%u.%u.%u", &maxMajor, &maxMinor,
+ &maxPatch, &maxTweak) < 2) {
+ std::ostringstream e;
+ e << "Invalid policy max version value \"" << version_max << "\". "
+ << "A numeric major.minor[.patch[.tweak]] must be given.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // It is an error if the min version is greater than the max version.
+ if (minMajor > maxMajor || (minMajor == maxMajor && minMinor > maxMinor) ||
+ (minMajor == maxMajor && minMinor == maxMinor &&
+ minPatch > maxPatch) ||
+ (minMajor == maxMajor && minMinor == maxMinor &&
+ minPatch == maxPatch && minTweak > maxTweak)) {
+ std::ostringstream e;
+ e << "Policy VERSION range \"" << version_min << "..." << version_max
+ << "\""
+ << " specifies a larger minimum than maximum.";
+ mf->IssueMessage(cmake::FATAL_ERROR, e.str());
+ return false;
+ }
+
+ // Use the max version as the policy version.
+ polMajor = maxMajor;
+ polMinor = maxMinor;
+ polPatch = maxPatch;
+ }
+
return cmPolicies::ApplyPolicyVersion(mf, polMajor, polMinor, polPatch);
}