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

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

#include <assert.h>
#include <stdlib.h>
#include "premake.h"
#include "vs200x.h"
#include "base/cstr.h"
#include "base/error.h"


/**
 * Write an XML attribute, adjusting for the differing Visual Studio formats.
 * \param   strm         The output stream, the attribute will be written here.
 * \param   indent_size  How far to indent (with tabs) the attribute.
 * \param   name    The attribute name.
 * \param   value   The attribute value; may contain printf-style formatting codes.
 * \returns OKAY if successful.
 */
int vs200x_attribute(Stream strm, int indent_size, const char* name, const char* value, ...)
{
	va_list args;
	int z = OKAY;

	va_start(args, value);
	z |= stream_writeline(strm, "");
	z |= stream_write_n(strm, "\t", indent_size);
	z |= stream_write(strm, "%s=\"", name);
	z |= stream_vprintf(strm, value, args);
	z |= stream_write(strm, "\"");
	va_end(args);
	return z;
}


/**
 * Write the ending part of an XML tag, adjust for the differing Visual Studio formats.
 * \param   sess    The current execution session.
 * \param   strm    The output stream.
 * \param   level   The XML element nesting level.
 * \param   markup  The end tag markup.
 * \returns OKAY if successful.
 */
int vs200x_element_end(Session sess, Stream strm, int level, const char* markup)
{
	int z;
	int version = vs200x_get_target_version(sess);
	if (version >= 2005)
	{
		z = stream_writeline(strm, "");
		if (markup[0] == '>')
		{
			level++;
		}
		z |= stream_write_n(strm, "\t", level);
		z |= stream_writeline(strm, "%s", markup);
	}
	else
	{
		z = stream_writeline(strm, markup);
	}
	return z;
}


/**
 * Return the Visual Studio version appropriate version of the string for a false
 * value. Before 2005 this was "FALSE", after it is "false".
 */
const char* vs200x_false(Session sess)
{
	int version = vs200x_get_target_version(sess);
	return (version < 2005) ? "FALSE" : "false";
}


/**
 * Converts the session action string to a Visual Studio version number.
 * \param   sess   The current execution session.
 * \returns The Visual Studio version number corresponding to the current action.
 */
int vs200x_get_target_version(Session sess)
{
	const char* action = session_get_action(sess);
	if (cstr_eq(action, "vs2002"))
	{
		return 2002;
	}
	else if (cstr_eq(action, "vs2003"))
	{
		return 2003;
	}
	else if (cstr_eq(action, "vs2005"))
	{
		return 2005;
	}
	else if (cstr_eq(action, "vs2008"))
	{
		return 2008;
	}
	else
	{
		assert(0);
		return 0;
	}
}


/**
 * Return the appropriate file extension for a particular project.
 * \param   prj    The project object.
 * \returns The appropriate project file extension, based on the project settings.
 */
const char* vs200x_project_file_extension(Project prj)
{
	const char* language = project_get_language(prj);
	if (cstr_eq(language, "c") || cstr_eq(language, "c++"))
	{
		return ".vcproj";
	}
	else
	{
		error_set("unsupported language '%s'", language); 
		return NULL;
	}
}


/**
 * Returns the Visual Studio GUID for a particular project type.
 * \param   language   The programming language used in the project.
 * \returns The GUID corresponding the programming language.
 */
const char* vs200x_tool_guid(const char* language)
{
	if (cstr_eq(language, "c") || cstr_eq(language, "c++"))
	{
		return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942";
	}
	else if (cstr_eq(language, "c#"))
	{
		return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
	}
	else
	{
		error_set("unsupported language '%s'", language); 
		return NULL;
	}
}


/**
 * Return the Visual Studio version appropriate version of the string for a true
 * value. Before 2005 this was "TRUE", after it is "true".
 */
const char* vs200x_true(Session sess)
{
	int version = vs200x_get_target_version(sess);
	return (version < 2005) ? "TRUE" : "true";
}