浏览代码

cmGetTargetPropertyCommand: Port away from cmCommand

Ref: #19499
Regina Pfeifer 6 年之前
父节点
当前提交
0b95c64e43
共有 3 个文件被更改,包括 16 次插入34 次删除
  1. 1 2
      Source/cmCommands.cxx
  2. 13 13
      Source/cmGetTargetPropertyCommand.cxx
  3. 2 19
      Source/cmGetTargetPropertyCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -229,8 +229,7 @@ void GetProjectCommands(cmState* state)
   state->AddBuiltinCommand("enable_testing", cmEnableTestingCommand);
   state->AddBuiltinCommand("get_source_file_property",
                            cmGetSourceFilePropertyCommand);
-  state->AddBuiltinCommand("get_target_property",
-                           cm::make_unique<cmGetTargetPropertyCommand>());
+  state->AddBuiltinCommand("get_target_property", cmGetTargetPropertyCommand);
   state->AddBuiltinCommand("get_test_property",
                            cm::make_unique<cmGetTestPropertyCommand>());
   state->AddBuiltinCommand("include_directories",

+ 13 - 13
Source/cmGetTargetPropertyCommand.cxx

@@ -4,6 +4,7 @@
 
 #include <sstream>
 
+#include "cmExecutionStatus.h"
 #include "cmListFileCache.h"
 #include "cmMakefile.h"
 #include "cmMessageType.h"
@@ -11,32 +12,31 @@
 #include "cmTarget.h"
 #include "cmTargetPropertyComputer.h"
 
-class cmExecutionStatus;
 class cmMessenger;
 
-// cmSetTargetPropertyCommand
-bool cmGetTargetPropertyCommand::InitialPass(
-  std::vector<std::string> const& args, cmExecutionStatus&)
+bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
+                                cmExecutionStatus& status)
 {
   if (args.size() != 3) {
-    this->SetError("called with incorrect number of arguments");
+    status.SetError("called with incorrect number of arguments");
     return false;
   }
   std::string const& var = args[0];
   std::string const& targetName = args[1];
   std::string prop;
   bool prop_exists = false;
+  cmMakefile& mf = status.GetMakefile();
 
-  if (cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) {
+  if (cmTarget* tgt = mf.FindTargetToUse(targetName)) {
     if (args[2] == "ALIASED_TARGET") {
-      if (this->Makefile->IsAlias(targetName)) {
+      if (mf.IsAlias(targetName)) {
         prop = tgt->GetName();
         prop_exists = true;
       }
     } else if (!args[2].empty()) {
       const char* prop_cstr = nullptr;
-      cmListFileBacktrace bt = this->Makefile->GetBacktrace();
-      cmMessenger* messenger = this->Makefile->GetMessenger();
+      cmListFileBacktrace bt = mf.GetBacktrace();
+      cmMessenger* messenger = mf.GetMessenger();
       if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2],
                                                     messenger, bt)) {
         prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
@@ -53,7 +53,7 @@ bool cmGetTargetPropertyCommand::InitialPass(
     bool issueMessage = false;
     std::ostringstream e;
     MessageType messageType = MessageType::AUTHOR_WARNING;
-    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0045)) {
+    switch (mf.GetPolicyStatus(cmPolicies::CMP0045)) {
       case cmPolicies::WARN:
         issueMessage = true;
         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0045) << "\n";
@@ -68,16 +68,16 @@ bool cmGetTargetPropertyCommand::InitialPass(
     if (issueMessage) {
       e << "get_target_property() called with non-existent target \""
         << targetName << "\".";
-      this->Makefile->IssueMessage(messageType, e.str());
+      mf.IssueMessage(messageType, e.str());
       if (messageType == MessageType::FATAL_ERROR) {
         return false;
       }
     }
   }
   if (prop_exists) {
-    this->Makefile->AddDefinition(var, prop);
+    mf.AddDefinition(var, prop);
     return true;
   }
-  this->Makefile->AddDefinition(var, var + "-NOTFOUND");
+  mf.AddDefinition(var, var + "-NOTFOUND");
   return true;
 }

+ 2 - 19
Source/cmGetTargetPropertyCommand.h

@@ -8,26 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-class cmGetTargetPropertyCommand : public cmCommand
-{
-public:
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmGetTargetPropertyCommand>();
-  }
-
-  /**
-   * This is called when the command is first encountered in
-   * the input file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) override;
-};
+bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
+                                cmExecutionStatus& status);
 
 #endif