1--
2-- vs200x_vcproj_user.lua
3-- Generate a Visual Studio 2002-2008 C/C++ project .user file
4-- Copyright (c) Jason Perkins and the Premake project
5--
6
7	local p = premake
8	local m = p.vstudio.vc200x
9
10
11
12--
13-- Generate a Visual Studio 200x C++ user file, with support for the new platforms API.
14--
15
16	m.elements.user = function(cfg)
17		return {
18			m.debugSettings,
19		}
20	end
21
22	function m.generateUser(prj)
23		p.indent("\t")
24
25		-- Only want output if there is something to configure
26		local contents = {}
27		local size = 0
28
29		for cfg in p.project.eachconfig(prj) do
30			contents[cfg] = p.capture(function()
31				p.push(4)
32				p.callArray(m.elements.user, cfg)
33				p.pop(4)
34			end)
35			size = size + #contents[cfg]
36		end
37
38		if size > 0 then
39			m.xmlElement()
40			m.visualStudioUserFile()
41			p.push('<Configurations>')
42			for cfg in p.project.eachconfig(prj) do
43				m.userConfiguration(cfg)
44				p.push('<DebugSettings')
45				if #contents[cfg] > 0 then
46					p.outln(contents[cfg])
47				end
48				p.pop('/>')
49				p.pop('</Configuration>')
50			end
51			p.pop('</Configurations>')
52			p.pop('</VisualStudioUserFile>')
53		end
54	end
55
56
57
58---
59-- Output the opening project tag.
60---
61
62	function m.visualStudioUserFile()
63		p.push('<VisualStudioUserFile')
64		p.w('ProjectType="Visual C++"')
65		m.version()
66		p.w('ShowAllFiles="false"')
67		p.w('>')
68	end
69
70
71
72--
73-- Write out the <Configuration> element, describing a specific Premake
74-- build configuration/platform pairing.
75--
76
77	function m.userConfiguration(cfg)
78		p.push('<Configuration')
79		p.x('Name="%s"', p.vstudio.projectConfig(cfg))
80		p.w('>')
81	end
82
83
84
85--
86-- Write out the debug settings for this project.
87--
88
89	m.elements.debugSettings = function(cfg)
90		return {
91			m.debugCommand,
92			m.debugDir,
93			m.debugArgs,
94			m.debugEnvironment,
95		}
96	end
97
98	function m.debugSettings(cfg)
99		p.callArray(m.elements.debugSettings, cfg)
100	end
101
102
103	function m.debugArgs(cfg)
104		if #cfg.debugargs > 0 then
105			p.x('CommandArguments="%s"', table.concat(cfg.debugargs, " "))
106		end
107	end
108
109
110	function m.debugCommand(cfg)
111		if cfg.debugcommand then
112			p.x('Command="%s"', p.vstudio.path(cfg, cfg.debugcommand))
113		end
114	end
115
116
117	function m.debugDir(cfg)
118		if cfg.debugdir then
119			p.x('WorkingDirectory="%s"', p.vstudio.path(cfg, cfg.debugdir))
120		end
121	end
122
123
124	function m.debugEnvironment(cfg)
125		if #cfg.debugenvs > 0 then
126			p.x('Environment="%s"', table.concat(cfg.debugenvs, "\n"))
127			if cfg.flags.DebugEnvsDontMerge then
128				p.x('EnvironmentMerge="false"')
129			end
130		end
131	end
132