cmReturnCommand.cxx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmReturnCommand.h"
  4. #include <cm/string_view>
  5. #include <cmext/string_view>
  6. #include "cmExecutionStatus.h"
  7. #include "cmMakefile.h"
  8. #include "cmMessageType.h"
  9. #include "cmPolicies.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmSystemTools.h"
  12. // cmReturnCommand
  13. bool cmReturnCommand(std::vector<std::string> const& args,
  14. cmExecutionStatus& status)
  15. {
  16. if (!args.empty()) {
  17. switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0140)) {
  18. case cmPolicies::WARN:
  19. status.GetMakefile().IssueMessage(
  20. MessageType::AUTHOR_WARNING,
  21. cmStrCat(
  22. cmPolicies::GetPolicyWarning(cmPolicies::CMP0140), '\n',
  23. "return() checks its arguments when the policy is set to NEW. "
  24. "Since the policy is not set the OLD behavior will be used so "
  25. "the arguments will be ignored."));
  26. CM_FALLTHROUGH;
  27. case cmPolicies::OLD:
  28. return true;
  29. case cmPolicies::REQUIRED_IF_USED:
  30. case cmPolicies::REQUIRED_ALWAYS:
  31. status.GetMakefile().IssueMessage(
  32. MessageType::FATAL_ERROR,
  33. cmStrCat('\n', cmPolicies::GetPolicyWarning(cmPolicies::CMP0140)));
  34. cmSystemTools::SetFatalErrorOccurred();
  35. return false;
  36. default:
  37. break;
  38. }
  39. if (args[0] != "PROPAGATE"_s) {
  40. status.SetError(
  41. cmStrCat("called with unsupported argument \"", args[0], '"'));
  42. cmSystemTools::SetFatalErrorOccurred();
  43. return false;
  44. }
  45. status.SetReturnInvoked({ args.begin() + 1, args.end() });
  46. } else {
  47. status.SetReturnInvoked();
  48. }
  49. return true;
  50. }