ENH: check in almost building VMS stuff with VMSBuild directory since the bootstrap...
[cmake.git] / Source / cmAddCustomTargetCommand.cxx
blob425718bdebea70115314ef14db2ecfedf509389c
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomTargetCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-10-09 15:01:23 $
7 Version: $Revision: 1.38 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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 "cmAddCustomTargetCommand.h"
19 // cmAddCustomTargetCommand
20 bool cmAddCustomTargetCommand
21 ::InitialPass(std::vector<std::string> const& args,
22 cmExecutionStatus&)
24 if(args.size() < 1 )
26 this->SetError("called with incorrect number of arguments");
27 return false;
30 // Check the target name.
31 if(args[0].find_first_of("/\\") != args[0].npos)
33 if(!this->Makefile->NeedBackwardsCompatibility(2,2))
35 cmOStringStream e;
36 e << "called with invalid target name \"" << args[0]
37 << "\". Target names may not contain a slash. "
38 << "Use ADD_CUSTOM_COMMAND to generate files. "
39 << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.2 "
40 << "or lower to skip this check.";
41 this->SetError(e.str().c_str());
42 return false;
46 // Accumulate one command line at a time.
47 cmCustomCommandLine currentLine;
49 // Save all command lines.
50 cmCustomCommandLines commandLines;
52 // Accumulate dependencies.
53 std::vector<std::string> depends;
54 std::string working_directory;
55 bool verbatim = false;
56 std::string comment_buffer;
57 const char* comment = 0;
58 std::vector<std::string> sources;
60 // Keep track of parser state.
61 enum tdoing {
62 doing_command,
63 doing_depends,
64 doing_working_directory,
65 doing_comment,
66 doing_source,
67 doing_verbatim
69 tdoing doing = doing_command;
71 // Look for the ALL option.
72 bool excludeFromAll = true;
73 unsigned int start = 1;
74 if(args.size() > 1)
76 if(args[1] == "ALL")
78 excludeFromAll = false;
79 start = 2;
83 // Parse the rest of the arguments.
84 for(unsigned int j = start; j < args.size(); ++j)
86 std::string const& copy = args[j];
88 if(copy == "DEPENDS")
90 doing = doing_depends;
92 else if(copy == "WORKING_DIRECTORY")
94 doing = doing_working_directory;
96 else if(copy == "VERBATIM")
98 doing = doing_verbatim;
99 verbatim = true;
101 else if (copy == "COMMENT")
103 doing = doing_comment;
105 else if(copy == "COMMAND")
107 doing = doing_command;
109 // Save the current command before starting the next command.
110 if(!currentLine.empty())
112 commandLines.push_back(currentLine);
113 currentLine.clear();
116 else if(copy == "SOURCES")
118 doing = doing_source;
120 else
122 switch (doing)
124 case doing_working_directory:
125 working_directory = copy;
126 break;
127 case doing_command:
128 currentLine.push_back(copy);
129 break;
130 case doing_depends:
131 depends.push_back(copy);
132 break;
133 case doing_comment:
134 comment_buffer = copy;
135 comment = comment_buffer.c_str();
136 break;
137 case doing_source:
138 sources.push_back(copy);
139 break;
140 default:
141 this->SetError("Wrong syntax. Unknown type of argument.");
142 return false;
147 std::string::size_type pos = args[0].find_first_of("#<>");
148 if(pos != args[0].npos)
150 cmOStringStream msg;
151 msg << "called with target name containing a \"" << args[0][pos]
152 << "\". This character is not allowed.";
153 this->SetError(msg.str().c_str());
154 return false;
157 // Store the last command line finished.
158 if(!currentLine.empty())
160 commandLines.push_back(currentLine);
161 currentLine.clear();
164 // Enforce name uniqueness.
166 std::string msg;
167 if(!this->Makefile->EnforceUniqueName(args[0], msg, true))
169 this->SetError(msg.c_str());
170 return false;
174 // Add the utility target to the makefile.
175 bool escapeOldStyle = !verbatim;
176 cmTarget* target =
177 this->Makefile->AddUtilityCommand(args[0].c_str(), excludeFromAll,
178 working_directory.c_str(), depends,
179 commandLines, escapeOldStyle, comment);
181 // Add additional user-specified source files to the target.
182 target->AddSources(sources);
184 return true;