CVS resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmAddCustomTargetCommand.cxx
blobe4f6951e832b0ad4dd7a82035eae513bf18ea559
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomTargetCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.27 $
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, cmExecutionStatus &)
23 if(args.size() < 1 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 // Check the target name.
30 if(args[0].find_first_of("/\\") != args[0].npos)
32 int major = 0;
33 int minor = 0;
34 if(const char* versionValue =
35 this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY"))
37 sscanf(versionValue, "%d.%d", &major, &minor);
39 if(!major || major > 3 || (major == 2 && minor > 2))
41 cmOStringStream e;
42 e << "called with invalid target name \"" << args[0]
43 << "\". Target names may not contain a slash. "
44 << "Use ADD_CUSTOM_COMMAND to generate files. "
45 << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.2 "
46 << "or lower to skip this check.";
47 this->SetError(e.str().c_str());
48 return false;
52 // Accumulate one command line at a time.
53 cmCustomCommandLine currentLine;
55 // Save all command lines.
56 cmCustomCommandLines commandLines;
58 // Accumulate dependencies.
59 std::vector<std::string> depends;
60 std::string working_directory;
61 bool verbatim = false;
62 std::string comment_buffer;
63 const char* comment = 0;
65 // Keep track of parser state.
66 enum tdoing {
67 doing_command,
68 doing_depends,
69 doing_working_directory,
70 doing_comment,
71 doing_verbatim
73 tdoing doing = doing_command;
75 // Look for the ALL option.
76 bool excludeFromAll = true;
77 unsigned int start = 1;
78 if(args.size() > 1)
80 if(args[1] == "ALL")
82 excludeFromAll = false;
83 start = 2;
87 // Parse the rest of the arguments.
88 for(unsigned int j = start; j < args.size(); ++j)
90 std::string const& copy = args[j];
92 if(copy == "DEPENDS")
94 doing = doing_depends;
96 else if(copy == "WORKING_DIRECTORY")
98 doing = doing_working_directory;
100 else if(copy == "VERBATIM")
102 doing = doing_verbatim;
103 verbatim = true;
105 else if (copy == "COMMENT")
107 doing = doing_comment;
109 else if(copy == "COMMAND")
111 doing = doing_command;
113 // Save the current command before starting the next command.
114 if(!currentLine.empty())
116 commandLines.push_back(currentLine);
117 currentLine.clear();
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 default:
138 this->SetError("Wrong syntax. Unknown type of argument.");
139 return false;
144 std::string::size_type pos = args[0].find_first_of("#<>");
145 if(pos != args[0].npos)
147 cmOStringStream msg;
148 msg << "called with target name containing a \"" << args[0][pos]
149 << "\". This character is not allowed.";
150 this->SetError(msg.str().c_str());
151 return false;
154 // Store the last command line finished.
155 if(!currentLine.empty())
157 commandLines.push_back(currentLine);
158 currentLine.clear();
161 // Add the utility target to the makefile.
162 bool escapeOldStyle = !verbatim;
163 this->Makefile->AddUtilityCommand(args[0].c_str(), excludeFromAll,
164 working_directory.c_str(), depends,
165 commandLines, escapeOldStyle, comment);
167 return true;