1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddCustomTargetCommand.cxx,v $
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
&)
25 this->SetError("called with incorrect number of arguments");
29 // Check the target name.
30 if(args
[0].find_first_of("/\\") != args
[0].npos
)
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))
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());
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.
69 doing_working_directory
,
73 tdoing doing
= doing_command
;
75 // Look for the ALL option.
76 bool excludeFromAll
= true;
77 unsigned int start
= 1;
82 excludeFromAll
= false;
87 // Parse the rest of the arguments.
88 for(unsigned int j
= start
; j
< args
.size(); ++j
)
90 std::string
const& copy
= args
[j
];
94 doing
= doing_depends
;
96 else if(copy
== "WORKING_DIRECTORY")
98 doing
= doing_working_directory
;
100 else if(copy
== "VERBATIM")
102 doing
= doing_verbatim
;
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
);
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 this->SetError("Wrong syntax. Unknown type of argument.");
144 std::string::size_type pos
= args
[0].find_first_of("#<>");
145 if(pos
!= args
[0].npos
)
148 msg
<< "called with target name containing a \"" << args
[0][pos
]
149 << "\". This character is not allowed.";
150 this->SetError(msg
.str().c_str());
154 // Store the last command line finished.
155 if(!currentLine
.empty())
157 commandLines
.push_back(currentLine
);
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
);