| 536 | } |
| 537 | |
| 538 | bool cmMakefile::ExecuteCommand(cmListFileFunction const& lff, |
| 539 | cmExecutionStatus& status, |
| 540 | cm::optional<std::string> deferId) |
| 541 | { |
| 542 | bool result = true; |
| 543 | |
| 544 | // quick return if blocked |
| 545 | if (this->IsFunctionBlocked(lff, status)) { |
| 546 | // No error. |
| 547 | return result; |
| 548 | } |
| 549 | |
| 550 | // Place this call on the call stack. |
| 551 | CallScope stack_manager(this, lff, std::move(deferId), status); |
| 552 | static_cast<void>(stack_manager); |
| 553 | |
| 554 | // Check for maximum recursion depth. |
| 555 | size_t depthLimit = this->GetRecursionDepthLimit(); |
| 556 | if (this->RecursionDepth > depthLimit) { |
| 557 | this->IssueMessage( |
| 558 | MessageType::FATAL_ERROR, |
| 559 | cmStrCat("Maximum recursion depth of ", depthLimit, " exceeded")); |
| 560 | cmSystemTools::SetFatalErrorOccurred(); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | // Lookup the command prototype. |
| 565 | if (cmState::Command command = |
| 566 | this->GetState()->GetCommandByExactName(lff.LowerCaseName())) { |
| 567 | // Decide whether to invoke the command. |
| 568 | if (!cmSystemTools::GetFatalErrorOccurred()) { |
| 569 | // if trace is enabled, print out invoke information |
| 570 | if (this->GetCMakeInstance()->GetTrace()) { |
| 571 | this->PrintCommandTrace(lff, this->Backtrace); |
| 572 | } |
| 573 | // Try invoking the command. |
| 574 | bool invokeSucceeded = command(lff.Arguments(), status); |
| 575 | bool hadNestedError = status.GetNestedError(); |
| 576 | if (!invokeSucceeded || hadNestedError) { |
| 577 | if (!hadNestedError) { |
| 578 | // The command invocation requested that we report an error. |
| 579 | std::string const error = |
| 580 | cmStrCat(lff.OriginalName(), ' ', status.GetError()); |
| 581 | this->IssueMessage(MessageType::FATAL_ERROR, error); |
| 582 | } |
| 583 | result = false; |
| 584 | if (this->GetCMakeInstance()->GetCommandFailureAction() == |
| 585 | cmake::CommandFailureAction::FATAL_ERROR) { |
| 586 | cmSystemTools::SetFatalErrorOccurred(); |
| 587 | } |
| 588 | } |
| 589 | if (this->GetCMakeInstance()->HasScriptModeExitCode() && |
| 590 | this->GetCMakeInstance()->RoleSupportsExitCode()) { |
| 591 | // pass-through the exit code from inner cmake_language(EXIT) , |
| 592 | // possibly from include() or similar command... |
| 593 | status.SetExitCode(this->GetCMakeInstance()->GetScriptModeExitCode()); |
| 594 | } |
| 595 | } |