-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathprojectGenerator.h
More file actions
542 lines (460 loc) · 21.9 KB
/
projectGenerator.h
File metadata and controls
542 lines (460 loc) · 21.9 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/*
* 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 _PROJECTGENERATOR_H_
#define _PROJECTGENERATOR_H_
#include "configGenerator.h"
#include <fstream>
#include <set>
class ProjectGenerator
{
private:
using StaticList = vector<string>;
using UnknownList = map<string, StaticList>;
struct ConfigConds
{
bool isStatic = false;
bool isShared = false;
bool is32 = false;
bool is64 = false;
ConfigConds(bool istatic, bool ishared, bool i32, bool i64)
: isStatic(istatic)
, isShared(ishared)
, is32(i32)
, is64(i64)
{}
};
using ConditionalList = map<string, ConfigConds>;
ifstream m_inputFile;
string m_inLine;
StaticList m_includes;
StaticList m_includesCPP;
StaticList m_includesC;
StaticList m_includesASM;
ConditionalList m_includesConditionalCPP;
ConditionalList m_includesConditionalC;
ConditionalList m_includesConditionalASM;
ConditionalList m_includesConditionalCU;
ConditionalList m_includesConditionalCL;
ConditionalList m_includesConditionalCOMP;
StaticList m_includesH;
StaticList m_includesRC;
StaticList m_includesCU;
StaticList m_includesCL;
StaticList m_includesCOMP;
UnknownList m_replaceIncludes;
StaticList m_libs;
UnknownList m_unknowns;
string m_projectName;
string m_projectDir;
StaticList m_subDirs;
map<string, StaticList> m_projectLibs;
bool m_addCustomTesseract{false};
const string m_tempDirectory = "FFVSTemp/";
public:
ConfigGenerator m_configHelper;
/**
* Checks all found Makefiles based on current configuration and generates project files and a solution files as
* needed.
* @return True if it succeeds, false if it fails.
*/
bool passAllMake();
/** Deletes any files that may have been created by previous runs. */
void deleteCreatedFiles();
/**
* Error function to cleanly exit.
* @param cleanupFiles (Optional) True to delete created files.
*/
void errorFunc(bool cleanupFiles = true);
private:
/**
* Outputs a project file for the current project directory.
* @return True if it succeeds, false if it fails.
*/
bool outputProject();
/**
* Output a project file for a program (ffplay etc.).
* @param destinationFile Destination project file.
* @param destinationFilterFile Destination project filter file.
* @return True if it succeeds, false if it fails.
*/
bool outputProgramProject(const string& destinationFile, const string& destinationFilterFile);
/** Cleans up any used variables after a project file has been created. */
void outputProjectCleanup();
/**
* Outputs a solution file (Also calls outputProgramProject for any programs).
* @return True if it succeeds, false if it fails.
*/
bool outputSolution();
bool passStaticIncludeObject(uint& startPos, uint& endPos, StaticList& staticIncludes);
bool passStaticIncludeLine(uint startPos, StaticList& staticIncludes);
bool passStaticInclude(uint length, StaticList& staticIncludes);
bool passDynamicIncludeObject(uint& startPos, uint& endPos, string& ident, StaticList& includes);
bool passDynamicIncludeLine(uint startPos, string& ident, StaticList& includes);
bool passDynamicInclude(uint length, StaticList& includes);
/**
* Pass a static source include line from current makefile that is wrapped in a reserved conditional.
* @param condition The pre-processor condition applied to the current line.
* @param list The file list to add any found files to when the condition evaluates to 'true'.
* @param replace The file list to add any found files to when the condition is a reserved value.
* @param offset The offset to start passing (used to separate different file tags).
* @return True if it succeeds, false if it fails.
*/
bool passCondition(const string& condition, StaticList& list, UnknownList& replace, uint offset = 0);
/**
* Pass a dynamic source include line from current makefile that is wrapped in a reserved conditional.
* @param condition The pre-processor condition applied to the current line.
* @param list The file list to add any found files to when the condition evaluates to 'true'.
* @param replace The file list to add any found files to when the condition is a reserved value.
* @param offset The offset to start passing (used to separate different file tags).
* @return True if it succeeds, false if it fails.
*/
bool passDCondition(const string& condition, StaticList& list, UnknownList& replace, uint offset = 0);
/**
* Pass a static source include line from current makefile.
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passCInclude(const string& condition = "");
/**
* Pass a dynamic source include line from current makefile.
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passDCInclude(const string& condition = "");
/**
* Pass a static asm include line from current makefile.
* @param offset The offset to start passing (used to separate old yasm and x86asm).
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passASMInclude(uint offset, const string& condition = "");
/**
* Pass a dynamic asm include line from current makefile.
* @param offset The offset to start passing (used to separate old yasm and x86asm).
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passDASMInclude(uint offset, const string& condition = "");
/**
* Pass a static mmx include line from current makefile.
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passMMXInclude(const string& condition = "");
/**
* Pass a dynamic mmx include line from current makefile.
* @param condition (Optional) The pre-processor condition applied to the current line.
* @return True if it succeeds, false if it fails.
*/
bool passDMMXInclude(const string& condition = "");
/**
* Pass a static header include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passHInclude(uint cutPos = 7);
/**
* Pass a dynamic header include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passDHInclude();
/**
* Pass a static lib include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passLibInclude();
/**
* Pass a dynamic lib include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passDLibInclude();
/**
* Pass a static unknown type include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passDUnknown();
/**
* Pass a dynamic unknown type include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passDLibUnknown();
/**
* Pass a shared only dynamic source include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passSharedDCInclude();
/**
* Pass a shared only source include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passSharedCInclude();
/**
* Pass a static only dynamic source include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passStaticDCInclude();
/**
* Pass a static only source include line from current makefile.
* @return True if it succeeds, false if it fails.
*/
bool passStaticCInclude();
/**
* Passes the makefile for the current project directory.
* @return True if it succeeds, false if it fails.
*/
bool passMake();
/**
* Pass the makefile for a specified program.
* @return True if it succeeds, false if it fails.
*/
bool passProgramMake();
/**
* Searches for the first source file.
* @param file The file name.
* @param extension The file extension.
* @param [out] retFileName Filename of the found file.
* @return True if it succeeds, false if it fails.
*/
bool findSourceFile(const string& file, const string& extension, string& retFileName) const;
/**
* Searches for matching source files.
* @param file The file name.
* @param extension The file extension.
* @param [in,out] retFiles The returned list of matching files.
* @return True if it succeeds, false if it fails.
*/
bool findSourceFiles(const string& file, const string& extension, vector<string>& retFiles) const;
void buildInterDependenciesHelper(
const StaticList& configOptions, const StaticList& addDeps, StaticList& libs) const;
void buildInterDependencies(StaticList& libs);
/**
* Gets library dependency lists.
* @param [in,out] libs The project dependency libs.
* @param [in,out] addLibs The windows dependency libs.
* @param winrt True if checking for winrt.
*/
void buildDependencies(StaticList& libs, StaticList& addLibs, bool winrt);
void buildDependencyValues(StaticList& includeDirs, StaticList& lib32Dirs, StaticList& lib64Dirs,
StaticList& definesShared, StaticList& definesStatic, bool winrt) const;
void buildProjectDependencies(map<string, bool>& projectDeps) const;
void buildProjectGUIDs(map<string, string>& keys) const;
struct DCEParams
{
string define;
string file;
bool operator==(const string& compare) const
{
return (file == compare);
}
};
/**
* Builds project specific DCE functions and variables that are not automatically detected.
* @param [out] definitionsDCE The return list of built DCE functions.
* @param [out] variablesDCE The return list of built DCE variables.
*/
void buildProjectDCEs(map<string, DCEParams>& definitionsDCE, map<string, DCEParams>& variablesDCE) const;
bool checkProjectFiles();
/**
* Builds '_wrap' files to wrap source files in a conditional compilation statement.
* @param replaceIncludes The list of files to scan.
* @param [in,out] existingIncludes The list of existing processed files.
* @param [in,out] conditionalIncludes The list of existing conditional files.
*/
bool createReplaceFiles(
const StaticList& replaceIncludes, StaticList& existingIncludes, ConditionalList& conditionalIncludes);
bool findProjectFiles(const StaticList& includes, StaticList& includesC, StaticList& includesCPP,
StaticList& includesASM, StaticList& includesH, StaticList& includesRC, StaticList& includesCU,
StaticList& includesCL, StaticList& includesCOMP) const;
/**
* Replace occurrences of known tags in string.
* @param [in,out] projectTemplate The project file in string form.
* @param winrt Whether this is a winrt project file.
*/
void outputTemplateTags(string& projectTemplate, bool winrt = false) const;
/**
* Replace occurrences of features in a props file.
* @param [in,out] projectTemplate The project file in string form.
*/
void outputPropsTags(string& projectTemplate) const;
void outputSourceFileType(StaticList& fileList, const string& type, const string& filterType,
string& projectTemplate, string& filterTemplate, StaticList& foundObjects, set<string>& foundFilters,
bool checkExisting, bool staticOnly = false, bool sharedOnly = false, bool bit32Only = false,
bool bit64Only = false) const;
void outputSourceFiles(string& projectTemplate, string& filterTemplate);
/**
* Find and load the list of function exports prefixes.
* @param [out] exportPrefixes The list of loaded export prefixes.
*/
bool findExportsList(StaticList& exportPrefixes) const;
/**
* Generate a module definition file.
* @param includeDirs The list of current directories to look for included files.
*/
bool outputProjectExports(const StaticList& includeDirs) const;
/**
* Executes a batch script to perform operations using a compiler based on current configuration.
* @param includeDirs The list of current directories to look for included files.
* @param [in,out] directoryObjects A list of subdirectories with each one containing a vector of files contained
* within it.
* @param runType The type of operation to run on input files (0=generate an sbr file, 1=pre-
* process to .i file).
* @returns True if it succeeds, false if it fails.
*/
bool runCompiler(
const vector<string>& includeDirs, map<string, vector<string>>& directoryObjects, int runType) const;
/**
* Executes a batch script to perform operations using the msvc compiler.
* @param includeDirs The list of current directories to look for included files.
* @param [in,out] directoryObjects A list of subdirectories with each one containing a vector of files contained
* within it.
* @param runType The type of operation to run on input files (0=generate an sbr file, 1=pre-
* process to .i file).
* @returns True if it succeeds, false if it fails.
*/
bool runMSVC(const vector<string>& includeDirs, map<string, vector<string>>& directoryObjects, int runType) const;
/**
* Executes a bash script to perform operations using the gcc compiler.
* @param includeDirs The list of current directories to look for included files.
* @param [in,out] directoryObjects A list of subdirectories with each one containing a vector of files contained
* within it.
* @param runType The type of operation to run on input files (1=pre-process to .i file).
* @returns True if it succeeds, false if it fails.
*/
bool runGCC(const vector<string>& includeDirs, map<string, vector<string>>& directoryObjects, int runType) const;
/**
* Output additional build events to the project.
* @param [in,out] projectTemplate The project template.
*/
void outputBuildEvents(string& projectTemplate) const;
/**
* Output additional include search directories to project.
* @param includeDirs The include dirs.
* @param [in,out] projectTemplate The project template.
*/
static void outputIncludeDirs(const StaticList& includeDirs, string& projectTemplate);
/**
* Output additional library search directories to project.
* @param lib32Dirs The library 32b dirs.
* @param lib64Dirs The library 64b dirs.
* @param [in,out] projectTemplate The project template.
*/
static void outputLibDirs(const StaticList& lib32Dirs, const StaticList& lib64Dirs, string& projectTemplate);
/**
* Output additional defines to the project.
* @param definesShared The defines for shared libraries.
* @param definesStatic The defines for static libraires.
* @param [in,out] projectTemplate The project template.
* @param program (Optional) True if building program project.
*/
void outputDefines(const StaticList& definesShared, const StaticList& definesStatic, string& projectTemplate,
bool program = false);
/**
* Comment out preprocessor directives inside macro arguments that MSVC cannot handle.
*/
void sanitizeSourceFiles();
/**
* Output asm tools to project template.
* @remark Either yasm or nasm tools will be used based on current configuration.
* @param [in,out] projectTemplate The project template.
*/
void outputASMTools(string& projectTemplate) const;
/**
* Output cuda tools to project template.
* @param [in,out] projectTemplate The project template.
*/
void outputCUDATools(string& projectTemplate) const;
/**
* Output OpenCL source2c build customization to project template.
* @remark Copies source2c.exe and opencl_source2c .props/.targets/.xml to the output directory
* and adds the ExtensionSettings/ExtensionTargets import groups.
* @param [in,out] projectTemplate The project template.
*/
void outputOpenCLTools(string& projectTemplate) const;
/**
* Output SPIRV source2c build customization to project template.
* @remark Copies source2c.exe and spirv_source2c .props/.targets/.xml to the output directory
* and adds the ExtensionSettings/ExtensionTargets import groups.
* @param [in,out] projectTemplate The project template.
*/
void outputSPIRVTools(string& projectTemplate) const;
/**
* Output resource source files (HTML/CSS) with custom build steps.
* @param [in,out] fileList The list of resource files to process.
* @param [in,out] projectTemplate The project template.
* @param [in,out] filterTemplate The filter template.
* @param [in,out] foundObjects The list of found object files.
* @param [in,out] foundFilters The set of found filters.
* @param staticOnly True to only include in static builds.
* @param sharedOnly True to only include in shared builds.
* @param bit32Only True to only include in 32-bit builds.
* @param bit64Only True to only include in 64-bit builds.
*/
void outputResourceSourceFiles(StaticList& fileList, string& projectTemplate, string& filterTemplate,
StaticList& foundObjects, set<string>& foundFilters, bool staticOnly = false, bool sharedOnly = false,
bool bit32Only = false, bool bit64Only = false) const;
bool outputDependencyLibs(string& projectTemplate, bool winrt, bool program);
/**
* Search through files in the current project and finds any undefined elements that are used in DCE blocks. A new
* file is then created and added to the project that contains hull definitions for any missing functions.
* @param includeDirs The list of current directories to look for included files.
* @return True if it succeeds, false if it fails.
*/
bool outputProjectDCE(const StaticList& includeDirs);
/**
* Passes an input file and looks for any function usage within a block of code eliminated by DCE.
* @param file The loaded file to search for DCE usage in.
* @param fileName Filename of the file currently being searched.
* @param [in,out] foundDCEUsage The return list of found DCE functions.
* @param [out] requiresPreProcess The file requires pre processing.
* @param [in,out] nonDCEUsage The return list of found functions not in DCE.
*/
void outputProjectDCEFindFunctions(const string& file, const string& fileName,
map<string, DCEParams>& foundDCEUsage, bool& requiresPreProcess, set<string>& nonDCEUsage) const;
/**
* Resolves a pre-processor define conditional string by replacing with current configuration settings.
* @param [in,out] define The pre-processor define string.
*/
void outputProgramDCEsResolveDefine(string& define);
/**
* Find any declaration of a specified function. Can also find a definition of the function if no declaration as
* found first.
* @param file The loaded file to search for function in.
* @param function The name of the function to search for.
* @param fileName Filename of the file being searched through.
* @param [out] retDeclaration Returns the complete declaration for the found function.
* @param [out] isFunction Returns if the found declaration was actually for a function or an incorrectly
* identified table/array declaration.
* @return True if it succeeds finding the function, false if it fails.
*/
static bool outputProjectDCEsFindDeclarations(
const string& file, const string& function, const string& fileName, string& retDeclaration, bool& isFunction);
/**
* Cleans a pre-processor define conditional string to remove any invalid values.
* @param [in,out] define The pre-processor define string to clean.
*/
static void outputProjectDCECleanDefine(string& define);
/**
* Combines 2 pre-processor define conditional strings.
* @param define The first define.
* @param define2 The second define.
* @param [out] retDefine The returned combined define.
*/
static void outputProgramDCEsCombineDefine(const string& define, const string& define2, string& retDefine);
};
#endif