From 45408b5ea1e3654b5d4f6289ca1a0b5c0f1ac4e9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 16 Mar 2018 12:42:36 -0400 Subject: 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 `[...]`. Define this to mean that version `` is required, but known policies up to those introduced by `` will be set to `NEW`. This will allow projects to easily specify a range of versions for which they have been updated. --- Source/cmCMakePolicyCommand.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'Source/cmCMakePolicyCommand.cxx') diff --git a/Source/cmCMakePolicyCommand.cxx b/Source/cmCMakePolicyCommand.cxx index 3ccc815e68..7ca1cbcb43 100644 --- a/Source/cmCMakePolicyCommand.cxx +++ b/Source/cmCMakePolicyCommand.cxx @@ -156,6 +156,23 @@ bool cmCMakePolicyCommand::HandleVersionMode( this->SetError("VERSION given too many arguments"); return false; } - this->Makefile->SetPolicyVersion(args[1].c_str()); + std::string const& version_string = args[1]; + + // Separate the version and any trailing ... component. + std::string::size_type const dd = version_string.find("..."); + std::string const version_min = version_string.substr(0, dd); + std::string const version_max = dd != std::string::npos + ? version_string.substr(dd + 3, std::string::npos) + : std::string(); + if (dd != std::string::npos && + (version_min.empty() || version_max.empty())) { + std::ostringstream e; + e << "VERSION \"" << version_string + << "\" does not have a version on both sides of \"...\"."; + this->SetError(e.str()); + return false; + } + + this->Makefile->SetPolicyVersion(version_min, version_max); return true; } -- cgit v1.2.1