Commit 1423507a authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'command-line-make-functions'

9c45b95d cmMakefile: Remove unused AddUtilityCommand overload
7f3ecbe7 cmCustomCommandLine: Provide command line make functions
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3819
parents 01cce698 9c45b95d
......@@ -191,6 +191,8 @@ set(SRCS
cmCustomCommand.h
cmCustomCommandGenerator.cxx
cmCustomCommandGenerator.h
cmCustomCommandLines.cxx
cmCustomCommandLines.h
cmDefinitions.cxx
cmDefinitions.h
cmDepends.cxx
......
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCustomCommandLines.h"
cmCustomCommandLine cmMakeCommandLine(
std::initializer_list<cm::string_view> ilist)
{
cmCustomCommandLine commandLine;
commandLine.reserve(ilist.size());
for (cm::string_view cmd : ilist) {
commandLine.emplace_back(cmd);
}
return commandLine;
}
cmCustomCommandLines cmMakeSingleCommandLine(
std::initializer_list<cm::string_view> ilist)
{
cmCustomCommandLines commandLines;
commandLines.push_back(cmMakeCommandLine(ilist));
return commandLines;
}
......@@ -5,25 +5,28 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <initializer_list>
#include <string>
#include <vector>
#include "cm_string_view.hxx" // IWYU pragma: keep
/** Data structure to represent a single command line. */
class cmCustomCommandLine : public std::vector<std::string>
{
public:
using Superclass = std::vector<std::string>;
using iterator = Superclass::iterator;
using const_iterator = Superclass::const_iterator;
};
/** Data structure to represent a list of command lines. */
class cmCustomCommandLines : public std::vector<cmCustomCommandLine>
{
public:
using Superclass = std::vector<cmCustomCommandLine>;
using iterator = Superclass::iterator;
using const_iterator = Superclass::const_iterator;
};
/** Return a command line from a list of command line parts. */
cmCustomCommandLine cmMakeCommandLine(
std::initializer_list<cm::string_view> ilist);
/** Return a command line vector with a single command line. */
cmCustomCommandLines cmMakeSingleCommandLine(
std::initializer_list<cm::string_view> ilist);
#endif
......@@ -77,16 +77,15 @@ bool cmFLTKWrapUICommand(std::vector<std::string> const& args,
depends.push_back(fluid_exe);
std::string cxxres = cmStrCat(outName, ".cxx");
cmCustomCommandLine commandLine;
commandLine.push_back(fluid_exe);
commandLine.push_back("-c"); // instructs Fluid to run in command line
commandLine.push_back("-h"); // optionally rename .h files
commandLine.push_back(hname);
commandLine.push_back("-o"); // optionally rename .cxx files
commandLine.push_back(cxxres);
commandLine.push_back(origname); // name of the GUI fluid file
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
cmCustomCommandLines commandLines = cmMakeSingleCommandLine({
fluid_exe,
"-c", // instructs Fluid to run in command line
"-h", // optionally rename .h files
hname,
"-o", // optionally rename .cxx files
cxxres,
origname // name of the GUI fluid file
});
// Add command for generating the .h and .cxx files
std::string no_main_dependency;
......
......@@ -3,6 +3,7 @@
#include "cmGlobalVisualStudio8Generator.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
......@@ -146,12 +147,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
// Add a custom prebuild target to run the VerifyGlobs script.
cmake* cm = this->GetCMakeInstance();
if (cm->DoWriteGlobVerifyTarget()) {
cmCustomCommandLine verifyCommandLine;
verifyCommandLine.push_back(cmSystemTools::GetCMakeCommand());
verifyCommandLine.push_back("-P");
verifyCommandLine.push_back(cm->GetGlobVerifyScript());
cmCustomCommandLines verifyCommandLines;
verifyCommandLines.push_back(verifyCommandLine);
cmCustomCommandLines verifyCommandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), "-P", cm->GetGlobVerifyScript() });
std::vector<std::string> byproducts;
byproducts.push_back(cm->GetGlobVerifyStamp());
......@@ -173,20 +170,13 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget()
listFiles.erase(new_end, listFiles.end());
// Create a rule to re-run CMake.
cmCustomCommandLine commandLine;
commandLine.push_back(cmSystemTools::GetCMakeCommand());
std::string argS = cmStrCat("-S", lg->GetSourceDirectory());
commandLine.push_back(argS);
std::string argB = cmStrCat("-B", lg->GetBinaryDirectory());
commandLine.push_back(argB);
commandLine.push_back("--check-stamp-list");
commandLine.push_back(stampList.c_str());
commandLine.push_back("--vs-solution-file");
std::string const sln =
lg->GetBinaryDirectory() + "/" + lg->GetProjectName() + ".sln";
commandLine.push_back(sln);
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), argS, argB, "--check-stamp-list",
stampList, "--vs-solution-file", sln });
// Add the rule. Note that we cannot use the CMakeLists.txt
// file as the main dependency because it would get
......
......@@ -13,6 +13,7 @@
#include "cmAlgorithms.h"
#include "cmCallVisualStudioMacro.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmLocalVisualStudioGenerator.h"
......@@ -900,17 +901,11 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
std::string obj_dir = gt->ObjectDirectory;
std::string cmakeCommand = cmSystemTools::GetCMakeCommand();
cmSystemTools::ConvertToWindowsExtendedPath(cmakeCommand);
cmCustomCommandLine cmdl;
cmdl.push_back(cmakeCommand);
cmdl.push_back("-E");
cmdl.push_back("__create_def");
cmdl.push_back(mdi->DefFile);
std::string obj_dir_expanded = obj_dir;
cmSystemTools::ReplaceString(obj_dir_expanded, this->GetCMakeCFGIntDir(),
configName.c_str());
cmSystemTools::MakeDirectory(obj_dir_expanded);
std::string const objs_file = obj_dir_expanded + "/objects.txt";
cmdl.push_back(objs_file);
cmGeneratedFileStream fout(objs_file.c_str());
if (!fout) {
cmSystemTools::Error("could not open " + objs_file);
......@@ -948,8 +943,8 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand(
fout << i->GetFullPath() << "\n";
}
cmCustomCommandLines commandLines;
commandLines.push_back(cmdl);
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmakeCommand, "-E", "__create_def", mdi->DefFile, objs_file });
cmCustomCommand command(gt->Target->GetMakefile(), outputs, empty, empty,
commandLines, "Auto build dll exports", ".");
commands.push_back(command);
......
......@@ -15,6 +15,7 @@
#include "cmComputeLinkInformation.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmCustomCommandLines.h"
#include "cmDocumentationEntry.h"
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
......@@ -500,22 +501,18 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
const char* no_working_directory = nullptr;
std::vector<std::string> no_depends;
cmTarget* allbuild = mf->AddUtilityCommand(
"ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_depends,
no_working_directory, "echo", "Build all projects");
"ALL_BUILD", cmMakefile::TargetOrigin::Generator, true,
no_working_directory, no_depends,
cmMakeSingleCommandLine({ "echo", "Build all projects" }));
cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root);
root->AddGeneratorTarget(allBuildGt);
// Add XCODE depend helper
std::string dir = root->GetCurrentBinaryDirectory();
cmCustomCommandLine makeHelper;
makeHelper.push_back("make");
makeHelper.push_back("-C");
makeHelper.push_back(dir);
makeHelper.push_back("-f");
makeHelper.push_back(this->CurrentXCodeHackMakefile);
makeHelper.push_back("OBJDIR=$(OBJDIR)");
makeHelper.push_back(""); // placeholder, see below
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ "make", "-C", dir, "-f", this->CurrentXCodeHackMakefile,
"OBJDIR=$(OBJDIR)", /* placeholder, see below */ "" });
// Add ZERO_CHECK
bool regenerate = !this->GlobalSettingIsOn("CMAKE_SUPPRESS_REGENERATION");
......@@ -530,7 +527,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
cmSystemTools::ReplaceString(file, "\\ ", " ");
cmTarget* check = mf->AddUtilityCommand(
CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator,
true, no_depends, no_working_directory, "make", "-f", file.c_str());
true, no_working_directory, no_depends,
cmMakeSingleCommandLine({ "make", "-f", file }));
cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root);
root->AddGeneratorTarget(checkGt);
......@@ -555,10 +553,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets(
// this will make sure that when the next target is built
// things are up-to-date
if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
makeHelper.back() = // fill placeholder
commandLines.front().back() = // fill placeholder
this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)");
cmCustomCommandLines commandLines;
commandLines.push_back(makeHelper);
std::vector<std::string> no_byproducts;
gen->GetMakefile()->AddCustomCommandToTarget(
target->GetName(), no_byproducts, no_depends, commandLines,
......@@ -1440,19 +1436,14 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(
if (gtgt->GetType() == cmStateEnums::SHARED_LIBRARY &&
!gtgt->IsFrameworkOnApple()) {
cmCustomCommandLines cmd;
cmd.resize(1);
cmd[0].push_back(cmSystemTools::GetCMakeCommand());
cmd[0].push_back("-E");
cmd[0].push_back("cmake_symlink_library");
std::string str_file = cmStrCat("$<TARGET_FILE:", gtgt->GetName(), '>');
std::string str_so_file =
cmStrCat("$<TARGET_SONAME_FILE:", gtgt->GetName(), '>');
std::string str_link_file =
cmStrCat("$<TARGET_LINKER_FILE:", gtgt->GetName(), '>');
cmd[0].push_back(str_file);
cmd[0].push_back(str_so_file);
cmd[0].push_back(str_link_file);
cmCustomCommandLines cmd = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), "-E", "cmake_symlink_library",
str_file, str_so_file, str_link_file });
cmCustomCommand command(this->CurrentMakefile, std::vector<std::string>(),
std::vector<std::string>(),
......
......@@ -92,11 +92,8 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
for (cmGeneratorTarget* l : tgts) {
if (l->GetType() == cmStateEnums::GLOBAL_TARGET) {
std::vector<std::string> no_depends;
cmCustomCommandLine force_command;
force_command.push_back("cd");
force_command.push_back(".");
cmCustomCommandLines force_commands;
force_commands.push_back(force_command);
cmCustomCommandLines force_commands =
cmMakeSingleCommandLine({ "cd", "." });
std::string no_main_dependency;
std::string force = cmStrCat(this->GetCurrentBinaryDirectory(),
"/CMakeFiles/", l->GetName(), "_force");
......@@ -246,21 +243,15 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule()
std::unique(listFiles.begin(), listFiles.end());
listFiles.erase(new_end, listFiles.end());
std::string argS = cmStrCat("-S", this->GetSourceDirectory());
std::string argB = cmStrCat("-B", this->GetBinaryDirectory());
std::string stampName =
cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/generate.stamp");
cmCustomCommandLine commandLine;
commandLine.push_back(cmSystemTools::GetCMakeCommand());
cmCustomCommandLines commandLines =
cmMakeSingleCommandLine({ cmSystemTools::GetCMakeCommand(), argS, argB,
"--check-stamp-file", stampName });
std::string comment = cmStrCat("Building Custom Rule ", makefileIn);
std::string args;
args = cmStrCat("-S", this->GetSourceDirectory());
commandLine.push_back(args);
args = cmStrCat("-B", this->GetBinaryDirectory());
commandLine.push_back(args);
commandLine.push_back("--check-stamp-file");
commandLine.push_back(stampName);
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
const char* no_working_directory = 0;
const char* no_working_directory = nullptr;
std::string fullpathStampName =
cmSystemTools::CollapseFullPath(stampName.c_str());
this->Makefile->AddCustomCommandToOutput(
......
......@@ -98,16 +98,11 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target,
}
// Add a pre-build event to create the directory.
cmCustomCommandLine command;
command.push_back(cmSystemTools::GetCMakeCommand());
command.push_back("-E");
command.push_back("make_directory");
command.push_back(impDir);
std::vector<std::string> no_output;
std::vector<std::string> no_byproducts;
std::vector<std::string> no_depends;
cmCustomCommandLines commands;
commands.push_back(command);
cmCustomCommandLines commands = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), "-E", "make_directory", impDir });
pcc.reset(new cmCustomCommand(0, no_output, no_byproducts, no_depends,
commands, 0, 0));
pcc->SetEscapeOldStyle(false);
......
......@@ -1173,35 +1173,6 @@ bool cmMakefile::AppendCustomCommandToOutput(
return false;
}
cmTarget* cmMakefile::AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const std::vector<std::string>& depends, const char* workingDirectory,
const char* command, const char* arg1, const char* arg2, const char* arg3,
const char* arg4)
{
// Construct the command line for the custom command.
cmCustomCommandLine commandLine;
commandLine.push_back(command);
if (arg1) {
commandLine.push_back(arg1);
}
if (arg2) {
commandLine.push_back(arg2);
}
if (arg3) {
commandLine.push_back(arg3);
}
if (arg4) {
commandLine.push_back(arg4);
}
cmCustomCommandLines commandLines;
commandLines.push_back(std::move(commandLine));
// Call the real signature of this method.
return this->AddUtilityCommand(utilityName, origin, excludeFromAll,
workingDirectory, depends, commandLines);
}
cmTarget* cmMakefile::AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& depends,
......
......@@ -243,14 +243,6 @@ public:
* 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,
TargetOrigin origin, bool excludeFromAll,
const std::vector<std::string>& depends,
const char* workingDirectory,
const char* command, const char* arg1 = nullptr,
const char* arg2 = nullptr,
const char* arg3 = nullptr,
const char* arg4 = nullptr);
cmTarget* AddUtilityCommand(
const std::string& utilityName, TargetOrigin origin, bool excludeFromAll,
const char* workingDirectory, const std::vector<std::string>& depends,
......
......@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmQTWrapCPPCommand.h"
#include <utility>
#include "cmCustomCommandLines.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
......@@ -65,14 +63,8 @@ bool cmQTWrapCPPCommand(std::vector<std::string> const& args,
sourceListValue += newName;
// Create the custom command to generate the file.
cmCustomCommandLine commandLine;
commandLine.push_back(moc_exe);
commandLine.push_back("-o");
commandLine.push_back(newName);
commandLine.push_back(hname);
cmCustomCommandLines commandLines;
commandLines.push_back(std::move(commandLine));
cmCustomCommandLines commandLines =
cmMakeSingleCommandLine({ moc_exe, "-o", newName, hname });
std::vector<std::string> depends;
depends.push_back(moc_exe);
......
......@@ -2,8 +2,6 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmQTWrapUICommand.h"
#include <utility>
#include "cmCustomCommandLines.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
......@@ -76,31 +74,12 @@ bool cmQTWrapUICommand(std::vector<std::string> const& args,
sourceListValue += mocName;
// set up .ui to .h and .cxx command
cmCustomCommandLine hCommand;
hCommand.push_back(uic_exe);
hCommand.push_back("-o");
hCommand.push_back(hName);
hCommand.push_back(uiName);
cmCustomCommandLines hCommandLines;
hCommandLines.push_back(std::move(hCommand));
cmCustomCommandLine cxxCommand;
cxxCommand.push_back(uic_exe);
cxxCommand.push_back("-impl");
cxxCommand.push_back(hName);
cxxCommand.push_back("-o");
cxxCommand.push_back(cxxName);
cxxCommand.push_back(uiName);
cmCustomCommandLines cxxCommandLines;
cxxCommandLines.push_back(std::move(cxxCommand));
cmCustomCommandLine mocCommand;
mocCommand.push_back(moc_exe);
mocCommand.push_back("-o");
mocCommand.push_back(mocName);
mocCommand.push_back(hName);
cmCustomCommandLines mocCommandLines;
mocCommandLines.push_back(std::move(mocCommand));
cmCustomCommandLines hCommandLines =
cmMakeSingleCommandLine({ uic_exe, "-o", hName, uiName });
cmCustomCommandLines cxxCommandLines = cmMakeSingleCommandLine(
{ uic_exe, "-impl", hName, "-o", cxxName, uiName });
cmCustomCommandLines mocCommandLines =
cmMakeSingleCommandLine({ moc_exe, "-o", mocName, hName });
std::vector<std::string> depends;
depends.push_back(uiName);
......
......@@ -957,16 +957,9 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
}
// Compose command lines
cmCustomCommandLines commandLines;
{
cmCustomCommandLine currentLine;
currentLine.push_back(cmSystemTools::GetCMakeCommand());
currentLine.push_back("-E");
currentLine.push_back("cmake_autogen");
currentLine.push_back(this->AutogenTarget.InfoFile);
currentLine.push_back("$<CONFIGURATION>");
commandLines.push_back(std::move(currentLine));
}
cmCustomCommandLines commandLines = cmMakeSingleCommandLine(
{ cmSystemTools::GetCMakeCommand(), "-E", "cmake_autogen",
this->AutogenTarget.InfoFile, "$<CONFIGURATION>" });
// Use PRE_BUILD on demand
bool usePRE_BUILD = false;
......@@ -1100,22 +1093,14 @@ bool cmQtAutoGenInitializer::InitRccTargets()
if (this->MultiConfig) {
// Build for all configurations
for (std::string const& config : this->ConfigsList) {
cmCustomCommandLine currentLine;
currentLine.push_back(cmSystemTools::GetCMakeCommand());
currentLine.push_back("-E");
currentLine.push_back("cmake_autorcc");
currentLine.push_back(qrc.InfoFile);
currentLine.push_back(config);
commandLines.push_back(std::move(currentLine));
commandLines.push_back(
cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
"cmake_autorcc", qrc.InfoFile, config }));
}
} else {
cmCustomCommandLine currentLine;
currentLine.push_back(cmSystemTools::GetCMakeCommand());
currentLine.push_back("-E");
currentLine.push_back("cmake_autorcc");
currentLine.push_back(qrc.InfoFile);
currentLine.push_back("$<CONFIG>");
commandLines.push_back(std::move(currentLine));
commandLines.push_back(
cmMakeCommandLine({ cmSystemTools::GetCMakeCommand(), "-E",
"cmake_autorcc", qrc.InfoFile, "$<CONFIG>" }));
}
std::string ccComment = cmStrCat(
"Automatic RCC for ", FileProjectRelativePath(makefile, qrc.QrcFile));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment