blob: da15b1af3e8fd3a629138a1d8141d0d022e02491 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCMakeCommand.h"
#include <algorithm>
#include <cstddef>
#include <iosfwd>
#include <memory>
#include <string>
#include "cmExecutionStatus.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmRange.h"
#include "cmStringAlgorithms.h"
inline std::ostream& operator<<(std::ostream& os,
cmListFileArgument const& arg)
{
os << arg.Value;
return os;
}
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
if (args.empty()) {
status.SetError("called with incorrect number of arguments");
return false;
}
cmMakefile& makefile = status.GetMakefile();
cmListFileContext context = makefile.GetExecutionContext();
bool result = false;
if (args[0].Value == "INVOKE") {
if (args.size() == 1) {
status.SetError("called with incorrect number of arguments");
return false;
}
// First argument is the name of the function to call
cmListFileFunction func;
func.Name = args[1].Value;
func.Line = context.Line;
// The rest of the arguments are passed to the function call above
func.Arguments.resize(args.size() - 1);
for (size_t i = 2; i < args.size(); ++i) {
cmListFileArgument lfarg;
lfarg.Delim = args[i].Delim;
lfarg.Line = context.Line;
lfarg.Value = args[i].Value;
func.Arguments.emplace_back(lfarg);
}
result = makefile.ExecuteCommand(func, status);
} else if (args[0].Value == "EVAL") {
if (args.size() < 2) {
status.SetError("called with incorrect number of arguments");
return false;
}
auto code_iter = std::find_if(
args.begin(), args.end(),
[](cmListFileArgument const& arg) { return arg.Value == "CODE"; });
if (code_iter == args.end()) {
status.SetError("called without CODE argument");
return false;
}
const std::string code = cmJoin(cmMakeRange(++code_iter, args.end()), " ");
result = makefile.ReadListFileAsString(
code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
} else {
status.SetError("called with unknown meta-operation");
}
return result;
}
|