-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathconfigGenerator.h
More file actions
360 lines (303 loc) · 13.2 KB
/
configGenerator.h
File metadata and controls
360 lines (303 loc) · 13.2 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
* copyright (c) 2014 Matthew Oliver
*
* This file is part of ShiftMediaProject.
*
* ShiftMediaProject is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* ShiftMediaProject is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ShiftMediaProject; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CONFIGGENERATOR_H
#define CONFIGGENERATOR_H
#include "helperFunctions.h"
#include <map>
#include <utility>
#include <vector>
class ConfigGenerator
{
friend class ProjectGenerator;
private:
class ConfigPair
{
friend class ConfigGenerator;
friend class ProjectGenerator;
private:
string m_option;
string m_prefix;
string m_value;
bool m_lock;
ConfigPair(string option, string prefix, string value)
: m_option(std::move(option))
, m_prefix(std::move(prefix))
, m_value(std::move(value))
, m_lock(false)
{}
};
using ValuesList = vector<ConfigPair>;
using DefaultValuesList = map<string, string>;
using DependencyList = map<string, bool>;
using ConfigList = map<string, vector<string>>;
using InterDependencies = map<string, vector<pair<vector<string>, vector<string>>>>;
ValuesList m_fixedConfigValues;
ValuesList m_configValues;
uint m_configComponentsStart{0};
uint m_configValuesEnd{0};
string m_configureFile;
bool m_isLibav{false};
string m_projectName;
string m_rootDirectory;
string m_solutionDirectory;
string m_outDirectory;
bool m_onlyDCE{false};
bool m_usingExistingConfig{false};
DefaultValuesList m_replaceList;
DefaultValuesList m_replaceListASM;
bool m_useNASM{true};
string m_tesseractName{"tesseract"};
ConfigList m_cachedConfigLists;
public:
/** Default constructor. */
ConfigGenerator();
/**
* Pass configuration options based on input values.
* @param argc The number of input options.
* @param [in] argv If non-null, the the list of input options.
* @return True if it succeeds, false if it fails.
*/
bool passConfig(int argc, char** argv);
/**
* Outputs a new configurations files based on current internal settings.
* @return True if it succeeds, false if it fails.
*/
bool outputConfig();
/** Deletes any files that may have been previously created by outputConfig. */
void deleteCreatedFiles() const;
private:
/**
* Passes the configure file and loads all available options.
* @return True if it succeeds, false if it fails.
*/
bool passConfigureFile();
/**
* Passes an existing config.h file.
* @return True if it succeeds, false if it fails.
*/
bool passExistingConfig();
/**
* Change configuration options.
* @param option The option to change.
* @return True if it succeeds, false if it fails.
*/
bool changeConfig(const string& option);
/**
* Checks current config values and performs validation of requirements.
* @return True if it succeeds, false if it fails.
*/
bool passCurrentValues();
/**
* Makes a files path relative to the project directory.
* @remark Assumes input file path is relative to the generator.
* @param fileName Filename of the file.
* @param [out] retFileName Filename with the path modified.
*/
void makeFileProjectRelative(const string& fileName, string& retFileName) const;
/**
* Makes a files path relative to the generator directory.
* @remark Assumes input file path is relative to the project.
* @param fileName Filename of the file.
* @param [out] retFileName Filename with the path modified.
*/
void makeFileGeneratorRelative(const string& fileName, string& retFileName) const;
static void buildFixedValues(DefaultValuesList& fixedValues);
/**
* Builds a list of configuration options that need to be replaced with the returned values.
* @param [in,out] replaceValues The replace values for config.h.
* @param [in,out] header The header that must be output at top of config file.
* @param [in,out] replaceValuesASM The replace values for config.asm.
*/
void buildReplaceValues(DefaultValuesList& replaceValues, string& header, DefaultValuesList& replaceValuesASM);
/**
* Creates a list of config items that are automatically set and should be be set by the user.
* @param [out] reservedItems The reserved items.
*/
static void buildReservedValues(vector<string>& reservedItems);
/**
* Creates a list of additional config option dependencies that are not available as actual config options.
* @param [out] additionalDependencies The additional dependencies.
*/
void buildAdditionalDependencies(DependencyList& additionalDependencies) const;
/**
* Creates a list of additional dependencies between config options (in addition to _deps lists).
* @param [out] interDependencies The additional dependencies. Format is <libName, <pair<{required conditions},
* {dependencies}>>>
*/
void buildInterDependencies(InterDependencies& interDependencies);
/**
* Creates a list of components that can be disabled based on the current configuration as better alternatives are
* enabled.
* @param [in,out] optimisedDisables The optimised disables.
*/
static void buildOptimisedDisables(ConfigList& optimisedDisables);
/**
* Creates a list of config options that must be forced to be enabled if the specified option is enabled.
* @param optionLower The enabled option (in lower case).
* @param [in,out] forceEnable The forced enable options.
*/
void buildForcedEnables(const string& optionLower, vector<string>& forceEnable);
/**
* Creates a list of config options that must be forced to be disabled if the specified option is disabled.
* @param optionLower The disabled option (in lower case).
* @param [in,out] forceDisable The forced disable options.
*/
void buildForcedDisables(const string& optionLower, vector<string>& forceDisable);
/**
* Creates a list of command line arguments that must be handled before all others.
* @param [out] earlyArgs The early arguments.
*/
static void buildEarlyConfigArgs(vector<string>& earlyArgs);
void buildObjects(const string& tag, vector<string>& objects);
bool getConfigList(
const string& list, vector<string>& returnList, bool force = true, uint currentFilePos = string::npos);
/**
* Perform the equivalent of configures find_things function.
* @param param1 The first parameter.
* @param param2 The second parameter.
* @param param3 The third parameter.
* @param [in,out] returnList Returns any detected configure defines.
* @param [in,out] returnExterns (Optional) If non-null, returns any detected extern variables.
* @return True if it succeeds, false if it fails.
*/
bool passFindThings(const string& param1, const string& param2, const string& param3, vector<string>& returnList,
vector<string>* returnExterns = nullptr) const;
/**
* Perform the equivalent of configures find_things_extern function.
* @param param1 The first parameter.
* @param param2 The second parameter.
* @param param3 The third parameter.
* @param param4 The fourth parameter.
* @param [in,out] returnList Returns any detected configure defines.
* @return True if it succeeds, false if it fails.
*/
bool passFindThingsExtern(const string& param1, const string& param2, const string& param3, const string& param4,
vector<string>& returnList) const;
/**
* Perform the equivalent of configures find_filters_extern function.
* @param param1 The first parameter.
* @param [in,out] returnList Returns any detected configure defines.
* @return True if it succeeds, false if it fails.
*/
bool passFindFiltersExtern(const string& param1, vector<string>& returnList) const;
bool passAddSuffix(
const string& param1, const string& param2, vector<string>& returnList, uint currentFilePos = string::npos);
bool passFilterOut(const string& param1, const string& param2, vector<string>& returnList, uint currentFilePos);
/**
* Perform the equivalent of configures full_filter_name function.
* @param param1 The first parameter.
* @param [in,out] returnString The return.
* @return True if it succeeds, false if it fails.
*/
bool passFullFilterName(const string& param1, string& returnString) const;
bool passConfigList(const string& prefix, const string& suffix, const string& list);
bool passEnabledComponents(const string& file, const string& structName, const string& name, const string& list);
/**
* Sets up all default starting config values.
* @return True if it succeeds, false if it fails.
*/
bool buildDefaultValues();
bool buildAutoDetectValues();
/**
* Sets up all config values that have a forced value.
* @return True if it succeeds, false if it fails.
*/
bool buildForcedValues();
/**
* Update configuration option without performing any dependency option checks.
* @param option The option to update.
* @param enable True to enable, false to disable.
* @param weak (Optional) True to only change a value if it is not already set.
* @returns True if it succeeds, false if it fails.
*/
bool fastToggleConfigValue(const string& option, bool enable, bool weak = false);
/**
* Update configuration option and perform any dependency option updates as well.
* @param option The option to update.
* @param enable True to enable, false to disable.
* @param weak (Optional) True to only change a value if it is not already set.
* @param deep (Optional) True to also enable _select and _suggest dependencies.
* @param recursive (Optional) True if the function has been called from within itself.
* @returns True if it succeeds, false if it fails.
*/
bool toggleConfigValue(
const string& option, bool enable, bool weak = false, bool deep = false, bool recursive = false);
/**
* Gets configuration option.
* @param option The options name.
* @return The configuration option, m_configValues.end() if option not found.
*/
ValuesList::iterator getConfigOption(const string& option);
ValuesList::const_iterator getConfigOption(const string& option) const;
/**
* Gets configuration option with prefix (i.e. HAVE_, CONFIG_ etc.) included.
* @param option The options name.
* @return The configuration option, m_configValues.end() if option not found.
*/
ValuesList::iterator getConfigOptionPrefixed(const string& option);
ValuesList::const_iterator getConfigOptionPrefixed(const string& option) const;
/**
* Queries if a configuration option is enabled.
* @param option The option.
* @return True if the configuration option is enabled, false if not.
*/
bool isConfigOptionEnabled(const string& option) const;
/**
* Queries if a configuration option exists.
* @param option The option.
* @return True if the configuration option is valid, false if not.
*/
bool isConfigOptionValid(const string& option) const;
/**
* Queries if a configuration option with prefix (i.e. HAVE_, CONFIG_ etc.) exists.
* @param option The option.
* @return True if the configuration option is valid, false if not.
*/
bool isConfigOptionValidPrefixed(const string& option) const;
/**
* Queries if assembly is enabled.
* @return True if asm is enabled, false if not.
*/
bool isASMEnabled() const;
/**
* Queries if cuda is enabled.
* @returns True if cuda is enabled, false if not.
*/
bool isCUDAEnabled() const;
/**
* Queries if opencl compilation is enabled.
* @returns True if opencl is enabled, false if not.
*/
bool isOpenCLEnabled() const;
/**
* Queries if spirv compilation is enabled.
* @returns True if spirv is enabled, false if not.
*/
bool isSPIRVEnabled() const;
/**
* Gets minimum supported windows version from config file.
* @param [out] major The version number major.
* @param [out] minor The version number minor.
* @return True if it succeeds, false if it fails.
*/
bool getMinWindowsVersion(uint& major, uint& minor) const;
bool passDependencyCheck(const ValuesList::iterator& option);
};
#endif