diff options
author | Brad King <brad.king@kitware.com> | 2021-11-19 14:06:43 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-11-19 14:06:54 (GMT) |
commit | 4a3480a7865285624e7684fb83c529cb35f657a4 (patch) | |
tree | 2bafd81c218c7ab46bdc43bc8f641feb62d83b87 /Source | |
parent | 3519c19091b0f298aa29285388d15076b0754e19 (diff) | |
parent | 3bb2542535fa2ca1e78195b69c53916a55d322e1 (diff) | |
download | CMake-4a3480a7865285624e7684fb83c529cb35f657a4.zip CMake-4a3480a7865285624e7684fb83c529cb35f657a4.tar.gz CMake-4a3480a7865285624e7684fb83c529cb35f657a4.tar.bz2 |
Merge topic 'custom-command-unique_ptr'
3bb2542535 cmMakefile: Simplify Add*Command and adopt to cmAddCustom*Command
c46b041a3b cmLocalGenerator: Simplify Add{Custom,Utility}Command
68b4e3b255 cmGlobalVisualStudio8Generator: Fix the misaligned argument, stdPipesUTF8
e37511ae7e cmMakefile: Simplify detail:::Add{Custom,Utility}Command
90e1206f25 cmMakefile: Introduce GeneratorAction as the class.
9b31a97748 cmCustomCommand: Move constructor arguments to individual setters
d0158b765b cmMakefile: Move CMP0116 lookup into Add{Custom,Utility}Command
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !6708
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmAddCustomCommandCommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmAddCustomTargetCommand.cxx | 21 | ||||
-rw-r--r-- | Source/cmCPluginAPI.cxx | 31 | ||||
-rw-r--r-- | Source/cmCustomCommand.cxx | 53 | ||||
-rw-r--r-- | Source/cmCustomCommand.h | 24 | ||||
-rw-r--r-- | Source/cmFLTKWrapUICommand.cxx | 24 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 11 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudio8Generator.cxx | 37 | ||||
-rw-r--r-- | Source/cmGlobalVisualStudioGenerator.cxx | 23 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 44 | ||||
-rw-r--r-- | Source/cmLocalGenerator.cxx | 227 | ||||
-rw-r--r-- | Source/cmLocalGenerator.h | 92 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 24 | ||||
-rw-r--r-- | Source/cmLocalVisualStudioGenerator.cxx | 10 | ||||
-rw-r--r-- | Source/cmMakefile.cxx | 161 | ||||
-rw-r--r-- | Source/cmMakefile.h | 90 | ||||
-rw-r--r-- | Source/cmQTWrapCPPCommand.cxx | 16 | ||||
-rw-r--r-- | Source/cmQTWrapUICommand.cxx | 32 | ||||
-rw-r--r-- | Source/cmQtAutoGenGlobalInitializer.cxx | 15 | ||||
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 105 |
20 files changed, 500 insertions, 572 deletions
diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index a7ce3a6..0798ed4 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -4,6 +4,9 @@ #include <sstream> #include <unordered_set> +#include <utility> + +#include <cm/memory> #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" @@ -316,21 +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(), mf.GetPolicyStatus(cmPolicies::CMP0116), 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(), - mf.GetPolicyStatus(cmPolicies::CMP0116), 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; @@ -366,8 +373,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, // Use the old-style mode for backward compatibility. mf.AddCustomCommandOldStyle(target, outputs, depends, source, commandLines, - comment, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + comment); } return true; diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 2b19aad..a246d06 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -4,13 +4,15 @@ #include <utility> +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -211,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, mf.GetPolicyStatus(cmPolicies::CMP0116), 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); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index c49347d..9714e16 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -223,10 +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, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + 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, @@ -267,8 +267,7 @@ static void CCONV cmAddCustomCommand(void* arg, const char* source, // Pass the call to the makefile instance. const char* no_comment = nullptr; mf->AddCustomCommandOldStyle(target, outputs2, depends2, source, - commandLines, no_comment, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + commandLines, no_comment); } static void CCONV cmAddCustomCommandToOutput(void* arg, const char* output, @@ -301,11 +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, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + 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, @@ -343,13 +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, - mf->GetPolicyStatus(cmPolicies::CMP0116)); + 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, diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index ec60ff7..f009632 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -6,28 +6,19 @@ #include <cmext/algorithm> -cmCustomCommand::cmCustomCommand(std::vector<std::string> outputs, - std::vector<std::string> byproducts, - std::vector<std::string> depends, - cmCustomCommandLines commandLines, - cmListFileBacktrace lfbt, const char* comment, - const char* workingDirectory, - bool stdPipesUTF8) - : Outputs(std::move(outputs)) - , Byproducts(std::move(byproducts)) - , Depends(std::move(depends)) - , CommandLines(std::move(commandLines)) - , Backtrace(std::move(lfbt)) - , Comment(comment ? comment : "") - , WorkingDirectory(workingDirectory ? workingDirectory : "") - , HaveComment(comment != nullptr) - , StdPipesUTF8(stdPipesUTF8) +const std::vector<std::string>& cmCustomCommand::GetOutputs() const { + return this->Outputs; } -const std::vector<std::string>& cmCustomCommand::GetOutputs() const +void cmCustomCommand::SetOutputs(std::vector<std::string> outputs) { - return this->Outputs; + this->Outputs = std::move(outputs); +} + +void cmCustomCommand::SetOutputs(std::string output) +{ + this->Outputs = { std::move(output) }; } const std::vector<std::string>& cmCustomCommand::GetByproducts() const @@ -35,22 +26,43 @@ const std::vector<std::string>& cmCustomCommand::GetByproducts() const return this->Byproducts; } +void cmCustomCommand::SetByproducts(std::vector<std::string> byproducts) +{ + this->Byproducts = std::move(byproducts); +} + const std::vector<std::string>& cmCustomCommand::GetDepends() const { return this->Depends; } +void cmCustomCommand::SetDepends(std::vector<std::string> depends) +{ + Depends = std::move(depends); +} + const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const { return this->CommandLines; } +void cmCustomCommand::SetCommandLines(cmCustomCommandLines commandLines) +{ + this->CommandLines = std::move(commandLines); +} + const char* cmCustomCommand::GetComment() const { const char* no_comment = nullptr; return this->HaveComment ? this->Comment.c_str() : no_comment; } +void cmCustomCommand::SetComment(const char* comment) +{ + this->Comment = comment ? comment : ""; + this->HaveComment = (comment != nullptr); +} + void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines) { cm::append(this->CommandLines, commandLines); @@ -86,6 +98,11 @@ cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const return this->Backtrace; } +void cmCustomCommand::SetBacktrace(cmListFileBacktrace lfbt) +{ + this->Backtrace = std::move(lfbt); +} + cmImplicitDependsList const& cmCustomCommand::GetImplicitDepends() const { return this->ImplicitDepends; diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 5cbd3d1..5ae26dd 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -25,22 +25,18 @@ class cmImplicitDependsList class cmCustomCommand { public: - /** Main constructor specifies all information for the command. */ - cmCustomCommand(std::vector<std::string> outputs, - std::vector<std::string> byproducts, - std::vector<std::string> depends, - cmCustomCommandLines commandLines, cmListFileBacktrace lfbt, - const char* comment, const char* workingDirectory, - bool stdPipesUTF8); - /** Get the output file produced by the command. */ const std::vector<std::string>& GetOutputs() const; + void SetOutputs(std::vector<std::string> outputs); + void SetOutputs(std::string output); /** Get the extra files produced by the command. */ const std::vector<std::string>& GetByproducts() const; + void SetByproducts(std::vector<std::string> byproducts); /** Get the vector that holds the list of dependencies. */ const std::vector<std::string>& GetDepends() const; + void SetDepends(std::vector<std::string> depends); /** Get the working directory. */ std::string const& GetWorkingDirectory() const @@ -48,14 +44,25 @@ public: return this->WorkingDirectory; } + void SetWorkingDirectory(const char* workingDirectory) + { + this->WorkingDirectory = (workingDirectory ? workingDirectory : ""); + } + /** Get the list of command lines. */ const cmCustomCommandLines& GetCommandLines() const; + void SetCommandLines(cmCustomCommandLines commandLines); /** Get the comment string for the command. */ const char* GetComment() const; + void SetComment(const char* comment); /** Get a value indicating if the command uses UTF-8 output pipes. */ bool GetStdPipesUTF8() const { return this->StdPipesUTF8; } + void SetStdPipesUTF8(bool stdPipesUTF8) + { + this->StdPipesUTF8 = stdPipesUTF8; + } /** Append to the list of command lines. */ void AppendCommands(const cmCustomCommandLines& commandLines); @@ -74,6 +81,7 @@ public: /** Backtrace of the command that created this custom command. */ cmListFileBacktrace const& GetBacktrace() const; + void SetBacktrace(cmListFileBacktrace lfbt); void SetImplicitDepends(cmImplicitDependsList const&); void AppendImplicitDepends(cmImplicitDependsList const&); diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 77d5795..47dd709 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -3,14 +3,17 @@ #include "cmFLTKWrapUICommand.h" #include <cstddef> +#include <utility> +#include <cm/memory> + +#include "cmCustomCommand.h" #include "cmCustomCommandLines.h" #include "cmExecutionStatus.h" #include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMakefile.h" #include "cmMessageType.h" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -96,14 +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.GetPolicyStatus(cmPolicies::CMP0116)); - mf.AddCustomCommandToOutput(hname, depends, no_main_dependency, - commandLines, no_comment, no_working_dir, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + + 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); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 94eec2e..b02dc29 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -38,7 +38,6 @@ #include "cmInstallGenerator.h" #include "cmInstallRuntimeDependencySet.h" #include "cmLinkLineComputer.h" -#include "cmListFileCache.h" #include "cmLocalGenerator.h" #include "cmMSVC60LinkLineComputer.h" #include "cmMakefile.h" @@ -2877,13 +2876,11 @@ void cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, cmTarget& target = tb.first; target.SetProperty("EXCLUDE_FROM_ALL", "TRUE"); - std::vector<std::string> no_outputs; - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; // Store the custom command in the target. - cmCustomCommand cc(no_outputs, no_byproducts, no_depends, gti.CommandLines, - cmListFileBacktrace(), nullptr, gti.WorkingDir.c_str(), - gti.StdPipesUTF8); + cmCustomCommand cc; + cc.SetCommandLines(gti.CommandLines); + cc.SetWorkingDirectory(gti.WorkingDir.c_str()); + cc.SetStdPipesUTF8(gti.StdPipesUTF8); cc.SetUsesTerminal(gti.UsesTerminal); target.AddPostBuildCommand(std::move(cc)); if (!gti.Message.empty()) { diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 1e45813..48c662c 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -147,13 +147,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() auto& lg = cm::static_reference_cast<cmLocalVisualStudio7Generator>(generators[0]); - const char* no_working_directory = nullptr; - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - cmCustomCommandLines no_commands; - cmTarget* tgt = lg.AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, no_working_directory, - no_byproducts, no_depends, no_commands, cmPolicies::NEW); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* tgt = lg.AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, + std::move(cc)); auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, &lg); auto gt = ptr.get(); @@ -203,11 +200,15 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() std::vector<std::string> byproducts; byproducts.push_back(cm->GetGlobVerifyStamp()); - lg.AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, - no_depends, verifyCommandLines, + cc = cm::make_unique<cmCustomCommand>(); + cc->SetByproducts(byproducts); + cc->SetCommandLines(verifyCommandLines); + cc->SetComment("Checking File Globs"); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetStdPipesUTF8(stdPipesUTF8); + lg.AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCustomCommandType::PRE_BUILD, - "Checking File Globs", no_working_directory, - cmPolicies::NEW, stdPipesUTF8); + std::move(cc)); // Ensure ZERO_CHECK always runs in Visual Studio using MSBuild, // otherwise the prebuild command will not be run. @@ -235,12 +236,16 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // overwritten by the CreateVCProjBuildRule. // (this could be avoided with per-target source files) std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; + cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(stamps); + cc->SetDepends(listFiles); + cc->SetCommandLines(commandLines); + cc->SetComment("Checking Build System"); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(stdPipesUTF8); if (cmSourceFile* file = lg.AddCustomCommandToOutput( - stamps, no_byproducts, listFiles, no_main_dependency, - no_implicit_depends, commandLines, "Checking Build System", - no_working_directory, cmPolicies::NEW, true, false, false, false, "", - "", stdPipesUTF8)) { + no_main_dependency, std::move(cc), true)) { gt->AddSource(file->ResolveFullPath()); } else { cmSystemTools::Error("Error adding rule for " + stamps[0]); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index f9bd67e..f6011d1 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -199,19 +199,18 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() { // Add a special target that depends on ALL projects for easy build // of one configuration only. - const char* no_working_dir = nullptr; - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - cmCustomCommandLines no_commands; for (auto const& it : this->ProjectMap) { std::vector<cmLocalGenerator*> const& gen = it.second; // add the ALL_BUILD to the first local generator of each project if (!gen.empty()) { // Use no actual command lines so that the target itself is not // considered always out of date. - cmTarget* allBuild = gen[0]->AddUtilityCommand( - "ALL_BUILD", true, no_working_dir, no_byproducts, no_depends, - no_commands, cmPolicies::NEW, false, "Build all projects"); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment("Build all projects"); + cmTarget* allBuild = + gen[0]->AddUtilityCommand("ALL_BUILD", true, std::move(cc)); gen[0]->AddGeneratorTarget( cm::make_unique<cmGeneratorTarget>(allBuild, gen[0])); @@ -942,9 +941,13 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( cmCustomCommandLines commandLines = cmMakeSingleCommandLine( { cmakeCommand, "-E", "__create_def", mdi->DefFile, objs_file }); - cmCustomCommand command(outputs, empty, empty, commandLines, - gt->Target->GetMakefile()->GetBacktrace(), - "Auto build dll exports", ".", true); + cmCustomCommand command; + command.SetOutputs(outputs); + command.SetCommandLines(commandLines); + command.SetComment("Auto build dll exports"); + command.SetBacktrace(gt->Target->GetMakefile()->GetBacktrace()); + command.SetWorkingDirectory("."); + command.SetStdPipesUTF8(true); commands.push_back(std::move(command)); } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 5b99945..44a3eb7 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -608,15 +608,13 @@ std::string cmGlobalXCodeGenerator::PostBuildMakeTarget( void cmGlobalXCodeGenerator::AddExtraTargets( cmLocalGenerator* root, std::vector<cmLocalGenerator*>& gens) { - const char* no_working_directory = nullptr; - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - // Add ALL_BUILD - cmTarget* allbuild = root->AddUtilityCommand( - "ALL_BUILD", true, no_working_directory, no_byproducts, no_depends, - cmMakeSingleCommandLine({ "echo", "Build all projects" }), - cmPolicies::NEW); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetCommandLines( + cmMakeSingleCommandLine({ "echo", "Build all projects" })); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* allbuild = + root->AddUtilityCommand("ALL_BUILD", true, std::move(cc)); root->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(allbuild, root)); @@ -642,10 +640,11 @@ void cmGlobalXCodeGenerator::AddExtraTargets( std::string file = this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile); cmSystemTools::ReplaceString(file, "\\ ", " "); - cmTarget* check = root->AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_working_directory, - no_byproducts, no_depends, - cmMakeSingleCommandLine({ "make", "-f", file }), cmPolicies::NEW); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetCommandLines(cmMakeSingleCommandLine({ "make", "-f", file })); + cc->SetCMP0116Status(cmPolicies::NEW); + cmTarget* check = root->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, + true, std::move(cc)); root->AddGeneratorTarget(cm::make_unique<cmGeneratorTarget>(check, root)); } @@ -671,11 +670,13 @@ void cmGlobalXCodeGenerator::AddExtraTargets( target->GetType() == cmStateEnums::OBJECT_LIBRARY) { legacyDependHelperCommandLines.front().back() = // fill placeholder this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)"); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetCommandLines(legacyDependHelperCommandLines); + cc->SetComment("Depend check for xcode"); + cc->SetWorkingDirectory(legacyDependHelperDir.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); gen->AddCustomCommandToTarget( - target->GetName(), no_byproducts, no_depends, - legacyDependHelperCommandLines, cmCustomCommandType::POST_BUILD, - "Depend check for xcode", legacyDependHelperDir.c_str(), - cmPolicies::NEW, true, false, "", "", false, + target->GetName(), cmCustomCommandType::POST_BUILD, std::move(cc), cmObjectLibraryCommands::Accept); } @@ -1723,15 +1724,16 @@ void cmGlobalXCodeGenerator::CreateCustomCommands( cmStrCat("$<TARGET_SONAME_FILE:", gtgt->GetName(), '>'); std::string str_link_file = cmStrCat("$<TARGET_LINKER_FILE:", gtgt->GetName(), '>'); - bool stdPipesUTF8 = true; cmCustomCommandLines cmd = cmMakeSingleCommandLine( { cmSystemTools::GetCMakeCommand(), "-E", "cmake_symlink_library", str_file, str_so_file, str_link_file }); - cmCustomCommand command( - std::vector<std::string>(), std::vector<std::string>(), - std::vector<std::string>(), cmd, this->CurrentMakefile->GetBacktrace(), - "Creating symlinks", "", stdPipesUTF8); + cmCustomCommand command; + command.SetCommandLines(cmd); + command.SetComment("Creating symlinks"); + command.SetWorkingDirectory(""); + command.SetBacktrace(this->CurrentMakefile->GetBacktrace()); + command.SetStdPipesUTF8(true); postbuild.push_back(std::move(command)); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c106137..5e37fe4 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1057,14 +1057,8 @@ void cmLocalGenerator::AddCompileOptions(std::vector<BT<std::string>>& flags, } cmTarget* cmLocalGenerator::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, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle, bool uses_terminal, - const std::string& depfile, const std::string& job_pool, - bool command_expand_lists, cmObjectLibraryCommands objLibCommands, - bool stdPipesUTF8) + const std::string& target, cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc, cmObjectLibraryCommands objLibCommands) { cmTarget* t = this->Makefile->GetCustomCommandTarget( target, objLibCommands, this->DirectoryBacktrace); @@ -1072,74 +1066,45 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget( return nullptr; } - detail::AddCustomCommandToTarget( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, t, byproducts, - depends, commandLines, type, comment, workingDir, escapeOldStyle, - uses_terminal, depfile, job_pool, command_expand_lists, stdPipesUTF8, - cmp0116); + cc->SetBacktrace(this->DirectoryBacktrace); - return t; -} + detail::AddCustomCommandToTarget(*this, cmCommandOrigin::Generator, t, type, + std::move(cc)); -cmSourceFile* cmLocalGenerator::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, - cmPolicies::PolicyStatus cmp0116, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8) -{ - std::vector<std::string> no_byproducts; - cmImplicitDependsList no_implicit_depends; - return this->AddCustomCommandToOutput( - { output }, no_byproducts, depends, main_dependency, no_implicit_depends, - commandLines, comment, workingDir, cmp0116, replace, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, job_pool, stdPipesUTF8); + return t; } cmSourceFile* cmLocalGenerator::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, cmPolicies::PolicyStatus cmp0116, 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, + bool replace) { // Make sure there is at least one output. - if (outputs.empty()) { + if (cc->GetOutputs().empty()) { cmSystemTools::Error("Attempt to add a custom rule with no output!"); return nullptr; } - return detail::AddCustomCommandToOutput( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, outputs, - byproducts, depends, main_dependency, implicit_depends, commandLines, - comment, workingDir, replace, escapeOldStyle, uses_terminal, - command_expand_lists, depfile, job_pool, stdPipesUTF8, cmp0116); + cc->SetBacktrace(this->DirectoryBacktrace); + return detail::AddCustomCommandToOutput(*this, cmCommandOrigin::Generator, + main_dependency, std::move(cc), + replace); } cmTarget* cmLocalGenerator::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, cmPolicies::PolicyStatus cmp0116, - bool escapeOldStyle, const char* comment, bool uses_terminal, - bool command_expand_lists, const std::string& job_pool, bool stdPipesUTF8) + const std::string& utilityName, bool excludeFromAll, + std::unique_ptr<cmCustomCommand> cc) { cmTarget* target = this->Makefile->AddNewUtilityTarget(utilityName, excludeFromAll); target->SetIsGeneratorProvided(true); - if (commandLines.empty() && depends.empty()) { + if (cc->GetCommandLines().empty() && cc->GetDepends().empty()) { return target; } - detail::AddUtilityCommand( - *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, target, - workingDir, byproducts, depends, commandLines, escapeOldStyle, comment, - uses_terminal, command_expand_lists, job_pool, stdPipesUTF8, cmp0116); + cc->SetBacktrace(this->DirectoryBacktrace); + detail::AddUtilityCommand(*this, cmCommandOrigin::Generator, target, + std::move(cc)); return target; } @@ -2750,8 +2715,6 @@ void cmLocalGenerator::CopyPchCompilePdb( file << "endforeach()\n"; } - bool stdPipesUTF8 = true; - auto configGenex = [&](cm::string_view expr) -> std::string { if (this->GetGlobalGenerator()->IsMultiConfig()) { return cmStrCat("$<$<CONFIG:", config, ">:", expr, ">"); @@ -2765,28 +2728,27 @@ void cmLocalGenerator::CopyPchCompilePdb( configGenex(copy_script) }); const std::string no_main_dependency; - const std::vector<std::string> no_deps; const char* no_message = ""; - const char* no_current_dir = nullptr; - const cmPolicies::PolicyStatus cmp0116_new = cmPolicies::NEW; - std::vector<std::string> no_byproducts; std::vector<std::string> outputs; outputs.push_back(configGenex( cmStrCat(target_compile_pdb_dir, pdb_prefix, ReuseFrom, ".pdb"))); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetCommandLines(commandLines); + cc->SetComment(no_message); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetStdPipesUTF8(true); + if (this->GetGlobalGenerator()->IsVisualStudio()) { + cc->SetByproducts(outputs); this->AddCustomCommandToTarget( - target->GetName(), outputs, no_deps, commandLines, - cmCustomCommandType::PRE_BUILD, no_message, no_current_dir, cmp0116_new, - true, false, "", "", false, cmObjectLibraryCommands::Accept, - stdPipesUTF8); + target->GetName(), cmCustomCommandType::PRE_BUILD, std::move(cc), + cmObjectLibraryCommands::Accept); } else { - cmImplicitDependsList no_implicit_depends; - cmSourceFile* copy_rule = this->AddCustomCommandToOutput( - outputs, no_byproducts, no_deps, no_main_dependency, no_implicit_depends, - commandLines, no_message, no_current_dir, cmp0116_new, false, true, - false, false, "", "", stdPipesUTF8); + cc->SetOutputs(outputs); + cmSourceFile* copy_rule = + this->AddCustomCommandToOutput(no_main_dependency, std::move(cc)); if (copy_rule) { target->AddSource(copy_rule->ResolveFullPath()); @@ -4051,19 +4013,16 @@ std::string ComputeCustomCommandRuleFileName(cmLocalGenerator& lg, h.HashString(output).substr(0, 16)); } -cmSourceFile* AddCustomCommand( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, 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, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116) +cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr<cmCustomCommand> cc, + bool replace) { cmMakefile* mf = lg.GetMakefile(); + const auto& lfbt = cc->GetBacktrace(); + const auto& outputs = cc->GetOutputs(); + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); // Choose a source file on which to store the custom command. cmSourceFile* file = nullptr; @@ -4118,28 +4077,18 @@ cmSourceFile* AddCustomCommand( // Attach the custom command to the file. if (file) { // Construct a complete list of dependencies. - std::vector<std::string> depends2(depends); if (!main_dependency.empty()) { - depends2.push_back(main_dependency); + cc->AppendDepends({ main_dependency }); } - std::unique_ptr<cmCustomCommand> cc = cm::make_unique<cmCustomCommand>( - outputs, byproducts, depends2, commandLines, lfbt, comment, workingDir, - stdPipesUTF8); - cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); - cc->SetImplicitDepends(implicit_depends); - cc->SetUsesTerminal(uses_terminal); - cc->SetCommandExpandLists(command_expand_lists); - cc->SetDepfile(depfile); - cc->SetJobPool(job_pool); - cc->SetCMP0116Status(cmp0116); - file->SetCustomCommand(std::move(cc)); lg.AddSourceOutputs(file, outputs, cmLocalGenerator::OutputRole::Primary, lfbt, origin); lg.AddSourceOutputs(file, byproducts, cmLocalGenerator::OutputRole::Byproduct, lfbt, origin); + + file->SetCustomCommand(std::move(cc)); } return file; } @@ -4168,63 +4117,39 @@ bool AnyTargetCommandOutputMatches( } namespace detail { -void AddCustomCommandToTarget(cmLocalGenerator& lg, - const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* 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, - cmPolicies::PolicyStatus cmp0116) +void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc) { // Add the command to the appropriate build step for the target. - std::vector<std::string> no_output; - cmCustomCommand cc(no_output, byproducts, depends, commandLines, lfbt, - comment, workingDir, stdPipesUTF8); - cc.SetEscapeOldStyle(escapeOldStyle); - cc.SetEscapeAllowMakeVars(true); - cc.SetUsesTerminal(uses_terminal); - cc.SetCommandExpandLists(command_expand_lists); - cc.SetDepfile(depfile); - cc.SetJobPool(job_pool); - cc.SetCMP0116Status(cmp0116); - cc.SetTarget(target->GetName()); + cc->SetEscapeAllowMakeVars(true); + cc->SetTarget(target->GetName()); + + lg.AddTargetByproducts(target, cc->GetByproducts(), cc->GetBacktrace(), + origin); + switch (type) { case cmCustomCommandType::PRE_BUILD: - target->AddPreBuildCommand(std::move(cc)); + target->AddPreBuildCommand(std::move(*cc)); break; case cmCustomCommandType::PRE_LINK: - target->AddPreLinkCommand(std::move(cc)); + target->AddPreLinkCommand(std::move(*cc)); break; case cmCustomCommandType::POST_BUILD: - target->AddPostBuildCommand(std::move(cc)); + target->AddPostBuildCommand(std::move(*cc)); break; } - lg.AddTargetByproducts(target, byproducts, lfbt, origin); + cc.reset(); } -cmSourceFile* AddCustomCommandToOutput( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, 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, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116) +cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg, + cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr<cmCustomCommand> cc, + bool replace) { - return AddCustomCommand(lg, lfbt, origin, outputs, byproducts, depends, - main_dependency, implicit_depends, commandLines, - comment, workingDir, replace, escapeOldStyle, - uses_terminal, command_expand_lists, depfile, - job_pool, stdPipesUTF8, cmp0116); + return AddCustomCommand(lg, origin, main_dependency, std::move(cc), replace); } void AppendCustomCommandToOutput(cmLocalGenerator& lg, @@ -4267,33 +4192,27 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg, lfbt); } -void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - 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, - cmPolicies::PolicyStatus cmp0116) +void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, std::unique_ptr<cmCustomCommand> cc) { + // They might be moved away + auto byproducts = cc->GetByproducts(); + auto lfbt = cc->GetBacktrace(); + // Use an empty comment to avoid generation of default comment. - if (!comment) { - comment = ""; + if (!cc->GetComment()) { + cc->SetComment(""); } // Create the generated symbolic output name of the utility target. std::string output = lg.CreateUtilityOutput(target->GetName(), byproducts, lfbt); + cc->SetOutputs(output); std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; - cmSourceFile* rule = AddCustomCommand( - lg, lfbt, origin, { output }, byproducts, depends, no_main_dependency, - no_implicit_depends, commandLines, comment, workingDir, - /*replace=*/false, escapeOldStyle, uses_terminal, command_expand_lists, - /*depfile=*/"", job_pool, stdPipesUTF8, cmp0116); + cmSourceFile* rule = + AddCustomCommand(lg, origin, no_main_dependency, std::move(cc), + /*replace=*/false); if (rule) { lg.AddTargetByproducts(target, byproducts, lfbt, origin); } diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 726817a..3edf5dc 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -329,53 +329,24 @@ public: * Add 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, - cmPolicies::PolicyStatus cmp0116, bool escapeOldStyle = true, - bool uses_terminal = false, const std::string& depfile = "", - const std::string& job_pool = "", bool command_expand_lists = false, - cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject, - bool stdPipesUTF8 = false); + const std::string& target, cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc, + cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject); /** * Add a custom command to a source file. */ - cmSourceFile* 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, cmPolicies::PolicyStatus cmp0116, - 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); - cmSourceFile* 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, cmPolicies::PolicyStatus cmp0116, - 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); + cmSourceFile* AddCustomCommandToOutput(const std::string& main_dependency, + std::unique_ptr<cmCustomCommand> cc, + bool replace = false); /** * Add 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, cmPolicies::PolicyStatus cmp0116, - 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); virtual std::string CreateUtilityOutput( std::string const& targetName, std::vector<std::string> const& byproducts, @@ -713,30 +684,15 @@ bool cmLocalGeneratorCheckObjectName(std::string& objName, #endif namespace detail { -void AddCustomCommandToTarget(cmLocalGenerator& lg, - const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* 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, - cmPolicies::PolicyStatus cmp0116); - -cmSourceFile* AddCustomCommandToOutput( - cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, 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, bool replace, bool escapeOldStyle, - bool uses_terminal, bool command_expand_lists, const std::string& depfile, - const std::string& job_pool, bool stdPipesUTF8, - cmPolicies::PolicyStatus cmp0116); +void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, cmCustomCommandType type, + std::unique_ptr<cmCustomCommand> cc); + +cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg, + cmCommandOrigin origin, + const std::string& main_dependency, + std::unique_ptr<cmCustomCommand> cc, + bool replace); void AppendCustomCommandToOutput(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, @@ -745,16 +701,8 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg, const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines); -void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, - cmCommandOrigin origin, cmTarget* target, - 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, - cmPolicies::PolicyStatus cmp0116); +void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin, + cmTarget* target, std::unique_ptr<cmCustomCommand> cc); std::vector<std::string> ComputeISPCObjectSuffixes(cmGeneratorTarget* target); std::vector<std::string> ComputeISPCExtraObjects( diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 7223049..886a4e8 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -110,7 +110,6 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() const auto& tgts = this->GetGeneratorTargets(); for (auto& l : tgts) { if (l->GetType() == cmStateEnums::GLOBAL_TARGET) { - std::vector<std::string> no_depends; cmCustomCommandLines force_commands = cmMakeSingleCommandLine({ "cd", "." }); std::string no_main_dependency; @@ -120,9 +119,13 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() this->Makefile->GetOrCreateGeneratedSource(force)) { sf->SetProperty("SYMBOLIC", "1"); } + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(force); + cc->SetCommandLines(force_commands); + cc->SetComment(" "); + cc->SetCMP0116Status(cmPolicies::NEW); if (cmSourceFile* file = this->AddCustomCommandToOutput( - force, no_depends, no_main_dependency, force_commands, " ", - nullptr, cmPolicies::NEW, true)) { + no_main_dependency, std::move(cc), true)) { l->AddSource(file->ResolveFullPath()); } } @@ -240,16 +243,19 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() std::string argB = cmStrCat("-B", this->GetBinaryDirectory()); std::string stampName = cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/generate.stamp"); - bool stdPipesUTF8 = true; cmCustomCommandLines commandLines = cmMakeSingleCommandLine({ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-file", stampName }); std::string comment = cmStrCat("Building Custom Rule ", makefileIn); - const char* no_working_directory = nullptr; - this->AddCustomCommandToOutput(stampName, listFiles, makefileIn, - commandLines, comment.c_str(), - no_working_directory, cmPolicies::NEW, true, - false, false, false, "", "", stdPipesUTF8); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(stampName); + cc->SetDepends(listFiles); + cc->SetCommandLines(commandLines); + cc->SetComment(comment.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(true); + this->AddCustomCommandToOutput(makefileIn, std::move(cc), true); if (cmSourceFile* file = this->Makefile->GetSource(makefileIn)) { // Finalize the source file path now since we're adding this after // the generator validated all project-named sources. diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 4ed1dd9..3e23f35 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -99,15 +99,11 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target, } // Add a pre-build event to create the directory. - std::vector<std::string> no_output; - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - bool stdPipesUTF8 = true; cmCustomCommandLines commands = cmMakeSingleCommandLine( { cmSystemTools::GetCMakeCommand(), "-E", "make_directory", impDir }); - pcc.reset(new cmCustomCommand(no_output, no_byproducts, no_depends, commands, - cmListFileBacktrace(), nullptr, nullptr, - stdPipesUTF8)); + pcc.reset(new cmCustomCommand()); + pcc->SetCommandLines(commands); + pcc->SetStdPipesUTF8(true); pcc->SetEscapeOldStyle(false); pcc->SetEscapeAllowMakeVars(true); return pcc; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index bf3e217..fe56dec 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -891,12 +891,23 @@ struct file_not_persistent }; } -void cmMakefile::AddGeneratorAction(GeneratorAction action) +void cmMakefile::AddGeneratorAction(GeneratorAction&& action) { assert(!this->GeneratorActionsInvoked); this->GeneratorActions.emplace_back(std::move(action), this->Backtrace); } +void cmMakefile::GeneratorAction::operator()(cmLocalGenerator& lg, + const cmListFileBacktrace& lfbt) +{ + if (cc) { + CCAction(lg, lfbt, std::move(cc)); + } else { + assert(Action); + Action(lg, lfbt); + } +} + void cmMakefile::DoGenerate(cmLocalGenerator& lg) { // do all the variable expansions here @@ -904,7 +915,7 @@ void cmMakefile::DoGenerate(cmLocalGenerator& lg) // give all the commands a chance to do something // after the file has been parsed before generation - for (const BT<GeneratorAction>& action : this->GeneratorActions) { + for (auto& action : this->GeneratorActions) { action.Value(lg, action.Backtrace); } this->GeneratorActionsInvoked = true; @@ -956,19 +967,6 @@ private: cmListFileBacktrace& Backtrace; cmListFileBacktrace Previous; }; - -cm::optional<std::string> MakeOptionalString(const char* str) -{ - if (str) { - return str; - } - return cm::nullopt; -} - -const char* GetCStrOrNull(const cm::optional<std::string>& str) -{ - return str ? str->c_str() : nullptr; -} } bool cmMakefile::ValidateCustomCommand( @@ -1056,14 +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, - cmPolicies::PolicyStatus cmp0116, 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); @@ -1075,53 +1071,30 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - // Strings could be moved into the callback function with C++14. - cm::optional<std::string> commentStr = MakeOptionalString(comment); - cm::optional<std::string> workingStr = MakeOptionalString(workingDir); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr<cmCustomCommand> tcc) { BacktraceGuard guard(this->Backtrace, lfbt); - detail::AddCustomCommandToTarget( - lg, lfbt, cmCommandOrigin::Project, t, byproducts, depends, - commandLines, type, GetCStrOrNull(commentStr), - GetCStrOrNull(workingStr), escapeOldStyle, uses_terminal, depfile, - job_pool, command_expand_lists, stdPipesUTF8, cmp0116); + tcc->SetBacktrace(lfbt); + detail::AddCustomCommandToTarget(lg, cmCommandOrigin::Project, t, type, + std::move(tcc)); }); return t; } 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, - cmPolicies::PolicyStatus cmp0116, 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) -{ - std::vector<std::string> no_byproducts; - cmImplicitDependsList no_implicit_depends; - this->AddCustomCommandToOutput( - { output }, no_byproducts, depends, main_dependency, no_implicit_depends, - commandLines, comment, workingDir, cmp0116, callback, replace, - escapeOldStyle, uses_terminal, command_expand_lists, depfile, job_pool, - stdPipesUTF8); -} - -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, cmPolicies::PolicyStatus cmp0116, - 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) { + const auto& outputs = cc->GetOutputs(); + const auto& byproducts = cc->GetByproducts(); + const auto& commandLines = cc->GetCommandLines(); + // Make sure there is at least one output. if (outputs.empty()) { cmSystemTools::Error("Attempt to add a custom rule with no output!"); @@ -1137,20 +1110,18 @@ void cmMakefile::AddCustomCommandToOutput( this->CreateGeneratedOutputs(outputs); this->CreateGeneratedOutputs(byproducts); - // Strings could be moved into the callback function with C++14. - cm::optional<std::string> commentStr = MakeOptionalString(comment); - cm::optional<std::string> workingStr = MakeOptionalString(workingDir); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr<cmCustomCommand> tcc) { BacktraceGuard guard(this->Backtrace, lfbt); + tcc->SetBacktrace(lfbt); cmSourceFile* sf = detail::AddCustomCommandToOutput( - lg, lfbt, cmCommandOrigin::Project, outputs, byproducts, depends, - main_dependency, implicit_depends, commandLines, - GetCStrOrNull(commentStr), GetCStrOrNull(workingStr), replace, - escapeOldStyle, uses_terminal, command_expand_lists, depfile, job_pool, - stdPipesUTF8, cmp0116); + lg, cmCommandOrigin::Project, main_dependency, std::move(tcc), + replace); if (callback && sf) { callback(sf); } @@ -1160,19 +1131,21 @@ void cmMakefile::AddCustomCommandToOutput( void cmMakefile::AddCustomCommandOldStyle( const std::string& target, const std::vector<std::string>& outputs, const std::vector<std::string>& depends, const std::string& source, - const cmCustomCommandLines& commandLines, const char* comment, - cmPolicies::PolicyStatus cmp0116) + 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, cmp0116); + this->AddCustomCommandToTarget(target, cmCustomCommandType::POST_BUILD, + std::move(cc)); return; } @@ -1204,19 +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, cmp0116, + 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, cmp0116, + auto cc1 = cm::make_unique<cmCustomCommand>(*cc); + cc1->SetOutputs(output); + this->AddCustomCommandToOutput(no_main_dependency, std::move(cc1), addRuleFileToTarget); } } @@ -1239,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, cmPolicies::PolicyStatus cmp0116, - 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. @@ -1258,19 +1231,17 @@ cmTarget* cmMakefile::AddUtilityCommand( // Always create the byproduct sources and mark them generated. this->CreateGeneratedOutputs(byproducts); - // Strings could be moved into the callback function with C++14. - cm::optional<std::string> commentStr = MakeOptionalString(comment); - cm::optional<std::string> workingStr = MakeOptionalString(workingDir); + cc->SetCMP0116Status(this->GetPolicyStatus(cmPolicies::CMP0116)); // Dispatch command creation to allow generator expressions in outputs. this->AddGeneratorAction( - [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt) { + std::move(cc), + [=](cmLocalGenerator& lg, const cmListFileBacktrace& lfbt, + std::unique_ptr<cmCustomCommand> tcc) { BacktraceGuard guard(this->Backtrace, lfbt); - detail::AddUtilityCommand( - lg, lfbt, cmCommandOrigin::Project, target, GetCStrOrNull(workingStr), - byproducts, depends, commandLines, escapeOldStyle, - GetCStrOrNull(commentStr), uses_terminal, command_expand_lists, - job_pool, stdPipesUTF8, cmp0116); + tcc->SetBacktrace(lfbt); + detail::AddUtilityCommand(lg, cmCommandOrigin::Project, target, + std::move(tcc)); }); return target; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 671cdab..af18230 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -24,6 +24,7 @@ #include "cm_sys_stat.h" #include "cmAlgorithms.h" +#include "cmCustomCommand.h" #include "cmCustomCommandTypes.h" #include "cmListFileCache.h" #include "cmMessageType.h" @@ -50,7 +51,6 @@ class cmExportBuildFileGenerator; class cmFunctionBlocker; class cmGeneratorExpressionEvaluationFile; class cmGlobalGenerator; -class cmImplicitDependsList; class cmInstallGenerator; class cmLocalGenerator; class cmMessenger; @@ -140,13 +140,47 @@ public: bool EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom = false) const; - using GeneratorAction = - std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>; + class GeneratorAction + { + using ActionT = + std::function<void(cmLocalGenerator&, const cmListFileBacktrace&)>; + using CCActionT = + std::function<void(cmLocalGenerator&, const cmListFileBacktrace&, + std::unique_ptr<cmCustomCommand> cc)>; + + public: + GeneratorAction(ActionT&& action) + : Action(std::move(action)) + { + } + + GeneratorAction(std::unique_ptr<cmCustomCommand> tcc, CCActionT&& action) + : CCAction(std::move(action)) + , cc(std::move(tcc)) + { + } + + void operator()(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt); + + private: + ActionT Action; + + // FIXME: Use std::variant + CCActionT CCAction; + std::unique_ptr<cmCustomCommand> cc; + }; /** * Register an action that is executed during Generate */ - void AddGeneratorAction(GeneratorAction action); + void AddGeneratorAction(GeneratorAction&& action); + + /// Helper to insert the constructor GeneratorAction(args...) + template <class... Args> + void AddGeneratorAction(Args&&... args) + { + AddGeneratorAction(GeneratorAction(std::move(args)...)); + } /** * Perform generate actions, Library dependency analysis etc before output of @@ -165,15 +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, - cmPolicies::PolicyStatus cmp0116, 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. @@ -184,33 +212,14 @@ 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, cmPolicies::PolicyStatus cmp0116, - 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, cmPolicies::PolicyStatus cmp0116, - 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, const std::string& source, const cmCustomCommandLines& commandLines, - const char* comment, - cmPolicies::PolicyStatus cmp0116); + const char* comment); void AppendCustomCommandToOutput( const std::string& output, const std::vector<std::string>& depends, const cmImplicitDependsList& implicit_depends, @@ -252,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, cmPolicies::PolicyStatus cmp0116, - 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. diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index ca0b259..b489944 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -2,10 +2,14 @@ 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" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -72,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, mf.GetPolicyStatus(cmPolicies::CMP0116)); + 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)); } } diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index f98f0b3..4d65f33 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -2,10 +2,14 @@ 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" -#include "cmPolicies.h" #include "cmRange.h" #include "cmSourceFile.h" #include "cmStringAlgorithms.h" @@ -85,22 +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, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + 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, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + 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, - mf.GetPolicyStatus(cmPolicies::CMP0116)); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(mocName); + cc->SetDepends(depends); + cc->SetCommandLines(mocCommandLines); + mf.AddCustomCommandToOutput(no_main_dependency, std::move(cc)); } } diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index f9e889a..b7ea7d6 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -7,7 +7,7 @@ #include <cm/memory> -#include "cmCustomCommandLines.h" +#include "cmCustomCommand.h" #include "cmDuration.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" @@ -171,13 +171,12 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( cmMakefile* makefile = localGen->GetMakefile(); // Create utility target - std::vector<std::string> no_byproducts; - std::vector<std::string> no_depends; - cmCustomCommandLines no_commands; - const cmPolicies::PolicyStatus cmp0116_new = cmPolicies::NEW; - cmTarget* target = localGen->AddUtilityCommand( - name, true, makefile->GetHomeOutputDirectory().c_str(), no_byproducts, - no_depends, no_commands, cmp0116_new, false, comment.c_str()); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetWorkingDirectory(makefile->GetHomeOutputDirectory().c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment(comment.c_str()); + cmTarget* target = localGen->AddUtilityCommand(name, true, std::move(cc)); localGen->AddGeneratorTarget( cm::make_unique<cmGeneratorTarget>(target, localGen)); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index c49cafe..64d8ea9 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1231,14 +1231,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Add a rule file to cause the target to build if a dependency has // changed, which will trigger the pre-build command to run autogen std::string no_main_dependency; - cmCustomCommandLines no_command_lines; - this->LocalGen->AddCustomCommandToOutput( - timestampFileGenex, uicDependencies, no_main_dependency, - no_command_lines, /*comment=*/"", this->Dir.Work.c_str(), - /*cmp0116=*/cmPolicies::NEW, /*replace=*/false, - /*escapeOldStyle=*/false, /*uses_terminal=*/false, - /*command_expand_lists=*/false, /*depfile=*/"", /*job_pool=*/"", - stdPipesUTF8); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(timestampFileGenex); + cc->SetDepends(uicDependencies); + cc->SetComment(""); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetStdPipesUTF8(stdPipesUTF8); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); } // Add the pre-build command directly to bypass the OBJECT_LIBRARY @@ -1246,11 +1248,13 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // PRE_BUILD will work for an OBJECT_LIBRARY in this specific case. // // PRE_BUILD does not support file dependencies! - const std::vector<std::string> no_output; - const std::vector<std::string> no_deps; - cmCustomCommand cc(no_output, autogenByproducts, no_deps, commandLines, - this->Makefile->GetBacktrace(), autogenComment.c_str(), - this->Dir.Work.c_str(), stdPipesUTF8); + cmCustomCommand cc; + cc.SetByproducts(autogenByproducts); + cc.SetCommandLines(commandLines); + cc.SetComment(autogenComment.c_str()); + cc.SetBacktrace(this->Makefile->GetBacktrace()); + cc.SetWorkingDirectory(this->Dir.Work.c_str()); + cc.SetStdPipesUTF8(stdPipesUTF8); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); this->GenTarget->Target->AddPreBuildCommand(std::move(cc)); @@ -1321,11 +1325,15 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() dependencies.push_back(depname); } + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetByproducts(timestampTargetProvides); + cc->SetDepends(dependencies); + cc->SetCommandLines(timestampTargetCommandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); cmTarget* timestampTarget = this->LocalGen->AddUtilityCommand( - timestampTargetName, true, this->Dir.Work.c_str(), - /*byproducts=*/timestampTargetProvides, - /*depends=*/dependencies, timestampTargetCommandLines, cmPolicies::NEW, - false, nullptr); + timestampTargetName, true, std::move(cc)); this->LocalGen->AddGeneratorTarget( cm::make_unique<cmGeneratorTarget>(timestampTarget, this->LocalGen)); @@ -1355,15 +1363,19 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() this->AddGeneratedSource(outputFile, this->Moc); const std::string no_main_dependency; - this->LocalGen->AddCustomCommandToOutput( - { outputFile }, timestampByproducts, dependencies, no_main_dependency, - /*implicit_depends=*/{}, commandLines, autogenComment.c_str(), - this->Dir.Work.c_str(), - /*cmp0116=*/cmPolicies::NEW, /*replace=*/false, - /*escapeOldStyle=*/false, - /*uses_terminal=*/false, - /*command_expand_lists=*/false, this->AutogenTarget.DepFile, "", - stdPipesUTF8); + cc = cm::make_unique<cmCustomCommand>(); + cc->SetOutputs(outputFile); + cc->SetByproducts(timestampByproducts); + cc->SetDepends(dependencies); + cc->SetCommandLines(commandLines); + cc->SetComment(autogenComment.c_str()); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetDepfile(this->AutogenTarget.DepFile); + cc->SetStdPipesUTF8(stdPipesUTF8); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); // Alter variables for the autogen target which now merely wraps the // custom command @@ -1374,11 +1386,16 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() } // Create autogen target + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetByproducts(autogenByproducts); + cc->SetDepends(dependencies); + cc->SetCommandLines(commandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetEscapeOldStyle(false); + cc->SetComment(autogenComment.c_str()); cmTarget* autogenTarget = this->LocalGen->AddUtilityCommand( - this->AutogenTarget.Name, true, this->Dir.Work.c_str(), - /*byproducts=*/autogenByproducts, - /*depends=*/dependencies, commandLines, cmPolicies::NEW, false, - autogenComment.c_str()); + this->AutogenTarget.Name, true, std::move(cc)); // Create autogen generator target this->LocalGen->AddGeneratorTarget( cm::make_unique<cmGeneratorTarget>(autogenTarget, this->LocalGen)); @@ -1435,7 +1452,6 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccDepends.push_back(qrc.QrcFile); ccDepends.push_back(qrc.InfoFile); - bool stdPipesUTF8 = true; cmCustomCommandLines commandLines; if (this->MultiConfig) { // Build for all configurations @@ -1453,6 +1469,13 @@ bool cmQtAutoGenInitializer::InitRccTargets() cmStrCat("Automatic RCC for ", FileProjectRelativePath(this->Makefile, qrc.QrcFile)); + auto cc = cm::make_unique<cmCustomCommand>(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetCommandLines(commandLines); + cc->SetCMP0116Status(cmPolicies::NEW); + cc->SetComment(ccComment.c_str()); + cc->SetStdPipesUTF8(true); + if (qrc.Generated || this->Rcc.GlobalTarget) { // Create custom rcc target std::string ccName; @@ -1462,10 +1485,11 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccName += cmStrCat('_', qrc.QrcPathChecksum); } - cmTarget* autoRccTarget = this->LocalGen->AddUtilityCommand( - ccName, true, this->Dir.Work.c_str(), ccOutput, ccDepends, - commandLines, cmPolicies::NEW, false, ccComment.c_str(), false, - false, "", stdPipesUTF8); + cc->SetByproducts(ccOutput); + cc->SetDepends(ccDepends); + cc->SetEscapeOldStyle(false); + cmTarget* autoRccTarget = + this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc)); // Create autogen generator target this->LocalGen->AddGeneratorTarget( @@ -1501,12 +1525,11 @@ bool cmQtAutoGenInitializer::InitRccTargets() ccDepends.push_back(this->Rcc.ExecutableTargetName); } std::string no_main_dependency; - cmImplicitDependsList no_implicit_depends; - this->LocalGen->AddCustomCommandToOutput( - ccOutput, ccByproducts, ccDepends, no_main_dependency, - no_implicit_depends, commandLines, ccComment.c_str(), - this->Dir.Work.c_str(), cmPolicies::NEW, false, true, false, false, - "", "", stdPipesUTF8); + cc->SetOutputs(ccOutput); + cc->SetByproducts(ccByproducts); + cc->SetDepends(ccDepends); + this->LocalGen->AddCustomCommandToOutput(no_main_dependency, + std::move(cc)); } // Reconfigure when .qrc file changes this->Makefile->AddCMakeDependFile(qrc.QrcFile); |