ENH: separate command from its arguments in the custom command. This allows the generator on windows to change the slashes for just the command

This commit is contained in:
Bill Hoffman 2001-09-04 16:07:54 -04:00
parent ecff0d36ac
commit cc5c1fa6f7
10 changed files with 75 additions and 37 deletions

View File

@ -53,25 +53,32 @@ bool cmAddCustomTargetCommand::InitialPass(std::vector<std::string>& args)
m_Makefile->ExpandVariablesInString(args[0]);
// all target option
std::string result;
std::string arguments;
std::vector<std::string>::iterator s = args.begin();
++s;
++s; // move past args[0] as it is already to be used
if (args.size() >= 3)
{
if (args[1] == "ALL")
{
all = true;
++s;
++s; // skip all
}
}
std::string command;
if(s != args.end())
{
command = m_Makefile->ExpandVariablesInString(*s);
++s;
}
for (;s != args.end(); ++s)
{
m_Makefile->ExpandVariablesInString(*s);
result += cmSystemTools::EscapeSpaces(s->c_str());
result += " ";
arguments += cmSystemTools::EscapeSpaces(s->c_str());
arguments += " ";
}
m_Makefile->AddUtilityCommand(args[0].c_str(),
result.c_str(), all);
command.c_str(),
arguments.c_str(), all);
return true;
}

View File

@ -45,10 +45,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The constructor
*/
cmCustomCommand::cmCustomCommand(const char *src, const char *command,
const char* arguments,
std::vector<std::string> dep,
std::vector<std::string> out):
m_Source(src),
m_Command(command),
m_Arguments(arguments),
m_Depends(dep),
m_Outputs(out)
{
@ -61,6 +63,7 @@ cmCustomCommand::cmCustomCommand(const char *src, const char *command,
cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
m_Source(r.m_Source),
m_Command(r.m_Command),
m_Arguments(r.m_Arguments),
m_Depends(r.m_Depends),
m_Outputs(r.m_Outputs)
{
@ -70,6 +73,7 @@ void cmCustomCommand::ExpandVariables(const cmMakefile &mf)
{
mf.ExpandVariablesInString(m_Source);
mf.ExpandVariablesInString(m_Command);
mf.ExpandVariablesInString(m_Arguments);
for (std::vector<std::string>::iterator i = m_Depends.begin();
i != m_Depends.end(); ++i)

View File

@ -53,6 +53,7 @@ class cmCustomCommand
{
public:
cmCustomCommand(const char *src, const char *command,
const char* arguments,
std::vector<std::string> dep,
std::vector<std::string> out);
cmCustomCommand(const cmCustomCommand& r);
@ -69,11 +70,17 @@ public:
std::string GetSourceName() const {return m_Source;}
void SetSourceName(const char *name) {m_Source = name;}
/**
* Return the command to execute
*/
///! Return the command to execute with arguments
std::string GetCommandAndArguments() const
{return m_Command + " " + m_Arguments;}
///! Return the command to execute
std::string GetCommand() const {return m_Command;}
void SetCommand(const char *cmd) {m_Command = cmd;}
///! Return the commands arguments
std::string GetArguments() const {return m_Arguments;}
void SetArguments(const char *arg) {m_Arguments = arg;}
/**
* Return the vector that holds the list of dependencies
@ -90,6 +97,7 @@ public:
private:
std::string m_Source;
std::string m_Command;
std::string m_Arguments;
std::vector<std::string> m_Depends;
std::vector<std::string> m_Outputs;
};

View File

@ -152,21 +152,22 @@ void cmDSPWriter::AddDSPBuildRule(cmSourceGroup& sourceGroup)
std::string dsprule = "${CMAKE_COMMAND} ";
m_Makefile->ExpandVariablesInString(dsprule);
dsprule = cmSystemTools::HandleNetworkPaths(dsprule.c_str());
dsprule += makefileIn;
dsprule += " -DSP -H\"";
dsprule += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeDirectory());
dsprule += "\" -S\"";
dsprule += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartDirectory());
dsprule += "\" -O\"";
dsprule += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartOutputDirectory());
dsprule += "\" -B\"";
dsprule += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeOutputDirectory());
dsprule += "\"";
m_Makefile->ExpandVariablesInString(dsprule);
std::string args = makefileIn;
args += " -DSP -H\"";
args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeDirectory());
args += "\" -S\"";
args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartDirectory());
args += "\" -O\"";
args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetStartOutputDirectory());
args += "\" -B\"";
args += cmSystemTools::HandleNetworkPaths(m_Makefile->GetHomeOutputDirectory());
args += "\"";
m_Makefile->ExpandVariablesInString(args);
std::vector<std::string> outputs;
outputs.push_back(dspname);
cmCustomCommand cc(makefileIn.c_str(), dsprule.c_str(),
args.c_str(),
m_Makefile->GetListFiles(),
outputs);
sourceGroup.AddCustomCommand(cc);
@ -263,9 +264,11 @@ void cmDSPWriter::WriteDSPFile(std::ostream& fout,
c != commands.end(); ++c)
{
totalCommandStr += "\n\t";
temp= c->first;
temp= c->second.m_Command;
cmSystemTools::ConvertToWindowsSlashes(temp);
totalCommandStr += temp;
totalCommandStr += " ";
totalCommandStr += c->second.m_Arguments;
totalCommand.Merge(c->second);
}
// Create a dummy file with the name of the source if it does

View File

@ -102,7 +102,8 @@ void cmDSWWriter::WriteDSWFile(std::ostream& fout)
allListFiles.push_back(m_Makefile);
// add a special target that depends on ALL projects for easy build
// of Debug only
m_Makefile->AddUtilityCommand("ALL_BUILD", "echo \"Build all projects\"", false);
m_Makefile->AddUtilityCommand("ALL_BUILD", "echo", "\"Build all projects\"",
false);
m_Makefile->FindSubDirectoryCMakeListsFiles(allListFiles);
// For each cmMakefile, create a DSP for it, and
// add it to this DSW file

View File

@ -470,9 +470,7 @@ void cmMakefile::AddCustomCommand(const char* source,
if (m_Targets.find(target) != m_Targets.end())
{
std::string c = cmSystemTools::EscapeSpaces(command);
c += " ";
c += commandArgs;
cmCustomCommand cc(source,c.c_str(),depends,outputs);
cmCustomCommand cc(source,c.c_str(),commandArgs,depends,outputs);
m_Targets[target].GetCustomCommands().push_back(cc);
std::string cacheCommand = command;
this->ExpandVariablesInString(cacheCommand);
@ -707,15 +705,17 @@ void cmMakefile::AddExecutable(const char *exeName,
void cmMakefile::AddUtilityCommand(const char* utilityName,
const char* command,
const char* arguments,
bool all)
{
std::vector<std::string> empty;
this->AddUtilityCommand(utilityName,command,all,
this->AddUtilityCommand(utilityName,command,arguments,all,
empty,empty);
}
void cmMakefile::AddUtilityCommand(const char* utilityName,
const char* command,
const char* arguments,
bool all,
const std::vector<std::string> &dep,
const std::vector<std::string> &out)
@ -723,7 +723,7 @@ void cmMakefile::AddUtilityCommand(const char* utilityName,
cmTarget target;
target.SetType(cmTarget::UTILITY);
target.SetInAll(all);
cmCustomCommand cc(utilityName, command, dep, out);
cmCustomCommand cc(utilityName, command, arguments, dep, out);
target.GetCustomCommands().push_back(cc);
m_Targets.insert(cmTargets::value_type(utilityName,target));
}

View File

@ -167,9 +167,11 @@ public:
*/
void AddUtilityCommand(const char* utilityName,
const char* command,
const char* arguments,
bool all);
void AddUtilityCommand(const char* utilityName,
const char* command,
const char* arguments,
bool all,
const std::vector<std::string> &depends,
const std::vector<std::string> &outputs);

View File

@ -94,32 +94,40 @@ void cmSourceGroup::AddSource(const char* name)
*/
void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
{
std::string commandAndArgs = cmd.GetCommandAndArguments();
BuildRules::iterator s = m_BuildRules.find(cmd.GetSourceName());
if(s == m_BuildRules.end())
{
// The source was not found. Add it with this command.
m_BuildRules[cmd.GetSourceName()][cmd.GetCommand()].
m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
m_BuildRules[cmd.GetSourceName()][cmd.GetCommand()].
m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
CommandFiles& cmdFiles = m_BuildRules[cmd.GetSourceName()][commandAndArgs];
cmdFiles.m_Command = cmd.GetCommand();
cmdFiles.m_Arguments = cmd.GetArguments();
cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
return;
}
// The source already exists. See if the command exists.
Commands& commands = s->second;
Commands::iterator c = commands.find(cmd.GetCommand());
Commands::iterator c = commands.find(commandAndArgs);
if(c == commands.end())
{
// The command did not exist. Add it.
commands[cmd.GetCommand()].m_Depends.insert(cmd.GetDepends().begin(), cmd.GetDepends().end());
commands[cmd.GetCommand()].m_Outputs.insert(cmd.GetOutputs().begin(), cmd.GetOutputs().end());
commands[commandAndArgs].m_Command = cmd.GetCommand();
commands[commandAndArgs].m_Arguments = cmd.GetArguments();
commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
cmd.GetDepends().end());
commands[commandAndArgs].m_Outputs.insert(cmd.GetOutputs().begin(),
cmd.GetOutputs().end());
return;
}
// The command already exists for this source. Merge the sets.
CommandFiles& commandFiles = c->second;
commandFiles.m_Depends.insert(cmd.GetDepends().begin(), cmd.GetDepends().end());
commandFiles.m_Outputs.insert(cmd.GetOutputs().begin(), cmd.GetOutputs().end());
commandFiles.m_Depends.insert(cmd.GetDepends().begin(),
cmd.GetDepends().end());
commandFiles.m_Outputs.insert(cmd.GetOutputs().begin(),
cmd.GetOutputs().end());
}
void cmSourceGroup::Print() const
@ -132,7 +140,9 @@ void cmSourceGroup::Print() const
for(Commands::const_iterator j = i->second.begin();
j != i->second.end(); ++j)
{
std::cout << "Command: " << j->first.c_str() << "\n";
std::cout << "FullCommand: " << j->first.c_str() << "\n";
std::cout << "Command: " << j->second.m_Command.c_str() << "\n";
std::cout << "Arguments: " << j->second.m_Arguments.c_str() << "\n";
std::cout << "Command Outputs " << j->second.m_Outputs.size() << "\n";
std::cout << "Command Depends " << j->second.m_Depends.size() << "\n";
}

View File

@ -67,6 +67,8 @@ public:
void Merge(const CommandFiles &r);
std::string m_Command;
std::string m_Arguments;
std::set<std::string> m_Outputs;
std::set<std::string> m_Depends;
};

View File

@ -139,6 +139,7 @@ void cmVTKWrapJavaCommand::FinalPass()
}
m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(),
"",
"",
true,
alldepends,