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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmFileSet.h"
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "cmGeneratorExpression.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmMessageType.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
cmFileSet::cmFileSet(std::string name, std::string type)
: Name(std::move(name))
, Type(std::move(type))
{
}
void cmFileSet::ClearDirectoryEntries()
{
this->DirectoryEntries.clear();
}
void cmFileSet::AddDirectoryEntry(BT<std::string> directories)
{
this->DirectoryEntries.push_back(std::move(directories));
}
void cmFileSet::ClearFileEntries()
{
this->FileEntries.clear();
}
void cmFileSet::AddFileEntry(BT<std::string> files)
{
this->FileEntries.push_back(std::move(files));
}
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
cmFileSet::CompileFileEntries() const
{
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result;
for (auto const& entry : this->FileEntries) {
for (auto const& ex : cmExpandedList(entry.Value)) {
cmGeneratorExpression ge(entry.Backtrace);
auto cge = ge.Parse(ex);
result.push_back(std::move(cge));
}
}
return result;
}
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>
cmFileSet::CompileDirectoryEntries() const
{
std::vector<std::unique_ptr<cmCompiledGeneratorExpression>> result;
for (auto const& entry : this->DirectoryEntries) {
for (auto const& ex : cmExpandedList(entry.Value)) {
cmGeneratorExpression ge(entry.Backtrace);
auto cge = ge.Parse(ex);
result.push_back(std::move(cge));
}
}
return result;
}
std::vector<std::string> cmFileSet::EvaluateDirectoryEntries(
const std::vector<std::unique_ptr<cmCompiledGeneratorExpression>>& cges,
cmLocalGenerator* lg, const std::string& config,
const cmGeneratorTarget* target,
cmGeneratorExpressionDAGChecker* dagChecker) const
{
std::vector<std::string> result;
for (auto const& cge : cges) {
auto entry = cge->Evaluate(lg, config, target, dagChecker);
auto dirs = cmExpandedList(entry);
for (std::string dir : dirs) {
if (!cmSystemTools::FileIsFullPath(dir)) {
dir = cmStrCat(lg->GetCurrentSourceDirectory(), '/', dir);
}
auto collapsedDir = cmSystemTools::CollapseFullPath(dir);
for (auto const& priorDir : result) {
auto collapsedPriorDir = cmSystemTools::CollapseFullPath(priorDir);
if (!cmSystemTools::SameFile(collapsedDir, collapsedPriorDir) &&
(cmSystemTools::IsSubDirectory(collapsedDir, collapsedPriorDir) ||
cmSystemTools::IsSubDirectory(collapsedPriorDir, collapsedDir))) {
lg->GetCMakeInstance()->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(
"Base directories in file set cannot be subdirectories of each "
"other:\n ",
priorDir, "\n ", dir),
cge->GetBacktrace());
return {};
}
}
result.push_back(dir);
}
}
return result;
}
void cmFileSet::EvaluateFileEntry(
const std::vector<std::string>& dirs,
std::map<std::string, std::vector<std::string>>& filesPerDir,
const std::unique_ptr<cmCompiledGeneratorExpression>& cge,
cmLocalGenerator* lg, const std::string& config,
const cmGeneratorTarget* target,
cmGeneratorExpressionDAGChecker* dagChecker) const
{
auto files = cge->Evaluate(lg, config, target, dagChecker);
for (std::string file : cmExpandedList(files)) {
if (!cmSystemTools::FileIsFullPath(file)) {
file = cmStrCat(lg->GetCurrentSourceDirectory(), '/', file);
}
auto collapsedFile = cmSystemTools::CollapseFullPath(file);
bool found = false;
std::string relDir;
for (auto const& dir : dirs) {
auto collapsedDir = cmSystemTools::CollapseFullPath(dir);
if (cmSystemTools::IsSubDirectory(collapsedFile, collapsedDir)) {
found = true;
relDir = cmSystemTools::GetParentDirectory(
cmSystemTools::RelativePath(collapsedDir, collapsedFile));
break;
}
}
if (!found) {
std::ostringstream e;
e << "File:\n " << file
<< "\nmust be in one of the file set's base directories:";
for (auto const& dir : dirs) {
e << "\n " << dir;
}
lg->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR, e.str(),
cge->GetBacktrace());
return;
}
filesPerDir[relDir].push_back(file);
}
}
|