Commit 3893ee72 authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

Add comment support, so that you can see in build process what the custom command does

parent ab64db6e
......@@ -32,7 +32,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
std::vector<std::string> args;
cmSystemTools::ExpandListArguments(argsIn, args);
std::string source, command, target;
std::string source, command, target, comment;
std::vector<std::string> command_args, depends, outputs;
enum tdoing {
......@@ -42,6 +42,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
doing_args,
doing_depends,
doing_outputs,
doing_comment,
doing_nothing
};
......@@ -75,6 +76,10 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
{
doing = doing_outputs;
}
else if (copy == "COMMENT")
{
doing = doing_comment;
}
else
{
switch (doing)
......@@ -97,6 +102,9 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
case doing_outputs:
outputs.push_back(copy);
break;
case doing_comment:
comment = copy;
break;
default:
this->SetError("Wrong syntax. Unknow type of argument.");
return false;
......@@ -108,12 +116,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
For the moment, let's say that COMMAND, TARGET are always
required.
*/
if(command.empty())
{
this->SetError("Wrong syntax. Empty COMMAND.");
return false;
}
if(target.empty())
{
this->SetError("Wrong syntax. Empty TARGET.");
......@@ -133,7 +136,8 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
command_args,
depends,
outputs,
target.c_str());
target.c_str(),
comment.c_str());
return true;
}
......
......@@ -86,8 +86,8 @@ public:
virtual const char* GetFullDocumentation()
{
return
"ADD_CUSTOM_COMMAND([SOURCE source] COMMAND command TARGET target "
"[ARGS [args...]] [DEPENDS [depends...]] [OUTPUTS [outputs...]])\n"
"ADD_CUSTOM_COMMAND([SOURCE source] [COMMAND command] TARGET target "
"[ARGS [args...]] [DEPENDS [depends...]] [OUTPUTS [outputs...]] [COMMENT comment])\n"
"Add a custom command.";
}
......
......@@ -40,6 +40,7 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
m_Source(r.m_Source),
m_Command(r.m_Command),
m_Arguments(r.m_Arguments),
m_Comment(r.m_Comment),
m_Depends(r.m_Depends),
m_Outputs(r.m_Outputs)
{
......
......@@ -54,6 +54,10 @@ public:
std::string GetCommand() const {return m_Command;}
void SetCommand(const char *cmd) {m_Command = cmd;}
///! Return the command to execute
std::string GetComment() const {return m_Comment;}
void SetComment(const char *cm) {m_Comment = cm;}
///! Return the commands arguments
std::string GetArguments() const {return m_Arguments;}
void SetArguments(const char *arg) {m_Arguments = arg;}
......@@ -74,6 +78,7 @@ private:
std::string m_Source;
std::string m_Command;
std::string m_Arguments;
std::string m_Comment;
std::vector<std::string> m_Depends;
std::vector<std::string> m_Outputs;
};
......
......@@ -1785,6 +1785,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
{
// escape spaces and convert to native slashes path for
// the command
const char* comment = c->second.m_Comment.c_str();
std::string command = c->second.m_Command;
cmSystemTools::ReplaceString(command, "/./", "/");
command = cmSystemTools::ConvertToOutputPath(command.c_str());
......@@ -1811,7 +1812,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
}
// output rule
this->OutputMakeRule(fout,
"Custom command",
(*comment?comment:"Custom command"),
source.c_str(),
depends.c_str(),
command.c_str());
......@@ -1838,7 +1839,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
}
// output rule
this->OutputMakeRule(fout,
"Custom command",
(*comment?comment:"Custom command"),
output->c_str(),
depends.c_str(),
command.c_str());
......@@ -2511,7 +2512,8 @@ void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
{
replace = *i;
m_Makefile->ExpandVariablesInString(replace);
if(count == 0 && replace[0] != '-' && replace.find("echo") != 0
if(count == 0 && replace.find_first_not_of(" \t\n\r") != std::string::npos &&
replace[0] != '-' && replace.find("echo") != 0
&& replace.find("$(MAKE)") != 0)
{
std::string echostring = "Building ";
......
......@@ -415,7 +415,8 @@ void cmMakefile::AddCustomCommand(const char* source,
const std::vector<std::string>& commandArgs,
const std::vector<std::string>& depends,
const std::vector<std::string>& outputs,
const char *target)
const char *target,
const char *comment)
{
// find the target,
if (m_Targets.find(target) != m_Targets.end())
......@@ -434,6 +435,10 @@ void cmMakefile::AddCustomCommand(const char* source,
}
cmCustomCommand cc(source,c.c_str(),combinedArgs.c_str(),depends,outputs);
if ( comment && comment[0] )
{
cc.SetComment(comment);
}
m_Targets[target].GetCustomCommands().push_back(cc);
std::string cacheCommand = command;
this->ExpandVariablesInString(cacheCommand);
......
......@@ -123,7 +123,8 @@ public:
const std::vector<std::string>& commandArgs,
const std::vector<std::string>& depends,
const std::vector<std::string>& outputs,
const char *target);
const char *target,
const char *comment = 0);
void AddCustomCommand(const char* source,
const char* command,
......@@ -260,6 +261,8 @@ public:
{
m_cmCurrentDirectory = m_cmStartDirectory;
m_CurrentOutputDirectory = m_StartOutputDirectory;
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", m_cmCurrentDirectory.c_str());
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", m_CurrentOutputDirectory.c_str());
}
//@{
......@@ -323,6 +326,7 @@ public:
{
m_cmCurrentDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", m_cmCurrentDirectory.c_str());
}
const char* GetCurrentDirectory() const
{
......@@ -332,6 +336,7 @@ public:
{
m_CurrentOutputDirectory = lib;
cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory);
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", m_CurrentOutputDirectory.c_str());
}
const char* GetCurrentOutputDirectory() const
{
......
......@@ -80,6 +80,7 @@ void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
CommandFiles& cmdFiles =
m_BuildRules[cmd.GetSourceName()].m_Commands[commandAndArgs];
cmdFiles.m_Command = cmd.GetCommand();
cmdFiles.m_Comment = cmd.GetComment();
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());
......@@ -93,6 +94,7 @@ void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
{
// The command did not exist. Add it.
commands[commandAndArgs].m_Command = cmd.GetCommand();
commands[commandAndArgs].m_Comment = cmd.GetComment();
commands[commandAndArgs].m_Arguments = cmd.GetArguments();
commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
cmd.GetDepends().end());
......
......@@ -39,12 +39,13 @@ public:
{
CommandFiles() {}
CommandFiles(const CommandFiles& r):
m_Outputs(r.m_Outputs), m_Depends(r.m_Depends) {}
m_Comment(r.m_Comment), m_Outputs(r.m_Outputs), m_Depends(r.m_Depends) {}
void Merge(const CommandFiles &r);
std::string m_Command;
std::string m_Arguments;
std::string m_Comment;
std::set<std::string> m_Outputs;
std::set<std::string> m_Depends;
};
......
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