Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project.c « project « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f8aae2f2f123004bb2ce6ea8f5db038d029122f (plain)
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
/**
 * \file   project.c
 * \brief  The project class.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "premake.h"
#include "project/project.h"
#include "project/solution.h"
#include "base/buffers.h"
#include "base/cstr.h"
#include "base/guid.h"
#include "base/path.h"
#include "base/strings.h"
#include "platform/platform.h"


struct FieldInfo ProjectFieldInfo[] =
{
	{ "basedir",    StringField,  NULL            },
	{ "files",      FilesField,   NULL            },
	{ "guid",       StringField,  guid_is_valid   },
	{ "language",   StringField,  NULL            },
	{ "location",   StringField,  NULL            },
	{ "name",       StringField,  NULL            },
	{  0,           0,            NULL            }
};


DEFINE_CLASS(Project)
{
	Solution solution;
	Fields fields;
	const char* config_filter;
};


/**
 * Create and initialize a new project object.
 * \returns A new project object.
 */
Project project_create()
{
	Project prj = ALLOC_CLASS(Project);
	prj->solution = NULL;
	prj->fields = fields_create(ProjectFieldInfo);
	prj->config_filter = NULL;
	return prj;
}


/**
 * Destroy a project object and release the associated memory.
 * \param   prj   The project object to destroy.
 */
void project_destroy(Project prj)
{
	assert(prj);
	fields_destroy(prj->fields);
	free(prj);
}


/**
 * Get the base directory for the project; any properties containing relative
 * paths are relative to this location.
 * \param   prj     The project object to query.
 * \returns The base directory, or NULL if no directory has been set.
 */
const char* project_get_base_dir(Project prj)
{
	return project_get_value(prj, ProjectBaseDirectory);
}


/**
 * Retrieve the current configuration filter. All subsequent requests for configuration
 * values will return settings from this configuration only.
 * \param   prj      The project object to query.
 * \returns The current configuration filter, or NULL if no filter has been set.
 */
const char* project_get_configuration_filter(Project prj)
{
	assert(prj);
	return prj->config_filter;
}


/**
 * Retrieve the fields object for this solution; used to unload values from the script.
 */
Fields project_get_fields(Project prj)
{
	assert(prj);
	return prj->fields;
}


/**
 * Get the path to the project output file, using the provided file extension.
 * \param   prj      The project object to query.
 * \param   basename The base filename; if NULL the project name will be used.
 * \param   ext      The file extension to be used on the filename; may be NULL.
 * \returns The path to the project file.
 */
const char* project_get_filename(Project prj, const char* basename, const char* ext)
{
	const char* base_dir;
	const char* location;
	const char* directory;
	const char* result;

	assert(prj);

	if (!basename)
	{
		basename = project_get_name(prj);
	}


	if (!ext)
	{
		ext = "";
	}

	base_dir = project_get_base_dir(prj);
	location = project_get_location(prj);
	directory = path_join(base_dir, location);

	result = path_assemble(directory, basename, ext);
	return result;
}


/**
 * Retrieve the list of source files associated with a project.
 */
Strings project_get_files(Project prj)
{
	assert(prj);
	return fields_get_values(prj->fields, ProjectFiles);
}


/**
 * Retrieve the GUID associated with a project.
 */
const char* project_get_guid(Project prj)
{
	assert(prj);
	return project_get_value(prj, ProjectGuid);
}


/**
 * Get the programming language used by the project.
 * \param   prj     The project object to query.
 * \returns The language used by the project, or NULL if no language has been set.
 */
const char* project_get_language(Project prj)
{
	const char* result = project_get_value(prj, ProjectLanguage);
	if (result == NULL && prj->solution != NULL)
	{
		result = solution_get_language(prj->solution);
	}
	return result;
}


/**
 * Retrieve the output location (the relative path from the base directory to the
 * target output directory) for this project.
 * \param   prj    The project object to modify.
 * \returns The project output location, or NULL if no location has been set.
 */
const char* project_get_location(Project prj)
{
	return project_get_value(prj, ProjectLocation);
}


/**
 * Get the name of the project.
 * \returns The name, if set, NULL otherwise.
 */
const char* project_get_name(Project prj)
{
	return project_get_value(prj, ProjectName);
}


/**
 * Retrieve the output filename for this project, taking into account platform-specific
 * naming conventions. For instance, for a project named "MyProject" this function would
 * return "MyProject.exe" on Windows. No path information is included, use the function
 * project_get_outdir() for that.
 */
const char* project_get_outfile(Project prj)
{
	char* buffer = buffers_next();
	strcpy(buffer, project_get_name(prj));
	if (platform_get() == Windows)
	{
		strcat(buffer, ".exe");
	}
	return buffer;
}


/**
 * Retrieve the solution associated with this project (internal).
 * \param   prj      The project to query.
 * \returns The associated solution, or NULL if no association has been made.
 */
Solution project_get_solution(Project prj)
{
	return prj->solution;
}


/**
 * Retrieve a string (single value) fields from a project, using the field indices.
 * \param   prj      The project object to query.
 * \param   field    The index of the field to query.
 * \returns The value of the field if set, of NULL.
 */
const char* project_get_value(Project prj, enum ProjectField field)
{
	assert(prj);
	return fields_get_value(prj->fields, field);
}


/**
 * Returns true if the specified language is recognized. Current valid language strings
 * are 'c', 'c++', and 'c#'.
 * \param   language   The language string.
 * \returns True if the language string is recognized.
 */
int project_is_valid_language(const char* language)
{
	return (cstr_eq(language, "c") ||
	        cstr_eq(language, "c++") ||
			cstr_eq(language, "c#"));
}


/**
 * Set the base directory of the project.
 * \param   prj      The project object to modify.
 * \param   base_dir The new base directory.
 */
void project_set_base_dir(Project prj, const char* base_dir)
{
	project_set_value(prj, ProjectBaseDirectory, base_dir);
}


/**
 * Set the current configuration filter. All subsequent requests for configuration
 * values will return settings from this configuration only.
 * \param   prj      The project object to query.
 * \param   cfg_name The name of the configuration on which to filter.
 */
void project_set_configuration_filter(Project prj, const char* cfg_name)
{
	assert(prj);
	prj->config_filter = cfg_name;
}


/**
 * Set the GUID associated with a project. The GUID is required by the Visual
 * Studio generators, and must be unique per project.
 * \param   prj        The project to modify.
 * \param   guid       The new project GUID.
 */
void project_set_guid(Project prj, const char* guid)
{
	project_set_value(prj, ProjectGuid, guid);
}


/**
 * Set the programming language used by a project.
 * \param   prj        The project to modify.
 * \param   language   The programming language used by the project.
 */
void project_set_language(Project prj, const char* language)
{
	project_set_value(prj, ProjectLanguage, language);
}


/**
 * Set the output location (the relative path from the base directory to the
 * target output directory) for this project.
 * \param   prj        The project object to modify.
 * \param   location   The new output location.
 */
void project_set_location(Project prj, const char* location)
{
	project_set_value(prj, ProjectLocation, location);
}


/**
 * Set the name of the project.
 * \param prj    The project object.
 * \param name   The new for the project.
 */
void project_set_name(Project prj, const char* name)
{
	project_set_value(prj, ProjectName, name);
}


/**
 * Associate a solution with this project (internal).
 * \param   prj      The project to modify.
 * \param   sln      The solution to associate with this project.
 */
void project_set_solution(Project prj, Solution sln)
{
	assert(prj);
	prj->solution = sln;
}


/**
 * Set a string (single value) field on a project, using the field indices.
 * \param   prj      The project object.
 * \param   field    The field to set.
 * \param   value    The new value for the field.
 */
void project_set_value(Project prj, enum ProjectField field, const char* value)
{
	assert(prj);
	fields_set_value(prj->fields, field, value);
}


/**
 * Sets the list of values associated with a field. The field will subsequently
 * "own" the list, and take responsibility to destroying it with the field set.
 * \param   prj      The project object.
 * \param   field    The index of the field to set.
 * \param   values   The list of new values for the field.
 */
void project_set_values(Project prj, enum ProjectField field, Strings values)
{
	assert(prj);
	fields_set_values(prj->fields, field, values);
}