1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomTargetCommand.cxx,v $
6 Date: $Date: 2008-03-07 22:05:06 $
7 Version: $Revision: 1.37 $
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
,
26 this->SetError("called with incorrect number of arguments");
30 // Check the target name.
31 if(args
[0].find_first_of("/\\") != args
[0].npos
)
33 if(!this->Makefile
->NeedBackwardsCompatibility(2,2))
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());
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;
59 // Keep track of parser state.
63 doing_working_directory
,
67 tdoing doing
= doing_command
;
69 // Look for the ALL option.
70 bool excludeFromAll
= true;
71 unsigned int start
= 1;
76 excludeFromAll
= false;
81 // Parse the rest of the arguments.
82 for(unsigned int j
= start
; j
< args
.size(); ++j
)
84 std::string
const& copy
= args
[j
];
88 doing
= doing_depends
;
90 else if(copy
== "WORKING_DIRECTORY")
92 doing
= doing_working_directory
;
94 else if(copy
== "VERBATIM")
96 doing
= doing_verbatim
;
99 else if (copy
== "COMMENT")
101 doing
= doing_comment
;
103 else if(copy
== "COMMAND")
105 doing
= doing_command
;
107 // Save the current command before starting the next command.
108 if(!currentLine
.empty())
110 commandLines
.push_back(currentLine
);
118 case doing_working_directory
:
119 working_directory
= copy
;
122 currentLine
.push_back(copy
);
125 depends
.push_back(copy
);
128 comment_buffer
= copy
;
129 comment
= comment_buffer
.c_str();
132 this->SetError("Wrong syntax. Unknown type of argument.");
138 std::string::size_type pos
= args
[0].find_first_of("#<>");
139 if(pos
!= args
[0].npos
)
142 msg
<< "called with target name containing a \"" << args
[0][pos
]
143 << "\". This character is not allowed.";
144 this->SetError(msg
.str().c_str());
148 // Store the last command line finished.
149 if(!currentLine
.empty())
151 commandLines
.push_back(currentLine
);
155 // Enforce name uniqueness.
158 if(!this->Makefile
->EnforceUniqueName(args
[0], msg
, true))
160 this->SetError(msg
.c_str());
165 // Add the utility target to the makefile.
166 bool escapeOldStyle
= !verbatim
;
167 this->Makefile
->AddUtilityCommand(args
[0].c_str(), excludeFromAll
,
168 working_directory
.c_str(), depends
,
169 commandLines
, escapeOldStyle
, comment
);