Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmCustomCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmCustomCommand.h"
13
14 #include "cmMakefile.h"
15
16 #include <cmsys/auto_ptr.hxx>
17
18 //----------------------------------------------------------------------------
19 cmCustomCommand::cmCustomCommand()
20 {
21   this->HaveComment = false;
22   this->EscapeOldStyle = true;
23   this->EscapeAllowMakeVars = false;
24 }
25
26 //----------------------------------------------------------------------------
27 cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
28   Outputs(r.Outputs),
29   Depends(r.Depends),
30   CommandLines(r.CommandLines),
31   HaveComment(r.HaveComment),
32   Comment(r.Comment),
33   WorkingDirectory(r.WorkingDirectory),
34   EscapeAllowMakeVars(r.EscapeAllowMakeVars),
35   EscapeOldStyle(r.EscapeOldStyle),
36   Backtrace(new cmListFileBacktrace(*r.Backtrace))
37 {
38 }
39
40 //----------------------------------------------------------------------------
41 cmCustomCommand& cmCustomCommand::operator=(cmCustomCommand const& r)
42 {
43   if(this == &r)
44     {
45     return *this;
46     }
47
48   this->Outputs = r.Outputs;
49   this->Depends = r.Depends;
50   this->CommandLines = r.CommandLines;
51   this->HaveComment = r.HaveComment;
52   this->Comment = r.Comment;
53   this->WorkingDirectory = r.WorkingDirectory;
54   this->EscapeAllowMakeVars = r.EscapeAllowMakeVars;
55   this->EscapeOldStyle = r.EscapeOldStyle;
56   this->ImplicitDepends = r.ImplicitDepends;
57
58   cmsys::auto_ptr<cmListFileBacktrace>
59     newBacktrace(new cmListFileBacktrace(*r.Backtrace));
60   delete this->Backtrace;
61   this->Backtrace = newBacktrace.release();
62
63   return *this;
64 }
65
66 //----------------------------------------------------------------------------
67 cmCustomCommand::cmCustomCommand(cmMakefile* mf,
68                                  const std::vector<std::string>& outputs,
69                                  const std::vector<std::string>& depends,
70                                  const cmCustomCommandLines& commandLines,
71                                  const char* comment,
72                                  const char* workingDirectory):
73   Outputs(outputs),
74   Depends(depends),
75   CommandLines(commandLines),
76   HaveComment(comment?true:false),
77   Comment(comment?comment:""),
78   WorkingDirectory(workingDirectory?workingDirectory:""),
79   EscapeAllowMakeVars(false),
80   EscapeOldStyle(true),
81   Backtrace(new cmListFileBacktrace)
82 {
83   this->EscapeOldStyle = true;
84   this->EscapeAllowMakeVars = false;
85   if(mf)
86     {
87     mf->GetBacktrace(*this->Backtrace);
88     }
89 }
90
91 //----------------------------------------------------------------------------
92 cmCustomCommand::~cmCustomCommand()
93 {
94   delete this->Backtrace;
95 }
96
97 //----------------------------------------------------------------------------
98 const std::vector<std::string>& cmCustomCommand::GetOutputs() const
99 {
100   return this->Outputs;
101 }
102
103 //----------------------------------------------------------------------------
104 const char* cmCustomCommand::GetWorkingDirectory() const
105 {
106   if(this->WorkingDirectory.size() == 0)
107     {
108     return 0;
109     }
110   return this->WorkingDirectory.c_str();
111 }
112
113 //----------------------------------------------------------------------------
114 const std::vector<std::string>& cmCustomCommand::GetDepends() const
115 {
116   return this->Depends;
117 }
118
119 //----------------------------------------------------------------------------
120 const cmCustomCommandLines& cmCustomCommand::GetCommandLines() const
121 {
122   return this->CommandLines;
123 }
124
125 //----------------------------------------------------------------------------
126 const char* cmCustomCommand::GetComment() const
127 {
128   const char* no_comment = 0;
129   return this->HaveComment? this->Comment.c_str() : no_comment;
130 }
131
132 //----------------------------------------------------------------------------
133 void cmCustomCommand::AppendCommands(const cmCustomCommandLines& commandLines)
134 {
135   for(cmCustomCommandLines::const_iterator i=commandLines.begin();
136       i != commandLines.end(); ++i)
137     {
138     this->CommandLines.push_back(*i);
139     }
140 }
141
142 //----------------------------------------------------------------------------
143 void cmCustomCommand::AppendDepends(const std::vector<std::string>& depends)
144 {
145   for(std::vector<std::string>::const_iterator i=depends.begin();
146       i != depends.end(); ++i)
147     {
148     this->Depends.push_back(*i);
149     }
150 }
151
152 //----------------------------------------------------------------------------
153 bool cmCustomCommand::GetEscapeOldStyle() const
154 {
155   return this->EscapeOldStyle;
156 }
157
158 //----------------------------------------------------------------------------
159 void cmCustomCommand::SetEscapeOldStyle(bool b)
160 {
161   this->EscapeOldStyle = b;
162 }
163
164 //----------------------------------------------------------------------------
165 bool cmCustomCommand::GetEscapeAllowMakeVars() const
166 {
167   return this->EscapeAllowMakeVars;
168 }
169
170 //----------------------------------------------------------------------------
171 void cmCustomCommand::SetEscapeAllowMakeVars(bool b)
172 {
173   this->EscapeAllowMakeVars = b;
174 }
175
176 //----------------------------------------------------------------------------
177 cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
178 {
179   return *this->Backtrace;
180 }
181
182 //----------------------------------------------------------------------------
183 cmCustomCommand::ImplicitDependsList const&
184 cmCustomCommand::GetImplicitDepends() const
185 {
186   return this->ImplicitDepends;
187 }
188
189 //----------------------------------------------------------------------------
190 void cmCustomCommand::SetImplicitDepends(ImplicitDependsList const& l)
191 {
192   this->ImplicitDepends = l;
193 }
194
195 //----------------------------------------------------------------------------
196 void cmCustomCommand::AppendImplicitDepends(ImplicitDependsList const& l)
197 {
198   this->ImplicitDepends.insert(this->ImplicitDepends.end(),
199                                l.begin(), l.end());
200 }