diff options
author | Brad King <brad.king@kitware.com> | 2018-03-26 15:12:50 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-03-26 15:31:08 (GMT) |
commit | 8dc97acb03db6d3d2f9effd84fd81432a68aa23c (patch) | |
tree | c9f3414a235dc540c6c7121465fa17d7145a3e74 /Source | |
parent | 6792c7787aedc0fb2a32b6ca563917f7447f2e80 (diff) | |
download | CMake-8dc97acb03db6d3d2f9effd84fd81432a68aa23c.zip CMake-8dc97acb03db6d3d2f9effd84fd81432a68aa23c.tar.gz CMake-8dc97acb03db6d3d2f9effd84fd81432a68aa23c.tar.bz2 |
cmake_minimum_required: Tolerate unknown future arguments
When a `...<max>` version is given that is larger than the running
version of CMake, assume that the project is aware of a newer version of
CMake and that any unknown arguments are future arguments. This will
allow future versions of CMake to add arguments to the command that
projects can use without introducing errors in older versions of CMake
(back to 3.12).
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCMakeMinimumRequired.cxx | 45 | ||||
-rw-r--r-- | Source/cmCMakeMinimumRequired.h | 2 |
2 files changed, 36 insertions, 11 deletions
diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx index c4834a8..2b51976 100644 --- a/Source/cmCMakeMinimumRequired.cxx +++ b/Source/cmCMakeMinimumRequired.cxx @@ -42,7 +42,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, // Make sure there was a version to check. if (version_string.empty()) { - return this->EnforceUnknownArguments(); + return this->EnforceUnknownArguments(std::string()); } // Separate the <min> version and any trailing ...<max> component. @@ -102,7 +102,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, } // The version is not from the future, so enforce unknown arguments. - if (!this->EnforceUnknownArguments()) { + if (!this->EnforceUnknownArguments(version_max)) { return false; } @@ -118,14 +118,39 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args, return true; } -bool cmCMakeMinimumRequired::EnforceUnknownArguments() +bool cmCMakeMinimumRequired::EnforceUnknownArguments( + std::string const& version_max) { - if (!this->UnknownArguments.empty()) { - std::ostringstream e; - e << "called with unknown argument \"" << this->UnknownArguments[0] - << "\"."; - this->SetError(e.str()); - return false; + if (this->UnknownArguments.empty()) { + return true; } - return true; + + // Consider the max version if at least two components were given. + unsigned int max_major = 0; + unsigned int max_minor = 0; + unsigned int max_patch = 0; + unsigned int max_tweak = 0; + if (sscanf(version_max.c_str(), "%u.%u.%u.%u", &max_major, &max_minor, + &max_patch, &max_tweak) >= 2) { + unsigned int current_major = cmVersion::GetMajorVersion(); + unsigned int current_minor = cmVersion::GetMinorVersion(); + unsigned int current_patch = cmVersion::GetPatchVersion(); + unsigned int current_tweak = cmVersion::GetTweakVersion(); + + if ((current_major < max_major) || + (current_major == max_major && current_minor < max_minor) || + (current_major == max_major && current_minor == max_minor && + current_patch < max_patch) || + (current_major == max_major && current_minor == max_minor && + current_patch == max_patch && current_tweak < max_tweak)) { + // A ...<max> version was given that is larger than the current + // version of CMake, so tolerate unknown arguments. + return true; + } + } + + std::ostringstream e; + e << "called with unknown argument \"" << this->UnknownArguments[0] << "\"."; + this->SetError(e.str()); + return false; } diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h index 18d9460..f9b61e1 100644 --- a/Source/cmCMakeMinimumRequired.h +++ b/Source/cmCMakeMinimumRequired.h @@ -34,7 +34,7 @@ public: private: std::vector<std::string> UnknownArguments; - bool EnforceUnknownArguments(); + bool EnforceUnknownArguments(std::string const& version_max); }; #endif |