1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomTargetCommand.cxx,v $
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
,
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;
58 std::vector
<std::string
> sources
;
60 // Keep track of parser state.
64 doing_working_directory
,
69 tdoing doing
= doing_command
;
71 // Look for the ALL option.
72 bool excludeFromAll
= true;
73 unsigned int start
= 1;
78 excludeFromAll
= false;
83 // Parse the rest of the arguments.
84 for(unsigned int j
= start
; j
< args
.size(); ++j
)
86 std::string
const& copy
= args
[j
];
90 doing
= doing_depends
;
92 else if(copy
== "WORKING_DIRECTORY")
94 doing
= doing_working_directory
;
96 else if(copy
== "VERBATIM")
98 doing
= doing_verbatim
;
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
);
116 else if(copy
== "SOURCES")
118 doing
= doing_source
;
124 case doing_working_directory
:
125 working_directory
= copy
;
128 currentLine
.push_back(copy
);
131 depends
.push_back(copy
);
134 comment_buffer
= copy
;
135 comment
= comment_buffer
.c_str();
138 sources
.push_back(copy
);
141 this->SetError("Wrong syntax. Unknown type of argument.");
147 std::string::size_type pos
= args
[0].find_first_of("#<>");
148 if(pos
!= args
[0].npos
)
151 msg
<< "called with target name containing a \"" << args
[0][pos
]
152 << "\". This character is not allowed.";
153 this->SetError(msg
.str().c_str());
157 // Store the last command line finished.
158 if(!currentLine
.empty())
160 commandLines
.push_back(currentLine
);
164 // Enforce name uniqueness.
167 if(!this->Makefile
->EnforceUniqueName(args
[0], msg
, true))
169 this->SetError(msg
.c_str());
174 // Add the utility target to the makefile.
175 bool escapeOldStyle
= !verbatim
;
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
);