summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorGabor Bencze <b.gabor98@gmail.com>2019-07-25 14:46:18 (GMT)
committerBrad King <brad.king@kitware.com>2019-08-20 18:42:19 (GMT)
commitdc629b5d97cd5486b2b0b385680a163e594922ae (patch)
treecc77de897a01d30358c464a77d4aa517da02e015 /Source
parente6a27adf9f1a17f13c5af888f778fde4cddebfac (diff)
downloadCMake-dc629b5d97cd5486b2b0b385680a163e594922ae.zip
CMake-dc629b5d97cd5486b2b0b385680a163e594922ae.tar.gz
CMake-dc629b5d97cd5486b2b0b385680a163e594922ae.tar.bz2
cmCommand refactor: cmCMakeMinimumRequired
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCMakeMinimumRequired.cxx50
-rw-r--r--Source/cmCMakeMinimumRequired.h30
-rw-r--r--Source/cmCommands.cxx3
3 files changed, 34 insertions, 49 deletions
diff --git a/Source/cmCMakeMinimumRequired.cxx b/Source/cmCMakeMinimumRequired.cxx
index f2eae38..f93c266 100644
--- a/Source/cmCMakeMinimumRequired.cxx
+++ b/Source/cmCMakeMinimumRequired.cxx
@@ -5,26 +5,32 @@
#include <sstream>
#include <stdio.h>
+#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmSystemTools.h"
#include "cmVersion.h"
-class cmExecutionStatus;
+namespace {
+bool EnforceUnknownArguments(std::string const& version_max,
+ std::vector<std::string> const& unknown_arguments,
+ cmExecutionStatus& status);
+}
// cmCMakeMinimumRequired
-bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus&)
+bool cmCMakeMinimumRequired(std::vector<std::string> const& args,
+ cmExecutionStatus& status)
{
// Process arguments.
std::string version_string;
bool doing_version = false;
+ std::vector<std::string> unknown_arguments;
for (std::string const& arg : args) {
if (arg == "VERSION") {
doing_version = true;
} else if (arg == "FATAL_ERROR") {
if (doing_version) {
- this->SetError("called with no value for VERSION.");
+ status.SetError("called with no value for VERSION.");
return false;
}
doing_version = false;
@@ -32,17 +38,17 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
doing_version = false;
version_string = arg;
} else {
- this->UnknownArguments.push_back(arg);
+ unknown_arguments.push_back(arg);
}
}
if (doing_version) {
- this->SetError("called with no value for VERSION.");
+ status.SetError("called with no value for VERSION.");
return false;
}
// Make sure there was a version to check.
if (version_string.empty()) {
- return this->EnforceUnknownArguments(std::string());
+ return EnforceUnknownArguments(std::string(), unknown_arguments, status);
}
// Separate the <min> version and any trailing ...<max> component.
@@ -56,12 +62,13 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
std::ostringstream e;
e << "VERSION \"" << version_string
<< R"(" does not have a version on both sides of "...".)";
- this->SetError(e.str());
+ status.SetError(e.str());
return false;
}
// Save the required version string.
- this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION", version_min);
+ status.GetMakefile().AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
+ version_min);
// Get the current version number.
unsigned int current_major = cmVersion::GetMajorVersion();
@@ -79,7 +86,7 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
&required_minor, &required_patch, &required_tweak) < 2) {
std::ostringstream e;
e << "could not parse VERSION \"" << version_min << "\".";
- this->SetError(e.str());
+ status.SetError(e.str());
return false;
}
@@ -95,32 +102,34 @@ bool cmCMakeMinimumRequired::InitialPass(std::vector<std::string> const& args,
e << "CMake " << version_min
<< " or higher is required. You are running version "
<< cmVersion::GetCMakeVersion();
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
+ status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, e.str());
cmSystemTools::SetFatalErrorOccured();
return true;
}
// The version is not from the future, so enforce unknown arguments.
- if (!this->EnforceUnknownArguments(version_max)) {
+ if (!EnforceUnknownArguments(version_max, unknown_arguments, status)) {
return false;
}
if (required_major < 2 || (required_major == 2 && required_minor < 4)) {
- this->Makefile->IssueMessage(
+ status.GetMakefile().IssueMessage(
MessageType::AUTHOR_WARNING,
"Compatibility with CMake < 2.4 is not supported by CMake >= 3.0.");
- this->Makefile->SetPolicyVersion("2.4", version_max);
+ status.GetMakefile().SetPolicyVersion("2.4", version_max);
} else {
- this->Makefile->SetPolicyVersion(version_min, version_max);
+ status.GetMakefile().SetPolicyVersion(version_min, version_max);
}
return true;
}
-bool cmCMakeMinimumRequired::EnforceUnknownArguments(
- std::string const& version_max)
+namespace {
+bool EnforceUnknownArguments(std::string const& version_max,
+ std::vector<std::string> const& unknown_arguments,
+ cmExecutionStatus& status)
{
- if (this->UnknownArguments.empty()) {
+ if (unknown_arguments.empty()) {
return true;
}
@@ -149,7 +158,8 @@ bool cmCMakeMinimumRequired::EnforceUnknownArguments(
}
std::ostringstream e;
- e << "called with unknown argument \"" << this->UnknownArguments[0] << "\".";
- this->SetError(e.str());
+ e << "called with unknown argument \"" << unknown_arguments[0] << "\".";
+ status.SetError(e.str());
return false;
}
+}
diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h
index 3881133..53f78f6 100644
--- a/Source/cmCMakeMinimumRequired.h
+++ b/Source/cmCMakeMinimumRequired.h
@@ -8,38 +8,14 @@
#include <string>
#include <vector>
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
class cmExecutionStatus;
-/** \class cmCMakeMinimumRequired
+/**
* \brief cmake_minimum_required command
*
* cmCMakeMinimumRequired implements the cmake_minimum_required CMake command
*/
-class cmCMakeMinimumRequired : public cmCommand
-{
-public:
- /**
- * This is a virtual constructor for the command.
- */
- std::unique_ptr<cmCommand> Clone() override
- {
- return cm::make_unique<cmCMakeMinimumRequired>();
- }
-
- /**
- * This is called when the command is first encountered in
- * the CMakeLists.txt file.
- */
- bool InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& status) override;
-
-private:
- std::vector<std::string> UnknownArguments;
- bool EnforceUnknownArguments(std::string const& version_max);
-};
+bool cmCMakeMinimumRequired(std::vector<std::string> const& args,
+ cmExecutionStatus& status);
#endif
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx
index 540f1ac..996ce97 100644
--- a/Source/cmCommands.cxx
+++ b/Source/cmCommands.cxx
@@ -117,8 +117,7 @@
void GetScriptingCommands(cmState* state)
{
state->AddBuiltinCommand("break", cmBreakCommand);
- state->AddBuiltinCommand("cmake_minimum_required",
- cm::make_unique<cmCMakeMinimumRequired>());
+ state->AddBuiltinCommand("cmake_minimum_required", cmCMakeMinimumRequired);
state->AddBuiltinCommand("cmake_policy",
cm::make_unique<cmCMakePolicyCommand>());
state->AddBuiltinCommand("configure_file",