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

Function HandleTransformPathCommand

Source/cmCMakePathCommand.cxx:481–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481bool HandleTransformPathCommand(
482 std::vector<std::string> const& args, cmExecutionStatus& status,
483 std::function<cmCMakePath(cmCMakePath const&,
484 std::string const& base)> const& transform,
485 bool normalizeOption = false)
486{
487 struct Arguments : public ArgumentParser::ParseResult
488 {
489 cm::optional<ArgumentParser::NonEmpty<std::string>> Output;
490 cm::optional<std::string> BaseDirectory;
491 bool Normalize = false;
492 };
493
494 auto parser = ArgumentParserWithOutputVariable<Arguments>{}.Bind(
495 "BASE_DIRECTORY"_s, &Arguments::BaseDirectory);
496 if (normalizeOption) {
497 parser.Bind("NORMALIZE"_s, &Arguments::Normalize);
498 }
499
500 Arguments arguments = parser.Parse(args);
501
502 if (arguments.MaybeReportError(status.GetMakefile())) {
503 return true;
504 }
505
506 if (!parser.GetInputs().empty()) {
507 status.SetError(cmStrCat(args[0], " called with unexpected arguments."));
508 return false;
509 }
510
511 std::string baseDirectory;
512 if (arguments.BaseDirectory) {
513 baseDirectory = *arguments.BaseDirectory;
514 } else {
515 baseDirectory = status.GetMakefile().GetCurrentSourceDirectory();
516 }
517
518 std::string inputPath;
519 if (!getInputPath(args[1], status, inputPath)) {
520 return false;
521 }
522
523 auto path = transform(cmCMakePath(inputPath), baseDirectory);
524 if (arguments.Normalize) {
525 path = path.Normal();
526 }
527
528 status.GetMakefile().AddDefinition(
529 arguments.Output ? *arguments.Output : args[1], path.String());
530
531 return true;
532}
533
534bool HandleRelativePathCommand(std::vector<std::string> const& args,
535 cmExecutionStatus& status)

Callers 2

Calls 13

getInputPathFunction · 0.85
transformFunction · 0.85
cmCMakePathClass · 0.85
MaybeReportErrorMethod · 0.80
NormalMethod · 0.80
cmStrCatFunction · 0.70
BindMethod · 0.45
ParseMethod · 0.45
GetMakefileMethod · 0.45
emptyMethod · 0.45
SetErrorMethod · 0.45
AddDefinitionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…