-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathchecks.h
More file actions
218 lines (175 loc) · 5.27 KB
/
checks.h
File metadata and controls
218 lines (175 loc) · 5.27 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
* Copyright (C) 2016-2017, Egor Pugin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "emitter.h"
#include "cppan_string.h"
#include "filesystem.h"
#include "yaml.h"
class CMakeEmitter;
struct Package;
struct CheckParameters
{
Strings headers;
StringSet definitions;
StringSet include_directories;
StringSet libraries;
StringSet flags;
// TODO: pass all found includes to this test
// it is possible only in sequential mode
bool all_includes = false;
void writeHeadersBefore(CMakeEmitter &ctx) const;
void writeHeadersAfter(CMakeEmitter &ctx) const;
void writeBefore(CMakeEmitter &ctx) const;
void writeAfter(CMakeEmitter &ctx) const;
void load(const yaml &n);
void save(yaml &n) const;
bool empty() const;
String getHash() const;
bool operator<(const CheckParameters &p) const;
};
class Check
{
public:
enum
{
Function,
Include,
Type,
Alignment,
Library,
LibraryFunction,
Symbol,
StructMember,
CSourceCompiles,
CSourceRuns,
CXXSourceCompiles,
CXXSourceRuns,
Decl, // decl goes almost at the end!!! (sort order)
Custom,
Max,
};
struct Information
{
int type;
String cppan_key;
String function;
// strings for printing/naming files
String singular;
String plural;
};
public:
// maybe variant: int, double, string?
using Value = int;
public:
Check(const Information &i, const CheckParameters ¶meters = CheckParameters());
virtual ~Check() = default;
const Information &getInformation() const { return information; }
String getVariable() const { return variable; }
String getData() const { return data; }
String getDataEscaped() const;
Value getValue() const { return value; }
String getMessage() const { return message; }
virtual void writeCheck(CMakeEmitter &/*ctx*/) const {}
virtual void save(yaml &/*root*/) const {}
void setValue(const Value &v) { value = v; }
bool get_cpp() const { return cpp; }
virtual void set_cpp(bool) {}
String getFileName() const;
virtual String printStatus() const
{
if (getValue())
return "-- " + information.singular + " " + getData() + " - found (" + std::to_string(getValue()) + ")";
else
return "-- " + information.singular + " " + getData() + " - not found";
}
virtual bool isOk() const
{
return !!getValue();
}
protected:
// self-information
Information information;
// e.g. HAVE_STDINT_H
String variable;
// symbol name (function, include, c/cxx source etc.)
// or source code
// or whatever
String data;
// (cmake) value
Value value = 0;
// message for printing
String message;
bool cpp = false;
public:
// default check won't be printed
bool default_ = false;
// parameters
CheckParameters parameters;
public:
static String make_include_var(const String &i);
static String make_type_var(const String &t, const String &prefix = "HAVE_");
static String make_struct_member_var(const String &m, const String &s);
private:
template <class T>
friend struct CheckPtrLess;
};
using CheckPtr = std::shared_ptr<Check>;
template <class T>
struct CheckPtrLess
{
bool operator()(const T &p1, const T &p2) const
{
if (p1 && p2)
return
std::tie(p1->information.type, p1->variable, p1->parameters) <
std::tie(p2->information.type, p2->variable, p2->parameters);
return p1 < p2;
}
};
using ChecksSet = std::set<CheckPtr, CheckPtrLess<CheckPtr>>;
struct Checks
{
ChecksSet checks;
bool valid = true;
bool empty() const;
void load(const yaml &root);
void load(const path &fn);
void save(yaml &root) const;
String save() const;
void write_checks(CMakeEmitter &ctx, const StringSet &prefixes = StringSet()) const;
void write_definitions(CMakeEmitter &ctx, const Package &d, const StringSet &prefixes = StringSet()) const;
void write_parallel_checks_for_workers(CMakeEmitter &ctx) const;
void read_parallel_checks_for_workers(const path &dir);
void remove_known_vars(const std::set<String> &known_vars);
std::vector<Checks> scatter(int N) const;
void print_values() const;
void print_values(CMakeEmitter &ctx) const;
Checks &operator+=(const Checks &rhs);
template <class T, class ... Args>
T *addCheck(Args && ... args);
};
Check::Information getCheckInformation(int type);
struct ParallelCheckOptions
{
path cmake_binary;
path dir;
path vars_file;
path checks_file;
String generator;
String system_version;
String toolset;
String toolchain;
};