resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmReturnCommand.cxx
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
5 #include <cm/string_view>
6 #include <cmext/string_view>
7
8 #include "cmExecutionStatus.h"
9 #include "cmMakefile.h"
10 #include "cmMessageType.h"
11 #include "cmPolicies.h"
12 #include "cmStringAlgorithms.h"
13 #include "cmSystemTools.h"
14
15 // cmReturnCommand
16 bool cmReturnCommand(std::vector<std::string> const& args,
17                      cmExecutionStatus& status)
18 {
19   if (!args.empty()) {
20     switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0140)) {
21       case cmPolicies::WARN:
22         status.GetMakefile().IssueMessage(
23           MessageType::AUTHOR_WARNING,
24           cmStrCat(
25             cmPolicies::GetPolicyWarning(cmPolicies::CMP0140), '\n',
26             "return() checks its arguments when the policy is set to NEW. "
27             "Since the policy is not set the OLD behavior will be used so "
28             "the arguments will be ignored."));
29         CM_FALLTHROUGH;
30       case cmPolicies::OLD:
31         return true;
32       case cmPolicies::REQUIRED_IF_USED:
33       case cmPolicies::REQUIRED_ALWAYS:
34         status.GetMakefile().IssueMessage(
35           MessageType::FATAL_ERROR,
36           cmStrCat('\n', cmPolicies::GetPolicyWarning(cmPolicies::CMP0140)));
37         cmSystemTools::SetFatalErrorOccurred();
38         return false;
39       default:
40         break;
41     }
42     if (args[0] != "PROPAGATE"_s) {
43       status.SetError(
44         cmStrCat("called with unsupported argument \"", args[0], '"'));
45       cmSystemTools::SetFatalErrorOccurred();
46       return false;
47     }
48     status.SetReturnInvoked({ args.begin() + 1, args.end() });
49   } else {
50     status.SetReturnInvoked();
51   }
52   return true;
53 }