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

_vstudio.lua « vstudio « actions « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cc6dc2b11da97029d03acf5adad5b8b3f3fd01e0 (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
--
-- _vstudio.lua
-- Define the Visual Studio 200x actions.
-- Copyright (c) 2008-2009 Jason Perkins and the Premake project
--

	_VS = { }


--
-- Map Premake platform identifiers to the Visual Studio versions. Adds the Visual
-- Studio specific "any" and "mixed" to make solution generation easier.
--

	premake.vstudio_platforms = { 
		any     = "Any CPU", 
		mixed   = "Mixed Platforms", 
		Native  = "Win32",
		x32     = "Win32", 
		x64     = "x64",
		PS3     = "PS3",
		Xbox360 = "Xbox 360",
	}

	

--
-- Returns the architecture identifier for a project.
--

	function _VS.arch(prj)
		if (prj.language == "C#") then
			if (_ACTION < "vs2005") then
				return ".NET"
			else
				return "Any CPU"
			end
		else
			return "Win32"
		end
	end
	
	

--
-- Return the version-specific text for a boolean value.
-- (this should probably go in vs200x_vcproj.lua)
--

	function _VS.bool(value)
		if (_ACTION < "vs2005") then
			return iif(value, "TRUE", "FALSE")
		else
			return iif(value, "true", "false")
		end
	end


--
-- Process the solution's list of configurations and platforms, creates a list
-- of build configuration/platform pairs in a Visual Studio compatible format.
--
-- @param sln
--    The solution containing the configuration and platform lists.
-- @param with_pseudo
--    If true, Visual Studio's "Any CPU" and "Mixed Platforms" platforms will
--    be added for .NET and mixed mode solutions.
--

--
-- Process the solution's list of configurations and platforms, creates a list
-- of build configuration/platform pairs in a Visual Studio compatible format.
--
-- @param sln
--    The solution containing the configuration and platform lists.
--

	function premake.vstudio_buildconfigs(sln)
		local cfgs = { }
		
		local platforms = premake.filterplatforms(sln, premake.vstudio_platforms, "Native")

		-- .NET projects add "Any CPU", mixed mode solutions add "Mixed Platforms"
		local hascpp    = premake.hascppproject(sln)
		local hasdotnet = premake.hasdotnetproject(sln)
		if hasdotnet then
			table.insert(platforms, 1, "any")
		end
		if hasdotnet and hascpp then
			table.insert(platforms, 2, "mixed")
		end
		
		for _, buildcfg in ipairs(sln.configurations) do
			for _, platform in ipairs(platforms) do
				local entry = { }
				entry.src_buildcfg = buildcfg
				entry.src_platform = platform
				
				-- PS3 is funky and needs special handling; it's more of a build
				-- configuration than a platform from Visual Studio's point of view				
				if platform ~= "PS3" then
					entry.buildcfg = buildcfg
					entry.platform = premake.vstudio_platforms[platform]
				else
					entry.buildcfg = platform .. " " .. buildcfg
					entry.platform = "Win32"
				end
				
				-- create a name the way VS likes it
				entry.name = entry.buildcfg .. "|" .. entry.platform
				
				-- flag the "fake" platforms added for .NET
				entry.isreal = (platform ~= "any" and platform ~= "mixed")
				
				table.insert(cfgs, entry)
			end
		end
		
		return cfgs
	end
	


--
-- Return a configuration type index.
-- (this should probably go in vs200x_vcproj.lua)
--

	function _VS.cfgtype(cfg)
		if (cfg.kind == "SharedLib") then
			return 2
		elseif (cfg.kind == "StaticLib") then
			return 4
		else
			return 1
		end
	end
	
	

--
-- Clean Visual Studio files
--

	function premake.vstudio_clean(solutions, projects, targets)
		for _,name in ipairs(solutions) do
			os.remove(name .. ".suo")
			os.remove(name .. ".ncb")
			os.remove(name .. ".userprefs")  -- MonoDevelop files
			os.remove(name .. ".usertasks")
		end
		
		for _,name in ipairs(projects) do
			os.remove(name .. ".csproj.user")
			os.remove(name .. ".csproj.webinfo")
		
			local files = os.matchfiles(name .. ".vcproj.*.user", name .. ".csproj.*.user")
			for _, fname in ipairs(files) do
				os.remove(fname)
			end
		end
		
		for _,name in ipairs(targets) do
			os.remove(name .. ".pdb")
			os.remove(name .. ".idb")
			os.remove(name .. ".ilk")
			os.remove(name .. ".vshost.exe")
			os.remove(name .. ".exe.manifest")
		end		
	end
	
	

--
-- Write out entries for the files element; called from premake.walksources().
-- (this should probably go in vs200x_vcproj.lua)
--

	local function output(indent, value)
		io.write(indent .. value .. "\r\n")
	end
	
	local function attrib(indent, name, value)
		io.write(indent .. "\t" .. name .. '="' .. value .. '"\r\n')
	end
	
	function _VS.files(prj, fname, state, nestlevel)
		local indent = string.rep("\t", nestlevel + 2)
		
		if (state == "GroupStart") then
			output(indent, "<Filter")
			attrib(indent, "Name", path.getname(fname))
			attrib(indent, "Filter", "")
			output(indent, "\t>")

		elseif (state == "GroupEnd") then
			output(indent, "</Filter>")

		else
			output(indent, "<File")
			attrib(indent, "RelativePath", path.translate(fname, "\\"))
			output(indent, "\t>")
			if (not prj.flags.NoPCH and prj.pchsource == fname) then
				for _, cfgname in ipairs(prj.configurations) do
					output(indent, "\t<FileConfiguration")
					attrib(indent, "\tName", cfgname .. "|Win32")
					output(indent, "\t\t>")
					output(indent, "\t\t<Tool")
					attrib(indent, "\t\tName", "VCCLCompilerTool")
					attrib(indent, "\t\tUsePrecompiledHeader", "1")
					output(indent, "\t\t/>")
					output(indent, "\t</FileConfiguration>")
				end
			end
			output(indent, "</File>")
		end
	end
	
	
	
--
-- Return the optimization code.
-- (this should probably go in vs200x_vcproj.lua)
--

	function _VS.optimization(cfg)
		local result = 0
		for _, value in ipairs(cfg.flags) do
			if (value == "Optimize") then
				result = 3
			elseif (value == "OptimizeSize") then
				result = 1
			elseif (value == "OptimizeSpeed") then
				result = 2
			end
		end
		return result
	end



--
-- Assemble the project file name.
--

	function _VS.projectfile(prj)
		local extension
		if (prj.language == "C#") then
			extension = ".csproj"
		else
			extension = ".vcproj"
		end

		local fname = path.join(prj.location, prj.name)
		return fname..extension
	end
	
	

-- 
-- Returns the runtime code for a configuration.
-- (this should probably go in vs200x_vcproj.lua)
--

	function _VS.runtime(cfg)
		local debugbuild = (_VS.optimization(cfg) == 0)
		if (cfg.flags.StaticRuntime) then
			return iif(debugbuild, 1, 0)
		else
			return iif(debugbuild, 3, 2)
		end
	end



--
-- Return the debugging symbols level for a configuration.
-- (this should probably go in vs200x_vcproj.lua)
--

	function _VS.symbols(cfg)
		if (not cfg.flags.Symbols) then
			return 0
		else
			-- Edit-and-continue does't work if optimizing or managed C++
			if (cfg.flags.NoEditAndContinue or _VS.optimization(cfg) ~= 0 or cfg.flags.Managed) then
				return 3
			else
				return 4
			end
		end
	end

	
	
--
-- Returns the Visual Studio tool ID for a given project type.
--

	function _VS.tool(prj)
		if (prj.language == "C#") then
			return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC"
		else
			return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"
		end
	end
	
	
	

--
-- Register the Visual Studio command line actions
--

	newaction {
		trigger         = "vs2002",
		shortname       = "Visual Studio 2002",
		description     = "Microsoft Visual Studio 2002",
		os              = "windows",
		
		valid_kinds     = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
		
		valid_languages = { "C", "C++", "C#" },
		
		valid_tools     = {
			cc     = { "msc"   },
			dotnet = { "msnet" },
		},

		solutiontemplates = {
			{ ".sln",         premake.vs2002_solution },
		},

		projecttemplates = {
			{ ".vcproj",      premake.vs200x_vcproj, function(this) return this.language ~= "C#" end },
			{ ".csproj",      premake.vs2002_csproj, function(this) return this.language == "C#" end },
			{ ".csproj.user", premake.vs2002_csproj_user, function(this) return this.language == "C#" end },
		},
		
		onclean = premake.vstudio_clean,
	}

	newaction {
		trigger         = "vs2003",
		shortname       = "Visual Studio 2003",
		description     = "Microsoft Visual Studio 2003",
		os              = "windows",

		valid_kinds     = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
		
		valid_languages = { "C", "C++", "C#" },
		
		valid_tools     = {
			cc     = { "msc"   },
			dotnet = { "msnet" },
		},

		solutiontemplates = {
			{ ".sln",         premake.vs2003_solution },
		},

		projecttemplates = {
			{ ".vcproj",      premake.vs200x_vcproj, function(this) return this.language ~= "C#" end },
			{ ".csproj",      premake.vs2002_csproj, function(this) return this.language == "C#" end },
			{ ".csproj.user", premake.vs2002_csproj_user, function(this) return this.language == "C#" end },
		},
		
		onclean = premake.vstudio_clean,
	}

	newaction {
		trigger         = "vs2005",
		shortname       = "Visual Studio 2005",
		description     = "Microsoft Visual Studio 2005 (SharpDevelop, MonoDevelop)",
		os              = "windows",

		valid_kinds     = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
		
		valid_languages = { "C", "C++", "C#" },
		
		valid_tools     = {
			cc     = { "msc"   },
			dotnet = { "msnet" },
		},

		solutiontemplates = {
			{ ".sln",         premake.vs2005_solution },
		},

		projecttemplates = {
			{ ".vcproj",      premake.vs200x_vcproj, function(this) return this.language ~= "C#" end },
			{ ".csproj",      premake.vs2005_csproj, function(this) return this.language == "C#" end },
			{ ".csproj.user", premake.vs2005_csproj_user, function(this) return this.language == "C#" end },
		},
		
		onclean = premake.vstudio_clean,
	}

	newaction {
		trigger         = "vs2008",
		shortname       = "Visual Studio 2008",
		description     = "Microsoft Visual Studio 2008",
		os              = "windows",

		valid_kinds     = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib" },
		
		valid_languages = { "C", "C++", "C#" },
		
		valid_tools     = {
			cc     = { "msc"   },
			dotnet = { "msnet" },
		},

		solutiontemplates = {
			{ ".sln",         premake.vs2005_solution },
		},

		projecttemplates = {
			{ ".vcproj",      premake.vs200x_vcproj, function(this) return this.language ~= "C#" end },
			{ ".csproj",      premake.vs2005_csproj, function(this) return this.language == "C#" end },
			{ ".csproj.user", premake.vs2005_csproj_user, function(this) return this.language == "C#" end },
		},
		
		onclean = premake.vstudio_clean,
	}