| 479 | } |
| 480 | |
| 481 | bool 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 | |
| 534 | bool HandleRelativePathCommand(std::vector<std::string> const& args, |
| 535 | cmExecutionStatus& status) |
no test coverage detected
searching dependent graphs…