소스 검색

cmQTWrapCPPCommand: Port away from cmCommand

Ref: #19499
Regina Pfeifer 6 년 전
부모
커밋
56bfb8de5d
3개의 변경된 파일23개의 추가작업 그리고 51개의 파일을 삭제
  1. 1 2
      Source/cmCommands.cxx
  2. 20 21
      Source/cmQTWrapCPPCommand.cxx
  3. 2 28
      Source/cmQTWrapCPPCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -289,8 +289,7 @@ void GetProjectCommands(cmState* state)
                            cm::make_unique<cmTargetLinkDirectoriesCommand>());
   state->AddBuiltinCommand("load_cache",
                            cm::make_unique<cmLoadCacheCommand>());
-  state->AddBuiltinCommand("qt_wrap_cpp",
-                           cm::make_unique<cmQTWrapCPPCommand>());
+  state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand);
   state->AddBuiltinCommand("qt_wrap_ui", cm::make_unique<cmQTWrapUICommand>());
   state->AddBuiltinCommand("remove_definitions",
                            cm::make_unique<cmRemoveDefinitionsCommand>());

+ 20 - 21
Source/cmQTWrapCPPCommand.cxx

@@ -2,45 +2,44 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmQTWrapCPPCommand.h"
 
+#include <utility>
+
 #include "cmCustomCommandLines.h"
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmRange.h"
 #include "cmSourceFile.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-#include <utility>
-
-class cmExecutionStatus;
-
-// cmQTWrapCPPCommand
-bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
-                                     cmExecutionStatus&)
+bool cmQTWrapCPPCommand(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;
   }
 
+  cmMakefile& mf = status.GetMakefile();
+
   // Get the moc executable to run in the custom command.
-  std::string const& moc_exe =
-    this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
+  std::string const& moc_exe = mf.GetRequiredDefinition("QT_MOC_EXECUTABLE");
 
   // Get the variable holding the list of sources.
   std::string const& sourceList = args[1];
-  std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
+  std::string sourceListValue = mf.GetSafeDefinition(sourceList);
 
   // Create a rule for all sources listed.
   for (std::string const& arg : cmMakeRange(args).advance(2)) {
-    cmSourceFile* curr = this->Makefile->GetSource(arg);
+    cmSourceFile* curr = mf.GetSource(arg);
     // if we should wrap the class
     if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
       // Compute the name of the file to generate.
       std::string srcName =
         cmSystemTools::GetFilenameWithoutLastExtension(arg);
-      std::string newName = cmStrCat(
-        this->Makefile->GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
-      cmSourceFile* sf = this->Makefile->GetOrCreateSource(newName, true);
+      std::string newName =
+        cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
+      cmSourceFile* sf = mf.GetOrCreateSource(newName, true);
       if (curr) {
         sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
       }
@@ -51,9 +50,9 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
         hname = arg;
       } else {
         if (curr && curr->GetIsGenerated()) {
-          hname = this->Makefile->GetCurrentBinaryDirectory();
+          hname = mf.GetCurrentBinaryDirectory();
         } else {
-          hname = this->Makefile->GetCurrentSourceDirectory();
+          hname = mf.GetCurrentSourceDirectory();
         }
         hname += "/";
         hname += arg;
@@ -81,13 +80,13 @@ bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
 
       std::string no_main_dependency;
       const char* no_working_dir = nullptr;
-      this->Makefile->AddCustomCommandToOutput(
-        newName, depends, no_main_dependency, commandLines, "Qt Wrapped File",
-        no_working_dir);
+      mf.AddCustomCommandToOutput(newName, depends, no_main_dependency,
+                                  commandLines, "Qt Wrapped File",
+                                  no_working_dir);
     }
   }
 
   // Store the final list of source files.
-  this->Makefile->AddDefinition(sourceList, sourceListValue);
+  mf.AddDefinition(sourceList, sourceListValue);
   return true;
 }

+ 2 - 28
Source/cmQTWrapCPPCommand.h

@@ -8,35 +8,9 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmQTWrapCPPCommand
- * \brief Create moc file rules for Qt classes
- *
- * cmQTWrapCPPCommand is used to create wrappers for Qt classes into
- * normal C++
- */
-class cmQTWrapCPPCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmQTWrapCPPCommand>();
-  }
-
-  /**
-   * 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;
-};
+bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
+                        cmExecutionStatus& status);
 
 #endif