mirror of
https://github.com/reactos/CMake.git
synced 2025-02-09 05:16:07 +00:00
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).
This commit is contained in:
parent
6792c7787a
commit
8dc97acb03
@ -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;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<std::string> UnknownArguments;
|
||||
bool EnforceUnknownArguments();
|
||||
bool EnforceUnknownArguments(std::string const& version_max);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
1
Tests/RunCMake/cmake_minimum_required/Future.cmake
Normal file
1
Tests/RunCMake/cmake_minimum_required/Future.cmake
Normal file
@ -0,0 +1 @@
|
||||
cmake_minimum_required(VERSION 3.11...99.0 SOME_FUTURE_OPTION)
|
@ -2,6 +2,8 @@ include(RunCMake)
|
||||
|
||||
run_cmake(Before24)
|
||||
run_cmake(CompatBefore24)
|
||||
run_cmake(Future)
|
||||
run_cmake(PolicyBefore24)
|
||||
run_cmake(Range)
|
||||
run_cmake(RangeBad)
|
||||
run_cmake(Unknown)
|
||||
|
1
Tests/RunCMake/cmake_minimum_required/Unknown-result.txt
Normal file
1
Tests/RunCMake/cmake_minimum_required/Unknown-result.txt
Normal file
@ -0,0 +1 @@
|
||||
1
|
4
Tests/RunCMake/cmake_minimum_required/Unknown-stderr.txt
Normal file
4
Tests/RunCMake/cmake_minimum_required/Unknown-stderr.txt
Normal file
@ -0,0 +1,4 @@
|
||||
^CMake Error at Unknown.cmake:1 \(cmake_minimum_required\):
|
||||
cmake_minimum_required called with unknown argument "SOME_UNKNOWN_OPTION".
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)$
|
1
Tests/RunCMake/cmake_minimum_required/Unknown.cmake
Normal file
1
Tests/RunCMake/cmake_minimum_required/Unknown.cmake
Normal file
@ -0,0 +1 @@
|
||||
cmake_minimum_required(VERSION 3.11 SOME_UNKNOWN_OPTION)
|
Loading…
x
Reference in New Issue
Block a user