Răsfoiți Sursa

cmMakefile: Simplify Add*Command and adopt to cmAddCustom*Command

NAKAMURA Takumi 4 ani în urmă
părinte
comite
3bb2542535

+ 18 - 10
Source/cmAddCustomCommandCommand.cxx

@@ -4,6 +4,9 @@
 
 #include <sstream>
 #include <unordered_set>
+#include <utility>
+
+#include <cm/memory>
 
 #include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
@@ -316,20 +319,25 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
   }
 
   // Choose which mode of the command to use.
-  bool escapeOldStyle = !verbatim;
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetByproducts(byproducts);
+  cc->SetCommandLines(commandLines);
+  cc->SetComment(comment);
+  cc->SetWorkingDirectory(working.c_str());
+  cc->SetEscapeOldStyle(!verbatim);
+  cc->SetUsesTerminal(uses_terminal);
+  cc->SetDepfile(depfile);
+  cc->SetJobPool(job_pool);
+  cc->SetCommandExpandLists(command_expand_lists);
   if (source.empty() && output.empty()) {
     // Source is empty, use the target.
-    std::vector<std::string> no_depends;
-    mf.AddCustomCommandToTarget(target, byproducts, no_depends, commandLines,
-                                cctype, comment, working.c_str(),
-                                escapeOldStyle, uses_terminal, depfile,
-                                job_pool, command_expand_lists);
+    mf.AddCustomCommandToTarget(target, cctype, std::move(cc));
   } else if (target.empty()) {
     // Target is empty, use the output.
-    mf.AddCustomCommandToOutput(
-      output, byproducts, depends, main_dependency, implicit_depends,
-      commandLines, comment, working.c_str(), nullptr, false, escapeOldStyle,
-      uses_terminal, command_expand_lists, depfile, job_pool);
+    cc->SetOutputs(output);
+    cc->SetDepends(depends);
+    cc->SetImplicitDepends(implicit_depends);
+    mf.AddCustomCommandToOutput(main_dependency, std::move(cc));
   } else if (!byproducts.empty()) {
     status.SetError("BYPRODUCTS may not be specified with SOURCE signatures");
     return false;

+ 15 - 5
Source/cmAddCustomTargetCommand.cxx

@@ -4,6 +4,9 @@
 
 #include <utility>
 
+#include <cm/memory>
+
+#include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmExecutionStatus.h"
 #include "cmGeneratorExpression.h"
@@ -210,11 +213,18 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args,
   }
 
   // Add the utility target to the makefile.
-  bool escapeOldStyle = !verbatim;
-  cmTarget* target = mf.AddUtilityCommand(
-    targetName, excludeFromAll, working_directory.c_str(), byproducts, depends,
-    commandLines, escapeOldStyle, comment, uses_terminal, command_expand_lists,
-    job_pool);
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetWorkingDirectory(working_directory.c_str());
+  cc->SetByproducts(byproducts);
+  cc->SetDepends(depends);
+  cc->SetCommandLines(commandLines);
+  cc->SetEscapeOldStyle(!verbatim);
+  cc->SetComment(comment);
+  cc->SetUsesTerminal(uses_terminal);
+  cc->SetCommandExpandLists(command_expand_lists);
+  cc->SetJobPool(job_pool);
+  cmTarget* target =
+    mf.AddUtilityCommand(targetName, excludeFromAll, std::move(cc));
 
   // Add additional user-specified source files to the target.
   target->AddSources(sources);

+ 12 - 13
Source/cmCPluginAPI.cxx

@@ -223,9 +223,10 @@ static void CCONV cmAddUtilityCommand(void* arg, const char* utilityName,
   }
 
   // Pass the call to the makefile instance.
-  std::vector<std::string> no_byproducts;
-  mf->AddUtilityCommand(utilityName, !all, nullptr, no_byproducts, depends2,
-                        commandLines);
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetDepends(depends2);
+  cc->SetCommandLines(commandLines);
+  mf->AddUtilityCommand(utilityName, !all, std::move(cc));
 }
 
 static void CCONV cmAddCustomCommand(void* arg, const char* source,
@@ -299,10 +300,11 @@ static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output,
   }
 
   // Pass the call to the makefile instance.
-  const char* no_comment = nullptr;
-  const char* no_working_dir = nullptr;
-  mf->AddCustomCommandToOutput(output, depends2, main_dependency, commandLines,
-                               no_comment, no_working_dir);
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetOutputs(output);
+  cc->SetDepends(depends2);
+  cc->SetCommandLines(commandLines);
+  mf->AddCustomCommandToOutput(main_dependency, std::move(cc));
 }
 
 static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
@@ -340,12 +342,9 @@ static void CCONV cmAddCustomCommandToTarget(void* arg, const char* target,
   }
 
   // Pass the call to the makefile instance.
-  std::vector<std::string> no_byproducts;
-  std::vector<std::string> no_depends;
-  const char* no_comment = nullptr;
-  const char* no_working_dir = nullptr;
-  mf->AddCustomCommandToTarget(target, no_byproducts, no_depends, commandLines,
-                               cctype, no_comment, no_working_dir);
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetCommandLines(commandLines);
+  mf->AddCustomCommandToTarget(target, cctype, std::move(cc));
 }
 
 static void addLinkLibrary(cmMakefile* mf, std::string const& target,

+ 15 - 6
Source/cmFLTKWrapUICommand.cxx

@@ -3,7 +3,11 @@
 #include "cmFLTKWrapUICommand.h"
 
 #include <cstddef>
+#include <utility>
 
+#include <cm/memory>
+
+#include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmExecutionStatus.h"
 #include "cmListFileCache.h"
@@ -95,12 +99,17 @@ bool cmFLTKWrapUICommand(std::vector<std::string> const& args,
 
       // Add command for generating the .h and .cxx files
       std::string no_main_dependency;
-      const char* no_comment = nullptr;
-      const char* no_working_dir = nullptr;
-      mf.AddCustomCommandToOutput(cxxres, depends, no_main_dependency,
-                                  commandLines, no_comment, no_working_dir);
-      mf.AddCustomCommandToOutput(hname, depends, no_main_dependency,
-                                  commandLines, no_comment, no_working_dir);
+
+      auto hcc = cm::make_unique<cmCustomCommand>();
+      hcc->SetDepends(depends);
+      hcc->SetCommandLines(commandLines);
+      auto ccc = cm::make_unique<cmCustomCommand>(*hcc);
+
+      hcc->SetOutputs(cxxres);
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(hcc));
+
+      ccc->SetOutputs(hname);
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(ccc));
 
       cmSourceFile* sf = mf.GetSource(cxxres);
       sf->AddDepend(hname);

+ 34 - 92
Source/cmMakefile.cxx

@@ -1054,13 +1054,12 @@ cmTarget* cmMakefile::GetCustomCommandTarget(
 }
 
 cmTarget* cmMakefile::AddCustomCommandToTarget(
-  const std::string& target, const std::vector<std::string>& byproducts,
-  const std::vector<std::string>& depends,
-  const cmCustomCommandLines& commandLines, cmCustomCommandType type,
-  const char* comment, const char* workingDir, bool escapeOldStyle,
-  bool uses_terminal, const std::string& depfile, const std::string& job_pool,
-  bool command_expand_lists, bool stdPipesUTF8)
+  const std::string& target, cmCustomCommandType type,
+  std::unique_ptr<cmCustomCommand> cc)
 {
+  const auto& byproducts = cc->GetByproducts();
+  const auto& commandLines = cc->GetCommandLines();
+
   cmTarget* t = this->GetCustomCommandTarget(
     target, cmObjectLibraryCommands::Reject, this->Backtrace);
 
@@ -1072,21 +1071,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
   // Always create the byproduct sources and mark them generated.
   this->CreateGeneratedOutputs(byproducts);
 
-  auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116);
-
-  auto cc = cm::make_unique<cmCustomCommand>();
-  cc->SetByproducts(byproducts);
-  cc->SetDepends(depends);
-  cc->SetCommandLines(commandLines);
-  cc->SetComment(comment);
-  cc->SetWorkingDirectory(workingDir);
-  cc->SetEscapeOldStyle(escapeOldStyle);
-  cc->SetUsesTerminal(uses_terminal);
-  cc->SetDepfile(depfile);
-  cc->SetJobPool(job_pool);
-  cc->SetCommandExpandLists(command_expand_lists);
-  cc->SetStdPipesUTF8(stdPipesUTF8);
-  cc->SetCMP0116Status(cmp0116);
+  cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116));
 
   // Dispatch command creation to allow generator expressions in outputs.
   this->AddGeneratorAction(
@@ -1103,31 +1088,13 @@ cmTarget* cmMakefile::AddCustomCommandToTarget(
 }
 
 void cmMakefile::AddCustomCommandToOutput(
-  const std::string& output, const std::vector<std::string>& depends,
-  const std::string& main_dependency, const cmCustomCommandLines& commandLines,
-  const char* comment, const char* workingDir,
-  const CommandSourceCallback& callback, bool replace, bool escapeOldStyle,
-  bool uses_terminal, bool command_expand_lists, const std::string& depfile,
-  const std::string& job_pool, bool stdPipesUTF8)
+  const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc,
+  const CommandSourceCallback& callback, bool replace)
 {
-  std::vector<std::string> no_byproducts;
-  cmImplicitDependsList no_implicit_depends;
-  this->AddCustomCommandToOutput(
-    { output }, no_byproducts, depends, main_dependency, no_implicit_depends,
-    commandLines, comment, workingDir, callback, replace, escapeOldStyle,
-    uses_terminal, command_expand_lists, depfile, job_pool, stdPipesUTF8);
-}
+  const auto& outputs = cc->GetOutputs();
+  const auto& byproducts = cc->GetByproducts();
+  const auto& commandLines = cc->GetCommandLines();
 
-void cmMakefile::AddCustomCommandToOutput(
-  const std::vector<std::string>& outputs,
-  const std::vector<std::string>& byproducts,
-  const std::vector<std::string>& depends, const std::string& main_dependency,
-  const cmImplicitDependsList& implicit_depends,
-  const cmCustomCommandLines& commandLines, const char* comment,
-  const char* workingDir, const CommandSourceCallback& callback, bool replace,
-  bool escapeOldStyle, bool uses_terminal, bool command_expand_lists,
-  const std::string& depfile, const std::string& job_pool, bool stdPipesUTF8)
-{
   // Make sure there is at least one output.
   if (outputs.empty()) {
     cmSystemTools::Error("Attempt to add a custom rule with no output!");
@@ -1143,23 +1110,7 @@ void cmMakefile::AddCustomCommandToOutput(
   this->CreateGeneratedOutputs(outputs);
   this->CreateGeneratedOutputs(byproducts);
 
-  auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116);
-
-  auto cc = cm::make_unique<cmCustomCommand>();
-  cc->SetOutputs(outputs);
-  cc->SetByproducts(byproducts);
-  cc->SetDepends(depends);
-  cc->SetImplicitDepends(implicit_depends);
-  cc->SetCommandLines(commandLines);
-  cc->SetComment(comment);
-  cc->SetWorkingDirectory(workingDir);
-  cc->SetEscapeOldStyle(escapeOldStyle);
-  cc->SetUsesTerminal(uses_terminal);
-  cc->SetCommandExpandLists(command_expand_lists);
-  cc->SetDepfile(depfile);
-  cc->SetJobPool(job_pool);
-  cc->SetStdPipesUTF8(stdPipesUTF8);
-  cc->SetCMP0116Status(cmp0116);
+  cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116));
 
   // Dispatch command creation to allow generator expressions in outputs.
   this->AddGeneratorAction(
@@ -1182,16 +1133,19 @@ void cmMakefile::AddCustomCommandOldStyle(
   const std::vector<std::string>& depends, const std::string& source,
   const cmCustomCommandLines& commandLines, const char* comment)
 {
+  auto cc = cm::make_unique<cmCustomCommand>();
+  cc->SetDepends(depends);
+  cc->SetCommandLines(commandLines);
+  cc->SetComment(comment);
+
   // Translate the old-style signature to one of the new-style
   // signatures.
   if (source == target) {
     // In the old-style signature if the source and target were the
     // same then it added a post-build rule to the target.  Preserve
     // this behavior.
-    std::vector<std::string> no_byproducts;
-    this->AddCustomCommandToTarget(
-      target, no_byproducts, depends, commandLines,
-      cmCustomCommandType::POST_BUILD, comment, nullptr);
+    this->AddCustomCommandToTarget(target, cmCustomCommandType::POST_BUILD,
+                                   std::move(cc));
     return;
   }
 
@@ -1223,18 +1177,20 @@ void cmMakefile::AddCustomCommandOldStyle(
   if (sourceFiles.find(source)) {
     // The source looks like a real file.  Use it as the main dependency.
     for (std::string const& output : outputs) {
-      this->AddCustomCommandToOutput(output, depends, source, commandLines,
-                                     comment, nullptr, addRuleFileToTarget);
+      auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
+      cc1->SetOutputs(output);
+      this->AddCustomCommandToOutput(source, std::move(cc1),
+                                     addRuleFileToTarget);
     }
   } else {
     std::string no_main_dependency;
-    std::vector<std::string> depends2 = depends;
-    depends2.push_back(source);
+    cc->AppendDepends({ source });
 
     // The source may not be a real file.  Do not use a main dependency.
     for (std::string const& output : outputs) {
-      this->AddCustomCommandToOutput(output, depends2, no_main_dependency,
-                                     commandLines, comment, nullptr,
+      auto cc1 = cm::make_unique<cmCustomCommand>(*cc);
+      cc1->SetOutputs(output);
+      this->AddCustomCommandToOutput(no_main_dependency, std::move(cc1),
                                      addRuleFileToTarget);
     }
   }
@@ -1257,14 +1213,13 @@ void cmMakefile::AppendCustomCommandToOutput(
   }
 }
 
-cmTarget* cmMakefile::AddUtilityCommand(
-  const std::string& utilityName, bool excludeFromAll, const char* workingDir,
-  const std::vector<std::string>& byproducts,
-  const std::vector<std::string>& depends,
-  const cmCustomCommandLines& commandLines, bool escapeOldStyle,
-  const char* comment, bool uses_terminal, bool command_expand_lists,
-  const std::string& job_pool, bool stdPipesUTF8)
+cmTarget* cmMakefile::AddUtilityCommand(const std::string& utilityName,
+                                        bool excludeFromAll,
+                                        std::unique_ptr<cmCustomCommand> cc)
 {
+  const auto& depends = cc->GetDepends();
+  const auto& byproducts = cc->GetByproducts();
+  const auto& commandLines = cc->GetCommandLines();
   cmTarget* target = this->AddNewUtilityTarget(utilityName, excludeFromAll);
 
   // Validate custom commands.
@@ -1276,20 +1231,7 @@ cmTarget* cmMakefile::AddUtilityCommand(
   // Always create the byproduct sources and mark them generated.
   this->CreateGeneratedOutputs(byproducts);
 
-  auto cmp0116 = this->GetPolicyStatus(cmPolicies::CMP0116);
-
-  auto cc = cm::make_unique<cmCustomCommand>();
-  cc->SetWorkingDirectory(workingDir);
-  cc->SetByproducts(byproducts);
-  cc->SetDepends(depends);
-  cc->SetCommandLines(commandLines);
-  cc->SetEscapeOldStyle(escapeOldStyle);
-  cc->SetComment(comment);
-  cc->SetUsesTerminal(uses_terminal);
-  cc->SetCommandExpandLists(command_expand_lists);
-  cc->SetJobPool(job_pool);
-  cc->SetStdPipesUTF8(stdPipesUTF8);
-  cc->SetCMP0116Status(cmp0116);
+  cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116));
 
   // Dispatch command creation to allow generator expressions in outputs.
   this->AddGeneratorAction(

+ 8 - 36
Source/cmMakefile.h

@@ -199,14 +199,9 @@ public:
    * Dispatch adding a custom PRE_BUILD, PRE_LINK, or POST_BUILD command to a
    * target.
    */
-  cmTarget* AddCustomCommandToTarget(
-    const std::string& target, const std::vector<std::string>& byproducts,
-    const std::vector<std::string>& depends,
-    const cmCustomCommandLines& commandLines, cmCustomCommandType type,
-    const char* comment, const char* workingDir, bool escapeOldStyle = true,
-    bool uses_terminal = false, const std::string& depfile = "",
-    const std::string& job_pool = "", bool command_expand_lists = false,
-    bool stdPipesUTF8 = false);
+  cmTarget* AddCustomCommandToTarget(const std::string& target,
+                                     cmCustomCommandType type,
+                                     std::unique_ptr<cmCustomCommand> cc);
 
   /**
    * Called for each file with custom command.
@@ -217,26 +212,8 @@ public:
    * Dispatch adding a custom command to a source file.
    */
   void AddCustomCommandToOutput(
-    const std::string& output, const std::vector<std::string>& depends,
-    const std::string& main_dependency,
-    const cmCustomCommandLines& commandLines, const char* comment,
-    const char* workingDir, const CommandSourceCallback& callback = nullptr,
-    bool replace = false, bool escapeOldStyle = true,
-    bool uses_terminal = false, bool command_expand_lists = false,
-    const std::string& depfile = "", const std::string& job_pool = "",
-    bool stdPipesUTF8 = false);
-  void AddCustomCommandToOutput(
-    const std::vector<std::string>& outputs,
-    const std::vector<std::string>& byproducts,
-    const std::vector<std::string>& depends,
-    const std::string& main_dependency,
-    const cmImplicitDependsList& implicit_depends,
-    const cmCustomCommandLines& commandLines, const char* comment,
-    const char* workingDir, const CommandSourceCallback& callback = nullptr,
-    bool replace = false, bool escapeOldStyle = true,
-    bool uses_terminal = false, bool command_expand_lists = false,
-    const std::string& depfile = "", const std::string& job_pool = "",
-    bool stdPipesUTF8 = false);
+    const std::string& main_dependency, std::unique_ptr<cmCustomCommand> cc,
+    const CommandSourceCallback& callback = nullptr, bool replace = false);
   void AddCustomCommandOldStyle(const std::string& target,
                                 const std::vector<std::string>& outputs,
                                 const std::vector<std::string>& depends,
@@ -284,14 +261,9 @@ public:
    * Dispatch adding a utility to the build.  A utility target is a command
    * that is run every time the target is built.
    */
-  cmTarget* AddUtilityCommand(
-    const std::string& utilityName, bool excludeFromAll,
-    const char* workingDir, const std::vector<std::string>& byproducts,
-    const std::vector<std::string>& depends,
-    const cmCustomCommandLines& commandLines, bool escapeOldStyle = true,
-    const char* comment = nullptr, bool uses_terminal = false,
-    bool command_expand_lists = false, const std::string& job_pool = "",
-    bool stdPipesUTF8 = false);
+  cmTarget* AddUtilityCommand(const std::string& utilityName,
+                              bool excludeFromAll,
+                              std::unique_ptr<cmCustomCommand> cc);
 
   /**
    * Add a subdirectory to the build.

+ 11 - 4
Source/cmQTWrapCPPCommand.cxx

@@ -2,6 +2,11 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmQTWrapCPPCommand.h"
 
+#include <utility>
+
+#include <cm/memory>
+
+#include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmExecutionStatus.h"
 #include "cmMakefile.h"
@@ -71,10 +76,12 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
       depends.push_back(hname);
 
       std::string no_main_dependency;
-      const char* no_working_dir = nullptr;
-      mf.AddCustomCommandToOutput(newName, depends, no_main_dependency,
-                                  commandLines, "Qt Wrapped File",
-                                  no_working_dir);
+      auto cc = cm::make_unique<cmCustomCommand>();
+      cc->SetOutputs(newName);
+      cc->SetDepends(depends);
+      cc->SetCommandLines(commandLines);
+      cc->SetComment("Qt Wrapped File");
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
     }
   }
 

+ 20 - 8
Source/cmQTWrapUICommand.cxx

@@ -2,6 +2,11 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmQTWrapUICommand.h"
 
+#include <utility>
+
+#include <cm/memory>
+
+#include "cmCustomCommand.h"
 #include "cmCustomCommandLines.h"
 #include "cmExecutionStatus.h"
 #include "cmMakefile.h"
@@ -84,19 +89,26 @@ bool cmQTWrapUICommand(std::vector<std::string> const& args,
       std::vector<std::string> depends;
       depends.push_back(uiName);
       std::string no_main_dependency;
-      const char* no_comment = nullptr;
-      const char* no_working_dir = nullptr;
-      mf.AddCustomCommandToOutput(hName, depends, no_main_dependency,
-                                  hCommandLines, no_comment, no_working_dir);
+      auto cc = cm::make_unique<cmCustomCommand>();
+      cc->SetOutputs(hName);
+      cc->SetDepends(depends);
+      cc->SetCommandLines(hCommandLines);
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
 
       depends.push_back(hName);
-      mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency,
-                                  cxxCommandLines, no_comment, no_working_dir);
+      cc = cm::make_unique<cmCustomCommand>();
+      cc->SetOutputs(cxxName);
+      cc->SetDepends(depends);
+      cc->SetCommandLines(cxxCommandLines);
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
 
       depends.clear();
       depends.push_back(hName);
-      mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency,
-                                  mocCommandLines, no_comment, no_working_dir);
+      cc = cm::make_unique<cmCustomCommand>();
+      cc->SetOutputs(mocName);
+      cc->SetDepends(depends);
+      cc->SetCommandLines(mocCommandLines);
+      mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc));
     }
   }