CMake/Source/cmAddCustomCommandCommand.cxx

231 lines
6.2 KiB
C++
Raw Normal View History

2001-11-08 00:47:38 +03:00
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
2001-11-08 00:47:38 +03:00
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
2001-11-08 00:47:38 +03:00
2002-01-21 23:30:43 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
2001-11-08 00:47:38 +03:00
=========================================================================*/
#include "cmAddCustomCommandCommand.h"
2003-06-03 18:30:23 +04:00
#include "cmTarget.h"
2001-11-08 00:47:38 +03:00
// cmAddCustomCommandCommand
bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
2001-11-08 00:47:38 +03:00
{
/* Let's complain at the end of this function about the lack of a particular
2003-06-03 18:30:23 +04:00
arg. For the moment, let's say that COMMAND, and either TARGET or SOURCE
are required.
*/
if (args.size() < 4)
2001-11-08 00:47:38 +03:00
{
this->SetError("called with wrong number of arguments.");
return false;
}
std::string source, target, comment, output, main_dependency;
std::vector<std::string> depends, outputs;
// Accumulate one command line at a time.
cmCustomCommandLine currentLine;
// Save all command lines.
cmCustomCommandLines commandLines;
2003-06-03 18:30:23 +04:00
cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
enum tdoing {
doing_source,
doing_command,
doing_target,
doing_depends,
2003-06-03 18:30:23 +04:00
doing_main_dependency,
doing_output,
doing_outputs,
doing_comment,
doing_nothing
};
tdoing doing = doing_nothing;
for (unsigned int j = 0; j < args.size(); ++j)
2001-11-08 00:47:38 +03:00
{
std::string const& copy = args[j];
if(copy == "SOURCE")
{
doing = doing_source;
}
else if(copy == "COMMAND")
{
doing = doing_command;
// Save the current command before starting the next command.
if(!currentLine.empty())
{
commandLines.push_back(currentLine);
currentLine.clear();
}
}
2003-06-03 18:30:23 +04:00
else if(copy == "PRE_BUILD")
{
cctype = cmTarget::PRE_BUILD;
}
else if(copy == "PRE_LINK")
{
cctype = cmTarget::PRE_LINK;
}
else if(copy == "POST_BUILD")
{
cctype = cmTarget::POST_BUILD;
}
else if(copy == "TARGET")
{
doing = doing_target;
}
else if(copy == "ARGS")
{
// Ignore this old keyword.
}
else if (copy == "DEPENDS")
{
doing = doing_depends;
}
else if (copy == "OUTPUTS")
{
doing = doing_outputs;
}
2003-06-03 18:30:23 +04:00
else if (copy == "OUTPUT")
{
doing = doing_output;
}
else if (copy == "MAIN_DEPENDENCY")
{
doing = doing_main_dependency;
}
else if (copy == "COMMENT")
{
doing = doing_comment;
}
else
{
std::string filename;
switch (doing)
{
2003-06-03 18:30:23 +04:00
case doing_output:
case doing_outputs:
if (!cmSystemTools::FileIsFullPath(copy.c_str()))
{
filename = m_Makefile->GetStartDirectory();
filename += "/";
}
filename += copy;
break;
case doing_source:
// We do not want to convert the argument to SOURCE because
// that option is only available for backward compatibility.
// Old-style use of this command may use the SOURCE==TARGET
// trick which we must preserve. If we convert the source
// to a full path then it will no longer equal the target.
default:
break;
}
switch (doing)
{
case doing_source:
source = copy;
break;
case doing_output:
output = filename;
break;
case doing_main_dependency:
main_dependency = copy;
break;
case doing_command:
currentLine.push_back(copy);
break;
case doing_target:
target = copy;
break;
case doing_depends:
depends.push_back(copy);
break;
case doing_outputs:
outputs.push_back(filename);
break;
case doing_comment:
comment = copy;
break;
default:
this->SetError("Wrong syntax. Unknown type of argument.");
return false;
}
}
2001-11-08 00:47:38 +03:00
}
// Store the last command line finished.
if(!currentLine.empty())
{
commandLines.push_back(currentLine);
currentLine.clear();
}
// At this point we could complain about the lack of arguments. For
// the moment, let's say that COMMAND, TARGET are always required.
if(output.empty() && target.empty())
2001-11-08 00:47:38 +03:00
{
2003-06-03 18:30:23 +04:00
this->SetError("Wrong syntax. A TARGET or OUTPUT must be specified.");
return false;
2001-11-08 00:47:38 +03:00
}
2003-07-15 20:52:16 +04:00
if(source.empty() && !target.empty() && !output.empty())
2003-07-15 20:52:16 +04:00
{
this->SetError("Wrong syntax. A TARGET and OUTPUT can not both be specified.");
return false;
}
std::string::size_type pos = output.find_first_of("#<>");
if(pos != output.npos)
{
cmOStringStream msg;
msg << "called with OUTPUT containing a \"" << output[pos]
<< "\". This character is not allowed.";
this->SetError(msg.str().c_str());
return false;
}
// Choose which mode of the command to use.
2003-06-03 18:30:23 +04:00
if(source.empty() && output.empty())
{
// Source is empty, use the target.
std::vector<std::string> no_depends;
m_Makefile->AddCustomCommandToTarget(target.c_str(), no_depends,
commandLines, cctype,
2003-06-03 18:30:23 +04:00
comment.c_str());
}
else if(target.empty())
{
// Target is empty, use the output.
m_Makefile->AddCustomCommandToOutput(output.c_str(), depends,
2003-06-03 18:30:23 +04:00
main_dependency.c_str(),
commandLines, comment.c_str());
}
else
{
// Use the old-style mode for backward compatibility.
m_Makefile->AddCustomCommandOldStyle(target.c_str(), outputs, depends,
source.c_str(), commandLines,
2003-06-03 18:30:23 +04:00
comment.c_str());
}
2001-11-08 00:47:38 +03:00
return true;
}