FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmAddCustomCommandCommand.cxx
blobf7b050857bd955cddb5e51ceba7669be2e1a76d3
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmAddCustomCommandCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-05-22 17:20:54 $
7 Version: $Revision: 1.13 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmAddCustomCommandCommand.h"
20 // cmAddCustomCommandCommand
21 bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& argsIn)
23 /* Let's complain at the end of this function about the lack of a particular
24 arg. For the moment, let's say that COMMAND, TARGET are always
25 required.
27 if (argsIn.size() < 4)
29 this->SetError("called with wrong number of arguments.");
30 return false;
32 std::vector<std::string> args;
33 cmSystemTools::ExpandListArguments(argsIn, args);
35 std::string source, command, target;
36 std::vector<std::string> command_args, depends, outputs;
37 std::string outDir = m_Makefile->GetCurrentOutputDirectory();
39 enum tdoing {
40 doing_source,
41 doing_command,
42 doing_target,
43 doing_args,
44 doing_depends,
45 doing_outputs,
46 doing_nothing
49 tdoing doing = doing_nothing;
51 for (unsigned int j = 0; j < args.size(); ++j)
53 std::string const& copy = args[j];
55 if(copy == "SOURCE")
57 doing = doing_source;
59 else if(copy == "COMMAND")
61 doing = doing_command;
63 else if(copy == "TARGET")
65 doing = doing_target;
67 else if(copy == "ARGS")
69 doing = doing_args;
71 else if (copy == "DEPENDS")
73 doing = doing_depends;
75 else if (copy == "OUTPUTS")
77 doing = doing_outputs;
79 else
81 switch (doing)
83 case doing_source:
84 source = copy;
85 break;
86 case doing_command:
87 command = copy;
88 break;
89 case doing_target:
90 target = copy;
91 break;
92 case doing_args:
93 command_args.push_back(copy);
94 break;
95 case doing_depends:
96 depends.push_back(copy);
97 break;
98 case doing_outputs:
99 outputs.push_back(copy);
100 break;
101 default:
102 this->SetError("Wrong syntax. Unknow type of argument.");
103 return false;
108 /* At this point we could complain about the lack of arguments.
109 For the moment, let's say that COMMAND, TARGET are always
110 required.
113 if(command.empty())
115 this->SetError("Wrong syntax. Empty COMMAND.");
116 return false;
118 if(target.empty())
120 this->SetError("Wrong syntax. Empty TARGET.");
121 return false;
124 // If source is empty, use target as source, so that this command
125 // can be used to just attach a commmand to a target
127 if(source.empty())
129 source = target;
132 m_Makefile->AddCustomCommand(source.c_str(),
133 command.c_str(),
134 command_args,
135 depends,
136 outputs,
137 target.c_str());
139 return true;