1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmAddCustomTargetCommand.h"
14 // cmAddCustomTargetCommand
15 bool cmAddCustomTargetCommand
16 ::InitialPass(std::vector<std::string> const& args,
21 this->SetError("called with incorrect number of arguments");
25 // Check the target name.
26 if(args[0].find_first_of("/\\") != args[0].npos)
28 if(!this->Makefile->NeedBackwardsCompatibility(2,2))
31 e << "called with invalid target name \"" << args[0]
32 << "\". Target names may not contain a slash. "
33 << "Use ADD_CUSTOM_COMMAND to generate files. "
34 << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.2 "
35 << "or lower to skip this check.";
36 this->SetError(e.str().c_str());
41 // Accumulate one command line at a time.
42 cmCustomCommandLine currentLine;
44 // Save all command lines.
45 cmCustomCommandLines commandLines;
47 // Accumulate dependencies.
48 std::vector<std::string> depends;
49 std::string working_directory;
50 bool verbatim = false;
51 std::string comment_buffer;
52 const char* comment = 0;
53 std::vector<std::string> sources;
55 // Keep track of parser state.
59 doing_working_directory,
64 tdoing doing = doing_command;
66 // Look for the ALL option.
67 bool excludeFromAll = true;
68 unsigned int start = 1;
73 excludeFromAll = false;
78 // Parse the rest of the arguments.
79 for(unsigned int j = start; j < args.size(); ++j)
81 std::string const& copy = args[j];
85 doing = doing_depends;
87 else if(copy == "WORKING_DIRECTORY")
89 doing = doing_working_directory;
91 else if(copy == "VERBATIM")
93 doing = doing_verbatim;
96 else if (copy == "COMMENT")
98 doing = doing_comment;
100 else if(copy == "COMMAND")
102 doing = doing_command;
104 // Save the current command before starting the next command.
105 if(!currentLine.empty())
107 commandLines.push_back(currentLine);
111 else if(copy == "SOURCES")
113 doing = doing_source;
119 case doing_working_directory:
120 working_directory = copy;
123 currentLine.push_back(copy);
127 std::string dep = copy;
128 cmSystemTools::ConvertToUnixSlashes(dep);
129 depends.push_back(dep);
133 comment_buffer = copy;
134 comment = comment_buffer.c_str();
137 sources.push_back(copy);
140 this->SetError("Wrong syntax. Unknown type of argument.");
146 std::string::size_type pos = args[0].find_first_of("#<>");
147 if(pos != args[0].npos)
150 msg << "called with target name containing a \"" << args[0][pos]
151 << "\". This character is not allowed.";
152 this->SetError(msg.str().c_str());
156 // Store the last command line finished.
157 if(!currentLine.empty())
159 commandLines.push_back(currentLine);
163 // Enforce name uniqueness.
166 if(!this->Makefile->EnforceUniqueName(args[0], msg, true))
168 this->SetError(msg.c_str());
173 // Convert working directory to a full path.
174 if(!working_directory.empty())
176 const char* build_dir = this->Makefile->GetCurrentOutputDirectory();
178 cmSystemTools::CollapseFullPath(working_directory.c_str(), build_dir);
181 // Add the utility target to the makefile.
182 bool escapeOldStyle = !verbatim;
184 this->Makefile->AddUtilityCommand(args[0].c_str(), excludeFromAll,
185 working_directory.c_str(), depends,
186 commandLines, escapeOldStyle, comment);
188 // Add additional user-specified source files to the target.
189 target->AddSources(sources);