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

Function HandleCompareCommand

Source/cmStringCommand.cxx:356–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356bool HandleCompareCommand(std::vector<std::string> const& args,
357 cmExecutionStatus& status)
358{
359 if (args.size() < 2) {
360 status.SetError("sub-command COMPARE requires a mode to be specified.");
361 return false;
362 }
363 std::string const& mode = args[1];
364 if ((mode == "EQUAL") || (mode == "NOTEQUAL") || (mode == "LESS") ||
365 (mode == "LESS_EQUAL") || (mode == "GREATER") ||
366 (mode == "GREATER_EQUAL")) {
367 if (args.size() < 5) {
368 std::string e =
369 cmStrCat("sub-command COMPARE, mode ", mode,
370 " needs at least 5 arguments total to command.");
371 status.SetError(e);
372 return false;
373 }
374
375 std::string const& left = args[2];
376 std::string const& right = args[3];
377 std::string const& outvar = args[4];
378 bool result;
379 cm::CMakeString::CompOperator op = cm::CMakeString::CompOperator::EQUAL;
380 if (mode == "LESS") {
381 op = cm::CMakeString::CompOperator::LESS;
382 } else if (mode == "LESS_EQUAL") {
383 op = cm::CMakeString::CompOperator::LESS_EQUAL;
384 } else if (mode == "GREATER") {
385 op = cm::CMakeString::CompOperator::GREATER;
386 } else if (mode == "GREATER_EQUAL") {
387 op = cm::CMakeString::CompOperator::GREATER_EQUAL;
388 }
389 result = cm::CMakeString{ left }.Compare(op, right);
390 if (mode == "NOTEQUAL") {
391 result = !result;
392 }
393
394 status.GetMakefile().AddDefinition(outvar, result ? "1" : "0");
395 return true;
396 }
397 std::string e = "sub-command COMPARE does not recognize mode " + mode;
398 status.SetError(e);
399 return false;
400}
401
402bool HandleReplaceCommand(std::vector<std::string> const& args,
403 cmExecutionStatus& status)

Callers

nothing calls this directly

Calls 6

cmStrCatFunction · 0.70
sizeMethod · 0.45
SetErrorMethod · 0.45
CompareMethod · 0.45
AddDefinitionMethod · 0.45
GetMakefileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…