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

vs200x_project.c « vs200x « actions « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2fda5addf2f832697a792f96505a27feb11a8bc9 (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
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
/**
 * \file   vs200x_project.c
 * \brief  Visual Studio multiple-version project generation functions.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <stdlib.h>
#include <string.h>
#include "premake.h"
#include "vs200x.h"
#include "vs200x_project.h"
#include "vs200x_config.h"
#include "actions/support/sourcetree.h"
#include "base/cstr.h"
#include "base/path.h"


/**
 * Write the opening [Configuration] element and attributes.
 */
int vs200x_project_config_element(Session sess, Project prj, Stream strm)
{
	int z = OKAY;
	const char* cfg_name = project_get_configuration_filter(prj);
	z |= stream_write(strm, "\t\t<Configuration");
	z |= vs200x_attribute(strm, 3, "Name", "%s|Win32", cfg_name);
	z |= vs200x_attribute(strm, 3, "OutputDirectory", "$(SolutionDir)$(ConfigurationName)");
	z |= vs200x_attribute(strm, 3, "IntermediateDirectory", "$(ConfigurationName)");
	z |= vs200x_attribute(strm, 3, "ConfigurationType", "1");
	z |= vs200x_config_character_set(sess, strm);
	z |= vs200x_element_end(sess, strm, 2, ">");
	return z;
}


/**
 * Write the closing [Configuration] element.
 */
int vs200x_project_config_end(Session sess, Project prj, Stream strm)
{
	UNUSED(sess);
	UNUSED(prj);
	return stream_writeline(strm, "\t\t</Configuration>");
}


/**
 * Create a new output stream for a project, and make it active for subsequent writes.
 */
int vs200x_project_create(Session sess, Project prj, Stream strm)
{
	/* create the project file */
	const char* extension = vs200x_project_file_extension(prj);
	const char* filename  = project_get_filename(prj, NULL, extension);
	strm = stream_create_file(filename);
	if (!strm)
	{
		return !OKAY;
	}

	/* make the stream active for the functions that come after */
	session_set_active_stream(sess, strm);
	return OKAY;
}


/**
 * Write the root [VisualStudioProject] element and attributes.
 */
int vs200x_project_element(Session sess, Project prj, Stream strm)
{
	int version, z;
	const char* prj_ver;
	const char* prj_name = project_get_name(prj);
	const char* prj_guid = project_get_guid(prj);

	version = vs200x_get_target_version(sess);
	switch (version)
	{
	default:
		prj_ver = "7.00";  break;
	case 2003:
		prj_ver = "7.10";  break;
	case 2005:
		prj_ver = "8.00";  break;
	case 2008:
		prj_ver = "9.00";  break;
	}

	z  = stream_write(strm, "<VisualStudioProject");
	z |= vs200x_attribute(strm, 1, "ProjectType", "Visual C++");
	z |= vs200x_attribute(strm, 1, "Version", prj_ver);
	z |= vs200x_attribute(strm, 1, "Name", prj_name);
	z |= vs200x_attribute(strm, 1, "ProjectGUID", "{%s}", prj_guid);
	if (version > 2003)
	{
		z |= vs200x_attribute(strm, 1, "RootNamespace", cstr_to_identifier(prj_name));
	}
	z |= vs200x_attribute(strm, 1, "Keyword", "Win32Proj");
	if (version > 2005)
	{
		z |= vs200x_attribute(strm, 1, "TargetFrameworkVersion", "196613");
	}
	z |= vs200x_element_end(sess, strm, 0, ">");
	return z;
}


/**
 * Write the file encoding at the start of the project file.
 */
int vs200x_project_encoding(Session sess, Project prj, Stream strm)
{
	int z;
	UNUSED(sess);
	UNUSED(prj);

	stream_set_newline(strm, "\r\n");
	z = stream_writeline(strm, "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>");
	return z;
}


/**
 * Write an individual file entry to the project file; callback for sourcetree_walk().
 * \param   sess      The current execution session context.
 * \param   prj       The current project; contains the file being enumerated.
 * \param   strm      The active output stream; for writing the file markup.
 * \param   filename  The name of the file to process.
 * \param   state     One of the ActionSourceStates, enabling file grouping.
 * \returns OKAY if successful.
 */
int vs200x_project_file(Session sess, Project prj, Stream strm, const char* filename, int state)
{
	const char* name;
	const char* ptr;
	int depth, z = OKAY;

	/* figure out the grouping depth, skipping over any leading dot directories */
	depth = 2;

	ptr = filename;
	while (cstr_starts_with(ptr, "../"))
	{
		ptr += 3;
	}

	ptr = strchr(ptr, '/');
	while (ptr != NULL)
	{
		depth++;
		ptr = strchr(ptr + 1, '/');
	}

	/* group name is just the last bit of the path */
	name = path_filename(filename);

	/* use the Windows path separator */
	filename = path_translate(filename, "\\");

	switch (state)
	{
	case GroupStart:
		if (strlen(filename) > 0 && !cstr_eq(name, ".."))
		{
			z |= stream_write_n(strm, "\t", depth);
			z |= stream_write(strm, "<Filter");
			z |= vs200x_attribute(strm, depth + 1, "Name", name);
			z |= vs200x_attribute(strm, depth + 1, "Filter", "");
			z |= vs200x_element_end(sess, strm, depth, ">");
		}
		break;

	case GroupEnd:
		if (strlen(filename) > 0 && !cstr_eq(name, ".."))
		{
			z |= stream_write_n(strm, "\t", depth);
			z |= stream_writeline(strm, "</Filter>");
		}
		break;

	case SourceFile:
		z |= stream_write_n(strm, "\t", depth);
		z |= stream_write(strm, "<File");
		ptr = (filename[0] == '.') ? "" : ".\\";
		z |= vs200x_attribute(strm, depth + 1, "RelativePath", "%s%s", ptr, filename);
		z |= vs200x_element_end(sess, strm, depth, ">");
		z |= stream_write_n(strm, "\t", depth);
		z |= stream_writeline(strm, "</File>");
		break;
	}

	UNUSED(prj);
	return z;
}


/**
 * Write out the [Files] element.
 */
int vs200x_project_files(Session sess, Project prj, Stream strm)
{
	int z = OKAY;
	z |= stream_writeline(strm, "\t<Files>");
	z |= sourcetree_walk(sess, prj, strm, vs200x_project_file);
	z |= stream_writeline(strm, "\t</Files>");
	return z;
}


/**
 * Write out the [Globals] element.
 */
int vs200x_project_globals(Session sess, Project prj, Stream strm)
{
	int z = OKAY;
	UNUSED(sess);
	UNUSED(prj);
	z |= stream_writeline(strm, "\t<Globals>");
	z |= stream_writeline(strm, "\t</Globals>");
	z |= stream_writeline(strm, "</VisualStudioProject>");
	return z;
}


/**
 * Write out the platforms section of a project file.
 */
int vs200x_project_platforms(Session sess, Project prj, Stream strm)
{
	int z = OKAY;
	UNUSED(prj);
	z |= stream_writeline(strm, "\t<Platforms>");
	z |= stream_write(strm, "\t\t<Platform");
	z |= vs200x_attribute(strm, 3, "Name", "Win32");
	z |= vs200x_element_end(sess, strm, 2, "/>");
	z |= stream_writeline(strm, "\t</Platforms>");
	return OKAY;
}


/**
 * Write out the [References] element and attributes.
 */
int vs200x_project_references(Session sess, Project prj, Stream strm)
{
	int z;
	UNUSED(prj);
	z  = stream_writeline(strm, "\t</Configurations>");
	if (vs200x_get_target_version(sess) > 2002)
	{
		z |= stream_writeline(strm, "\t<References>");
		z |= stream_writeline(strm, "\t</References>");
	}
	return z;
}


/**
 * Write out the [ToolFiles] section of a Visual Studio project.
 */
int vs200x_project_tool_files(Session sess, Project prj, Stream strm)
{
	int version, z = OKAY;
	UNUSED(prj);

	version = vs200x_get_target_version(sess);
	if (version > 2003)
	{
		z |= stream_writeline(strm, "\t<ToolFiles>");
		z |= stream_writeline(strm, "\t</ToolFiles>");
	}
	z |= stream_writeline(strm, "\t<Configurations>");
	return z;
}


/**
 * Common function to write an empty [Tool] element.
 */
static int vs200x_project_vc_empty_tool(Session sess, Project prj, Stream strm, const char* name)
{
	int z;
	UNUSED(prj);
	z  = stream_write(strm, "\t\t\t<Tool");
	z |= vs200x_attribute(strm, 4, "Name", name);
	z |= vs200x_element_end(sess, strm, 3, "/>");
	return z;
}


/**
 * Write the VCALinkTool [Tool] element and attributes.
 */
int vs200x_project_vc_alink_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCALinkTool");
}


/**
 * Write the VCAppVerifierTool [Tool] element and attributes.
 */
int vs200x_project_vc_app_verifier_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCAppVerifierTool");
}


/**
 * Write the VCBscMakeTool [Tool] element and attributes.
 */
int vs200x_project_vc_bsc_make_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCBscMakeTool");
}


/**
 * Write the VCCLCompilerTool [Tool] element and attributes.
 */
int vs200x_project_vc_cl_compiler_tool(Session sess, Project prj, Stream strm)
{
	int z = OKAY;
	z |= stream_write(strm, "\t\t\t<Tool");
	z |= vs200x_attribute(strm, 4, "Name", "VCCLCompilerTool");
	z |= vs200x_attribute(strm, 4, "Optimization", "0");
	z |= vs200x_config_defines(sess, strm, prj);
	z |= vs200x_attribute(strm, 4, "MinimalRebuild", vs200x_true(sess));
	z |= vs200x_attribute(strm, 4, "BasicRuntimeChecks", "3");
	z |= vs200x_attribute(strm, 4, "RuntimeLibrary", "3");
	z |= vs200x_config_runtime_type_info(sess, strm, prj);
	z |= vs200x_config_use_precompiled_header(sess, strm, prj);
	z |= vs200x_attribute(strm, 4, "WarningLevel", "3");
	z |= vs200x_config_detect_64bit_portability(sess, strm, prj);
	z |= vs200x_attribute(strm, 4, "DebugInformationFormat", "4");
	z |= vs200x_element_end(sess, strm, 3, "/>");
	return z;
}


/**
 * Write the VCCustomBuildTool [Tool] element and attributes.
 */
int vs200x_project_vc_custom_build_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCCustomBuildTool");
}


/**
 * Write the VCFxCopTool [Tool] element and attributes.
 */
int vs200x_project_vc_fx_cop_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCFxCopTool");
}


/**
 * Write the VCLinkerTool [Tool] element and attributes.
 */
int vs200x_project_vc_linker_tool(Session sess, Project prj, Stream strm)
{
	int z;
	UNUSED(prj);
	z  = stream_write(strm, "\t\t\t<Tool");
	z |= vs200x_attribute(strm, 4, "Name", "VCLinkerTool");
	z |= vs200x_attribute(strm, 4, "LinkIncremental", "2");
	z |= vs200x_attribute(strm, 4, "GenerateDebugInformation", vs200x_true(sess));
	z |= vs200x_attribute(strm, 4, "SubSystem", "1");
	z |= vs200x_attribute(strm, 4, "EntryPointSymbol", "mainCRTStartup");
	z |= vs200x_attribute(strm, 4, "TargetMachine", "1");
	z |= vs200x_element_end(sess, strm, 3, "/>");
	return z;
}


/**
 * Write the VCManagedResourceCompilerTool [Tool] element and attributes.
 */
int vs200x_project_vc_managed_resource_compiler_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCManagedResourceCompilerTool");
}


/**
 * Write the VCManifestTool [Tool] element and attributes.
 */
int vs200x_project_vc_manifest_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCManifestTool");
}


/**
 * Write the VCMIDLTool [Tool] element and attributes.
 */
int vs200x_project_vc_midl_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCMIDLTool");
}


/**
 * Write the VCPreBuildEventTool [Tool] element and attributes.
 */
int vs200x_project_vc_pre_build_event_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCPreBuildEventTool");
}


/**
 * Write the VCPreLinkEventTool [Tool] element and attributes.
 */
int vs200x_project_vc_pre_link_event_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCPreLinkEventTool");
}


/**
 * Write the VCPostBuildEventTool [Tool] element and attributes.
 */
int vs200x_project_vc_post_build_event_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCPostBuildEventTool");
}


/**
 * Write the VCResourceCompiler [Tool] element and attributes.
 */
int vs200x_project_vc_resource_compiler_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCResourceCompilerTool");
}


/**
 * Write the VCWebDeploymentTool [Tool] element and attributes.
 */
int vs200x_project_vc_web_deployment_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCWebDeploymentTool");
}


/**
 * Write the VCWebServiceProxyGeneratorTool [Tool] element and attributes.
 */
int vs200x_project_vc_web_service_proxy_generator_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCWebServiceProxyGeneratorTool");
}


/**
 * Write the VCXDCMakeTool [Tool] element and attributes.
 */
int vs200x_project_vc_xdc_make_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCXDCMakeTool");
}


/**
 * Write the VCXMLDataGeneratorTool [Tool] element and attributes.
 */
int vs200x_project_vc_xml_data_generator_tool(Session sess, Project prj, Stream strm)
{
	return vs200x_project_vc_empty_tool(sess, prj, strm, "VCXMLDataGeneratorTool");
}