MCPcopy Create free account
hub / github.com/Kitware/CMake / cmParseArgumentsCommand

Function cmParseArgumentsCommand

Source/cmParseArgumentsCommand.cxx:136–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136bool cmParseArgumentsCommand(std::vector<std::string> const& args,
137 cmExecutionStatus& status)
138{
139 // cmake_parse_arguments(prefix options single multi <ARGN>)
140 // 1 2 3 4
141 // or
142 // cmake_parse_arguments(PARSE_ARGV N prefix options single multi)
143 if (args.size() < 4) {
144 status.SetError("must be called with at least 4 arguments.");
145 return false;
146 }
147
148 auto argIter = args.begin();
149 auto argEnd = args.end();
150 bool parseFromArgV = false;
151 unsigned long argvStart = 0;
152 if (*argIter == "PARSE_ARGV") {
153 if (args.size() != 6) {
154 status.GetMakefile().IssueMessage(
155 MessageType::FATAL_ERROR,
156 "PARSE_ARGV must be called with exactly 6 arguments.");
157 cmSystemTools::SetFatalErrorOccurred();
158 return true;
159 }
160 parseFromArgV = true;
161 argIter++; // move past PARSE_ARGV
162 if (!cmStrToULong(*argIter, &argvStart)) {
163 status.GetMakefile().IssueMessage(
164 MessageType::FATAL_ERROR,
165 cmStrCat("PARSE_ARGV index '", *argIter,
166 "' is not an unsigned integer"));
167 cmSystemTools::SetFatalErrorOccurred();
168 return true;
169 }
170 argIter++; // move past N
171 }
172 // the first argument is the prefix
173 std::string const prefix = (*argIter++) + "_";
174
175 UserArgumentParser parser;
176
177 // define the result maps holding key/value pairs for
178 // options, single values and multi values
179 options_map options;
180 single_map singleValArgs;
181 multi_map multiValArgs;
182
183 // anything else is put into a vector of unparsed strings
184 std::vector<std::string> unparsed;
185
186 auto const duplicateKey = [&status](std::string const& key) {
187 status.GetMakefile().IssueMessage(
188 MessageType::WARNING, cmStrCat("keyword defined more than once: ", key));
189 };
190
191 // the second argument is a (cmake) list of options without argument
192 cmList list{ *argIter++ };
193 parser.Bind(list, options, duplicateKey);

Callers

nothing calls this directly

Calls 15

cmStrToULongFunction · 0.85
PassParsedArgumentsFunction · 0.85
assignMethod · 0.80
appendMethod · 0.80
emplace_backMethod · 0.80
cmStrCatFunction · 0.70
sizeMethod · 0.45
SetErrorMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IssueMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…