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
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#ifndef TOOLS_CREATE_PROJECT_H
#define TOOLS_CREATE_PROJECT_H
#include <map>
#include <list>
#include <string>
#include <cassert>
// The PP_NARG macro returns the number of arguments that have been passed to it.
#define PP_NARG(...) \
PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define PP_NARG_(...) \
PP_ARG_N(__VA_ARGS__)
#define PP_ARG_N( \
_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,N,...) N
#define PP_RSEQ_N() \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9,8,7,6,5,4,3,2,1,0
#define SET_VALUES(list, ...) \
{ \
std::string values[PP_NARG(__VA_ARGS__)] = { __VA_ARGS__ }; \
list.assign(values, values + (sizeof(values) / sizeof(values[0]))); \
}
typedef std::list<std::string> StringList;
/**
* Structure to describe a game engine to be built into ScummVM.
*
* We do get the game engines available by parsing the "configure"
* script of our source distribution. See "parseConfigure" for more
* information on that.
* @see parseConfigure
*/
struct EngineDesc {
/**
* The name of the engine. We use this to determine the directory
* the engine is in and to create the define, which needs to be
* set to enable the engine.
*/
std::string name;
/**
* A human readable description of the engine. We will use this
* to display a description of the engine to the user in the list
* of which engines are built and which are disabled.
*/
std::string desc;
/**
* Whether the engine should be included in the build or not.
*/
bool enable;
/**
* A list of all available sub engine names. Sub engines are engines
* which are built on top of an existing engines and can be only
* enabled when the parten engine is enabled.
*/
StringList subEngines;
bool operator==(const std::string &n) const {
return (name == n);
}
};
typedef std::list<EngineDesc> EngineDescList;
/**
* This function parses the ScummVM configure file and creates a list
* of available engines.
*
* It will also automatically setup the default build state (enabled
* or disabled) to the state specified in the "configure" file.
*
* @param srcDir Path to the root of the ScummVM source.
* @return List of available engines.
*/
EngineDescList parseConfigure(const std::string &srcDir);
/**
* Checks whether the specified engine is a sub engine. To determine this
* there is a fully setup engine list needed.
*
* @param name Name of the engine to check.
* @param engines List of engines.
* @return "true", when the engine is a sub engine, "false" otherwise.
*/
bool isSubEngine(const std::string &name, const EngineDescList &engines);
/**
* Enables or disables the specified engine in the engines list.
*
* This function also disables all sub engines of an engine, when it is
* to be disabled.
* Also this function does enable the parent of a sub engine, when a
* sub engine is to be enabled.
*
* @param name Name of the engine to be enabled or disabled.
* @param engines The list of engines, which should be operated on.
* @param enable Whether the engine should be enabled or disabled.
* @return "true", when it succeeded, "false" otherwise.
*/
bool setEngineBuildState(const std::string &name, EngineDescList &engines, bool enable);
/**
* Returns a list of all defines, according to the engine list passed.
*
* @param features The list of engines, which should be operated on. (this may contain engines, which are *not* enabled!)
*/
StringList getEngineDefines(const EngineDescList &engines);
/**
* Structure to define a given feature, usually an external library,
* used to build ScummVM.
*/
struct Feature {
const char *name; ///< Name of the feature
const char *define; ///< Define of the feature
const char *libraries; ///< Libraries, which need to be linked, for the feature
bool enable; ///< Whether the feature is enabled or not
const char *description; ///< Human readable description of the feature
bool operator==(const std::string &n) const {
return (name == n);
}
};
typedef std::list<Feature> FeatureList;
/**
* Creates a list of all features available for MSVC.
*
* @return A list including all features available.
*/
FeatureList getAllFeatures();
/**
* Returns a list of all defines, according to the feature set
* passed.
*
* @param features List of features for the build (this may contain features, which are *not* enabled!)
*/
StringList getFeatureDefines(const FeatureList &features);
/**
* Returns a list of all external library files, according to the
* feature set passed.
*
* @param features List of features for the build (this may contain features, which are *not* enabled!)
*/
StringList getFeatureLibraries(const FeatureList &features);
/**
* Sets the state of a given feature. This can be used to
* either include or exclude an feature.
*
* @param name Name of the feature.
* @param features List of features to operate on.
* @param enable Whether the feature should be enabled or disabled.
* @return "true", when it succeeded, "false" otherwise.
*/
bool setFeatureBuildState(const std::string &name, FeatureList &features, bool enable);
/**
* Structure to describe a MSVC build setup.
*
* This includes various information about which engines to
* enable, which features should be built into ScummVM.
* It also contains the path to the ScummVM souce root.
*/
struct BuildSetup {
std::string srcDir; ///< Path to the ScummVM sources.
std::string filePrefix; ///< Prefix for the relative path arguments in the project files.
std::string outputDir; ///< Path where to put the MSVC project files.
EngineDescList engines; ///< Engine list for the build (this may contain engines, which are *not* enabled!).
FeatureList features; ///< Feature list for the build (this may contain features, which are *not* enabled!).
StringList defines; ///< List of all defines for the build.
StringList libraries; ///< List of all external libraries required for the build.
};
/**
* Quits the program with the specified error message.
*
* @param message The error message to print to stderr.
*/
#if defined(__GNUC__)
#define NORETURN_POST __attribute__((__noreturn__))
#elif defined(_MSC_VER)
#define NORETURN_PRE __declspec(noreturn)
#endif
#ifndef NORETURN_PRE
#define NORETURN_PRE
#endif
#ifndef NORETURN_POST
#define NORETURN_POST
#endif
void NORETURN_PRE error(const std::string &message) NORETURN_POST;
namespace CreateProjectTool {
/**
* Gets a proper sequence of \t characters for the given
* indentation level.
*
* For example with an indentation level of 2 this will
* produce:
* \t\t
*
* @param indentation The indentation level
* @return Sequence of \t characters.
*/
std::string getIndent(const int indentation);
/**
* Converts the given path to only use backslashes.
* This means that for example the path:
* foo/bar\test.txt
* will be converted to:
* foo\bar\test.txt
*
* @param path Path string.
* @return Converted path.
*/
std::string convertPathToWin(const std::string &path);
/**
* Splits a file name into name and extension.
* The file name must be only the filename, no
* additional path name.
*
* @param fileName Filename to split
* @param name Reference to a string, where to store the name.
* @param ext Reference to a string, where to store the extension.
*/
void splitFilename(const std::string &fileName, std::string &name, std::string &ext);
/**
* Checks whether the given file will produce an object file or not.
*
* @param fileName Name of the file.
* @return "true" when it will produce a file, "false" otherwise.
*/
bool producesObjectFile(const std::string &fileName);
/**
* Structure representing a file tree. This contains two
* members: name and children. "name" holds the name of
* the node. "children" does contain all the node's children.
* When the list "children" is empty, the node is a file entry,
* otherwise it's a directory.
*/
struct FileNode {
typedef std::list<FileNode *> NodeList;
explicit FileNode(const std::string &n) : name(n), children() {}
~FileNode() {
for (NodeList::iterator i = children.begin(); i != children.end(); ++i)
delete *i;
}
std::string name; ///< Name of the node
NodeList children; ///< List of children for the node
};
class ProjectProvider {
public:
typedef std::map<std::string, std::string> UUIDMap;
/**
* Instantiate new ProjectProvider class
*
* @param global_warnings List of warnings that apply to all projects
* @param project_warnings List of project-specific warnings
* @param version Target project version.
*/
ProjectProvider(StringList &global_warnings, std::map<std::string, StringList> &project_warnings, const int version = 0);
virtual ~ProjectProvider() {}
/**
* Creates all build files
*
* @param setup Description of the desired build setup.
*/
void createProject(const BuildSetup &setup);
protected:
const int _version; ///< Target project version
StringList &_globalWarnings; ///< Global warnings
std::map<std::string, StringList> &_projectWarnings; ///< Per-project warnings
UUIDMap _uuidMap; ///< List of (project name, UUID) pairs
/**
* Create workspace/solution file
*
* @param setup Description of the desired build setup.
*/
virtual void createWorkspace(const BuildSetup &setup) = 0;
/**
* Create other files (such as build properties)
*
* @param setup Description of the desired build setup.
*/
virtual void createOtherBuildFiles(const BuildSetup &setup) = 0;
/**
* Create a project file for the specified list of files.
*
* @param name Name of the project file.
* @param uuid UUID of the project file.
* @param setup Description of the desired build.
* @param moduleDir Path to the module.
* @param includeList Files to include (must have "moduleDir" as prefix).
* @param excludeList Files to exclude (must have "moduleDir" as prefix).
*/
virtual void createProjectFile(const std::string &name, const std::string &uuid, const BuildSetup &setup, const std::string &moduleDir,
const StringList &includeList, const StringList &excludeList) = 0;
/**
* Writes file entries for the specified directory node into
* the given project file. It will also take care of duplicate
* object files.
*
* @param dir Directory node.
* @param projectFile File stream to write to.
* @param indentation Indentation level to use.
* @param duplicate List of duplicate object file names.
* @param objPrefix Prefix to use for object files, which would name clash.
* @param filePrefix Generic prefix to all files of the node.
*/
virtual void writeFileListToProject(const FileNode &dir, std::ofstream &projectFile, const int indentation,
const StringList &duplicate, const std::string &objPrefix, const std::string &filePrefix) = 0;
/**
* Output a list of project references to the file stream
*
* @param output File stream to write to.
*/
virtual void writeReferences(std::ofstream &) {};
/**
* Get the file extension for project files
*/
virtual const char *getProjectExtension() { return ""; }
/**
* Adds files of the specified directory recursively to given project file.
*
* @param dir Path to the directory.
* @param projectFile Output stream object, where all data should be written to.
* @param includeList Files to include (must have a relative directory as prefix).
* @param excludeList Files to exclude (must have a relative directory as prefix).
* @param filePrefix Prefix to use for relative path arguments.
*/
void addFilesToProject(const std::string &dir, std::ofstream &projectFile,
const StringList &includeList, const StringList &excludeList,
const std::string &filePrefix);
/**
* Creates a list of files of the specified module. This also
* creates a list of files, which should not be included.
* All filenames will have "moduleDir" as prefix.
*
* @param moduleDir Path to the module.
* @param defines List of set defines.
* @param includeList Reference to a list, where included files should be added.
* @param excludeList Reference to a list, where excluded files should be added.
*/
void createModuleList(const std::string &moduleDir, const StringList &defines, StringList &includeList, StringList &excludeList) const;
/**
* Creates an UUID for every enabled engine of the
* passed build description.
*
* @param setup Description of the desired build.
* @return A map, which includes UUIDs for all enabled engines.
*/
UUIDMap createUUIDMap(const BuildSetup &setup) const;
/**
* Creates an UUID and returns it in string representation.
*
* @return A new UUID as string.
*/
std::string createUUID() const;
};
} // End of CreateProjectTool namespace
#endif // TOOLS_CREATE_PROJECT_H
|