2001-11-08 00:47:38 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2001-11-08 00:47:38 +03:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
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
|
2002-12-12 02:13:33 +03:00
|
|
|
bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2001-11-09 18:42:16 +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.
|
2001-11-09 18:33:22 +03:00
|
|
|
*/
|
2002-12-12 02:13:33 +03:00
|
|
|
if (args.size() < 4)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
|
|
|
this->SetError("called with wrong number of arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
std::string source, command, target, comment, output, main_dependency;
|
2001-11-09 18:33:22 +03:00
|
|
|
std::vector<std::string> command_args, depends, outputs;
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD;
|
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
enum tdoing {
|
|
|
|
doing_source,
|
|
|
|
doing_command,
|
|
|
|
doing_target,
|
|
|
|
doing_args,
|
|
|
|
doing_depends,
|
2003-06-03 18:30:23 +04:00
|
|
|
doing_main_dependency,
|
|
|
|
doing_output,
|
2001-11-09 18:33:22 +03:00
|
|
|
doing_outputs,
|
2002-12-11 00:47:37 +03:00
|
|
|
doing_comment,
|
2001-11-09 18:33:22 +03:00
|
|
|
doing_nothing
|
|
|
|
};
|
|
|
|
|
|
|
|
tdoing doing = doing_nothing;
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
for (unsigned int j = 0; j < args.size(); ++j)
|
2001-11-08 00:47:38 +03:00
|
|
|
{
|
2002-03-06 02:41:24 +03:00
|
|
|
std::string const& copy = args[j];
|
2001-11-09 18:33:22 +03:00
|
|
|
|
|
|
|
if(copy == "SOURCE")
|
|
|
|
{
|
|
|
|
doing = doing_source;
|
|
|
|
}
|
|
|
|
else if(copy == "COMMAND")
|
|
|
|
{
|
|
|
|
doing = doing_command;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2001-11-09 18:33:22 +03:00
|
|
|
else if(copy == "TARGET")
|
|
|
|
{
|
|
|
|
doing = doing_target;
|
|
|
|
}
|
|
|
|
else if(copy == "ARGS")
|
|
|
|
{
|
|
|
|
doing = doing_args;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2002-12-11 00:47:37 +03:00
|
|
|
else if (copy == "COMMENT")
|
|
|
|
{
|
|
|
|
doing = doing_comment;
|
|
|
|
}
|
2001-11-09 18:33:22 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (doing)
|
|
|
|
{
|
|
|
|
case doing_source:
|
|
|
|
source = copy;
|
|
|
|
break;
|
2003-06-03 18:30:23 +04:00
|
|
|
case doing_output:
|
|
|
|
output = copy;
|
|
|
|
break;
|
|
|
|
case doing_main_dependency:
|
|
|
|
main_dependency = copy;
|
|
|
|
break;
|
2001-11-09 18:33:22 +03:00
|
|
|
case doing_command:
|
|
|
|
command = copy;
|
|
|
|
break;
|
|
|
|
case doing_target:
|
|
|
|
target = copy;
|
|
|
|
break;
|
|
|
|
case doing_args:
|
|
|
|
command_args.push_back(copy);
|
|
|
|
break;
|
|
|
|
case doing_depends:
|
|
|
|
depends.push_back(copy);
|
|
|
|
break;
|
|
|
|
case doing_outputs:
|
|
|
|
outputs.push_back(copy);
|
|
|
|
break;
|
2002-12-11 00:47:37 +03:00
|
|
|
case doing_comment:
|
|
|
|
comment = copy;
|
|
|
|
break;
|
2001-11-09 18:33:22 +03:00
|
|
|
default:
|
|
|
|
this->SetError("Wrong syntax. Unknow type of argument.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2001-11-08 00:47:38 +03:00
|
|
|
}
|
2001-11-08 22:34:51 +03:00
|
|
|
|
2001-11-09 18:33:22 +03:00
|
|
|
/* At this point we could complain about the lack of arguments.
|
2002-04-11 18:05:47 +04:00
|
|
|
For the moment, let's say that COMMAND, TARGET are always
|
2001-11-09 18:33:22 +03:00
|
|
|
required.
|
|
|
|
*/
|
2003-06-03 18:30:23 +04:00
|
|
|
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.");
|
2001-11-09 18:33:22 +03:00
|
|
|
return false;
|
2001-11-08 00:47:38 +03:00
|
|
|
}
|
2003-06-03 18:30:23 +04:00
|
|
|
|
|
|
|
// If source is empty, use the target
|
|
|
|
if(source.empty() && output.empty())
|
|
|
|
{
|
|
|
|
m_Makefile->AddCustomCommandToTarget(target.c_str(),
|
|
|
|
command.c_str(),
|
|
|
|
command_args,
|
|
|
|
cctype,
|
|
|
|
comment.c_str());
|
|
|
|
return true;
|
|
|
|
}
|
2002-04-11 18:05:47 +04:00
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
// If target is empty, use the output
|
|
|
|
if(target.empty())
|
2002-04-11 18:05:47 +04:00
|
|
|
{
|
2003-06-03 18:30:23 +04:00
|
|
|
m_Makefile->AddCustomCommandToOutput(output.c_str(),
|
|
|
|
command.c_str(),
|
|
|
|
command_args,
|
|
|
|
main_dependency.c_str(),
|
|
|
|
depends,
|
|
|
|
comment.c_str());
|
|
|
|
return true;
|
2002-04-11 18:05:47 +04:00
|
|
|
}
|
|
|
|
|
2003-06-03 18:30:23 +04:00
|
|
|
// otherwise backwards compatiblity mode
|
2001-11-09 18:33:22 +03:00
|
|
|
m_Makefile->AddCustomCommand(source.c_str(),
|
|
|
|
command.c_str(),
|
|
|
|
command_args,
|
2002-10-24 02:03:27 +04:00
|
|
|
depends,
|
2001-11-08 22:34:51 +03:00
|
|
|
outputs,
|
2002-12-11 00:47:37 +03:00
|
|
|
target.c_str(),
|
|
|
|
comment.c_str());
|
2002-01-04 00:02:43 +03:00
|
|
|
|
2001-11-08 00:47:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-04 00:02:43 +03:00
|
|
|
|