From 41b0d60f48c3d8d882ec25b56d638b392121fcc8 Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Thu, 12 Sep 2019 10:08:01 +0200 Subject: cmDefinePropertyCommand: Port away from cmCommand Ref: #19499 --- Source/cmCommands.cxx | 3 +-- Source/cmDefinePropertyCommand.cxx | 51 +++++++++++++++++--------------------- Source/cmDefinePropertyCommand.h | 26 ++----------------- 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index f675a93..1e8ee9e 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -224,8 +224,7 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("add_test", cmAddTestCommand); state->AddBuiltinCommand("build_command", cmBuildCommand); state->AddBuiltinCommand("create_test_sourcelist", cmCreateTestSourceList); - state->AddBuiltinCommand("define_property", - cm::make_unique()); + state->AddBuiltinCommand("define_property", cmDefinePropertyCommand); state->AddBuiltinCommand("enable_language", cm::make_unique()); state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand); diff --git a/Source/cmDefinePropertyCommand.cxx b/Source/cmDefinePropertyCommand.cxx index 86a83da..f4e4fda 100644 --- a/Source/cmDefinePropertyCommand.cxx +++ b/Source/cmDefinePropertyCommand.cxx @@ -2,19 +2,17 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmDefinePropertyCommand.h" -#include - +#include "cmExecutionStatus.h" #include "cmMakefile.h" #include "cmProperty.h" #include "cmState.h" +#include "cmStringAlgorithms.h" -class cmExecutionStatus; - -bool cmDefinePropertyCommand::InitialPass(std::vector const& args, - cmExecutionStatus&) +bool cmDefinePropertyCommand(std::vector const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } @@ -37,17 +35,17 @@ bool cmDefinePropertyCommand::InitialPass(std::vector const& args, } else if (scope_arg == "CACHED_VARIABLE") { scope = cmProperty::CACHED_VARIABLE; } else { - std::ostringstream e; - e << "given invalid scope " << scope_arg << ". " - << "Valid scopes are " - << "GLOBAL, DIRECTORY, TARGET, SOURCE, " - << "TEST, VARIABLE, CACHED_VARIABLE."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid scope ", scope_arg, + ". Valid scopes are GLOBAL, DIRECTORY, TARGET, " + "SOURCE, TEST, VARIABLE, CACHED_VARIABLE.")); return false; } // Parse remaining arguments. bool inherited = false; + std::string PropertyName; + std::string BriefDocs; + std::string FullDocs; enum Doing { DoingNone, @@ -68,39 +66,36 @@ bool cmDefinePropertyCommand::InitialPass(std::vector const& args, inherited = true; } else if (doing == DoingProperty) { doing = DoingNone; - this->PropertyName = args[i]; + PropertyName = args[i]; } else if (doing == DoingBrief) { - this->BriefDocs += args[i]; + BriefDocs += args[i]; } else if (doing == DoingFull) { - this->FullDocs += args[i]; + FullDocs += args[i]; } else { - std::ostringstream e; - e << "given invalid argument \"" << args[i] << "\"."; - this->SetError(e.str()); + status.SetError(cmStrCat("given invalid argument \"", args[i], "\".")); return false; } } // Make sure a property name was found. - if (this->PropertyName.empty()) { - this->SetError("not given a PROPERTY argument."); + if (PropertyName.empty()) { + status.SetError("not given a PROPERTY argument."); return false; } // Make sure documentation was given. - if (this->BriefDocs.empty()) { - this->SetError("not given a BRIEF_DOCS argument."); + if (BriefDocs.empty()) { + status.SetError("not given a BRIEF_DOCS argument."); return false; } - if (this->FullDocs.empty()) { - this->SetError("not given a FULL_DOCS argument."); + if (FullDocs.empty()) { + status.SetError("not given a FULL_DOCS argument."); return false; } // Actually define the property. - this->Makefile->GetState()->DefineProperty( - this->PropertyName, scope, this->BriefDocs.c_str(), this->FullDocs.c_str(), - inherited); + status.GetMakefile().GetState()->DefineProperty( + PropertyName, scope, BriefDocs.c_str(), FullDocs.c_str(), inherited); return true; } diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h index 36f97df..60dd76a 100644 --- a/Source/cmDefinePropertyCommand.h +++ b/Source/cmDefinePropertyCommand.h @@ -8,31 +8,9 @@ #include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -class cmDefinePropertyCommand : public cmCommand -{ -public: - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This is called when the command is first encountered in - * the input file. - */ - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; - -private: - std::string PropertyName; - std::string BriefDocs; - std::string FullDocs; -}; +bool cmDefinePropertyCommand(std::vector const& args, + cmExecutionStatus& status); #endif -- cgit v0.12