1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: cmAddCustomCommandCommand.cxx,v $
Language: C++
Date: $Date: 2002/01/03 21:02:42 $
Version: $Revision: 1.5 $
Copyright (c) 2000 National Library of Medicine
All rights reserved.
See COPYRIGHT.txt for copyright details.
=========================================================================*/
#include "cmAddCustomCommandCommand.h"
// cmAddCustomCommandCommand
bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
{
/* Let's complain at the end of this function about the lack of a particular
arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
required.
*/
if (args.size() < 6)
{
this->SetError("called with wrong number of arguments.");
return false;
}
std::string source, command, target;
std::vector<std::string> command_args, depends, outputs;
std::string outDir = m_Makefile->GetCurrentOutputDirectory();
enum tdoing {
doing_source,
doing_command,
doing_target,
doing_args,
doing_depends,
doing_outputs,
doing_nothing
};
tdoing doing = doing_nothing;
for (unsigned int j = 0; j < args.size(); ++j)
{
std::string copy = args[j];
m_Makefile->ExpandVariablesInString(copy);
if(copy == "SOURCE")
{
doing = doing_source;
}
else if(copy == "COMMAND")
{
doing = doing_command;
}
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;
}
else
{
switch (doing)
{
case doing_source:
source = copy;
break;
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;
default:
this->SetError("Wrong syntax. Unknow type of argument.");
return false;
}
}
}
/* At this point we could complain about the lack of arguments.
For the moment, let's say that SOURCE, COMMAND, TARGET are always
required.
*/
if(source.empty())
{
this->SetError("Wrong syntax. Empty SOURCE.");
return false;
}
if(command.empty())
{
this->SetError("Wrong syntax. Empty COMMAND.");
return false;
}
if(target.empty())
{
this->SetError("Wrong syntax. Empty TARGET.");
return false;
}
m_Makefile->AddCustomCommand(source.c_str(),
command.c_str(),
command_args,
depends,
outputs,
target.c_str());
int cc = outputs.size()-1;
while( cc >= 0 )
{
std::string fileName = outputs[cc];
std::string directory = cmSystemTools::GetFilenamePath(fileName);
if ( directory == std::string() )
{
directory = outDir;
}
fileName = cmSystemTools::GetFilenameName(fileName);
std::string::size_type pos = fileName.rfind(".");
fileName = fileName.substr(0, pos);
// Add the generated source to the package target's source list.
cmSourceFile file;
file.SetName(fileName.c_str(), directory.c_str(), "c", false);
m_Makefile->AddSource(file, target.c_str());
cc--;
}
m_Makefile->GetTargets()[target.c_str()].GetSourceLists().push_back(target);
return true;
}
|