2009-03-25 23:04:32 +00:00
|
|
|
--
|
|
|
|
-- vs2005_solution.lua
|
2012-06-08 19:07:49 +00:00
|
|
|
-- Generate a Visual Studio 2005-2012 solution.
|
2013-05-22 15:15:48 +00:00
|
|
|
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
|
2009-03-25 23:04:32 +00:00
|
|
|
--
|
|
|
|
|
2012-11-27 15:18:06 +00:00
|
|
|
premake.vstudio.sln2005 = {}
|
2011-02-02 18:27:52 +00:00
|
|
|
local vstudio = premake.vstudio
|
|
|
|
local sln2005 = premake.vstudio.sln2005
|
2012-02-03 21:03:46 +00:00
|
|
|
local solution = premake.solution
|
2012-01-12 21:59:15 +00:00
|
|
|
local project = premake5.project
|
2012-12-18 16:09:50 +00:00
|
|
|
local tree = premake.tree
|
2012-01-12 21:59:15 +00:00
|
|
|
|
2011-02-16 20:16:07 +00:00
|
|
|
|
2012-01-03 22:08:22 +00:00
|
|
|
--
|
2012-01-12 21:59:15 +00:00
|
|
|
-- Generate a Visual Studio 200x solution, with support for the new platforms API.
|
2012-01-03 22:08:22 +00:00
|
|
|
--
|
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
function sln2005.generate_ng(sln)
|
2009-03-25 23:04:32 +00:00
|
|
|
-- Mark the file as Unicode
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\239\187\191')
|
2009-03-25 23:04:32 +00:00
|
|
|
|
2013-01-09 16:41:32 +00:00
|
|
|
sln2005.reorderProjects(sln)
|
|
|
|
|
2013-04-25 13:59:55 +00:00
|
|
|
sln2005.header()
|
2012-12-18 16:09:50 +00:00
|
|
|
sln2005.projects(sln)
|
2009-03-25 23:04:32 +00:00
|
|
|
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('Global')
|
2012-11-17 20:49:06 +00:00
|
|
|
sln2005.configurationPlatforms(sln)
|
2011-02-02 18:27:52 +00:00
|
|
|
sln2005.properties(sln)
|
2012-12-18 16:09:50 +00:00
|
|
|
sln2005.NestedProjects(sln)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('EndGlobal')
|
2013-05-22 15:15:48 +00:00
|
|
|
|
2009-03-25 23:04:32 +00:00
|
|
|
end
|
|
|
|
|
2011-02-16 20:16:07 +00:00
|
|
|
|
|
|
|
--
|
2013-04-25 13:59:55 +00:00
|
|
|
-- Generate the solution header. Each Visual Studio action definition
|
|
|
|
-- should include its own version.
|
2011-02-16 20:16:07 +00:00
|
|
|
--
|
|
|
|
|
2013-04-25 13:59:55 +00:00
|
|
|
function sln2005.header()
|
|
|
|
local action = premake.action.current()
|
2013-04-25 20:05:08 +00:00
|
|
|
_p('Microsoft Visual Studio Solution File, Format Version %d.00', action.vstudio.solutionVersion)
|
2011-02-16 20:16:07 +00:00
|
|
|
_p('# Visual Studio %s', _ACTION:sub(3))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-01-09 16:41:32 +00:00
|
|
|
--
|
|
|
|
-- If a startup project is specified, move it (and any enclosing groups)
|
|
|
|
-- to the front of the project list. This will make Visual Studio treat
|
|
|
|
-- it like a startup project.
|
|
|
|
--
|
|
|
|
-- I force the new ordering into the tree so that it will get applied to
|
|
|
|
-- all sections of the solution; otherwise the first change to the solution
|
|
|
|
-- in the IDE will cause the orderings to get rewritten.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.reorderProjects(sln)
|
|
|
|
if sln.startproject then
|
|
|
|
local np
|
|
|
|
local tr = solution.grouptree(sln)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onleaf = function(n)
|
|
|
|
if n.project.name == sln.startproject then
|
|
|
|
np = n
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
while np and np.parent do
|
|
|
|
local p = np.parent
|
|
|
|
local i = table.indexof(p.children, np)
|
|
|
|
table.remove(p.children, i)
|
|
|
|
table.insert(p.children, 1, np)
|
|
|
|
np = p
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-02-16 20:16:07 +00:00
|
|
|
--
|
2012-12-18 16:09:50 +00:00
|
|
|
-- Write out the list of projects and groups contained by the solution.
|
2011-02-16 20:16:07 +00:00
|
|
|
--
|
|
|
|
|
2012-12-18 16:09:50 +00:00
|
|
|
function sln2005.projects(sln)
|
|
|
|
local tr = solution.grouptree(sln)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onleaf = function(n)
|
|
|
|
local prj = n.project
|
|
|
|
|
|
|
|
-- Build a relative path from the solution file to the project file
|
|
|
|
local slnpath = premake.solution.getlocation(prj.solution)
|
|
|
|
local prjpath = vstudio.projectfile(prj)
|
|
|
|
prjpath = path.translate(path.getrelative(slnpath, prjpath))
|
2013-01-08 18:19:56 +00:00
|
|
|
|
2012-12-18 16:09:50 +00:00
|
|
|
_x('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, prjpath, prj.uuid)
|
|
|
|
if _ACTION < "vs2012" then
|
|
|
|
sln2005.projectdependencies_ng(prj)
|
|
|
|
end
|
|
|
|
_p('EndProject')
|
|
|
|
end,
|
2013-01-08 18:19:56 +00:00
|
|
|
|
2012-12-18 16:09:50 +00:00
|
|
|
onbranch = function(n)
|
|
|
|
_x('Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "%s", "%s", "{%s}"', n.name, n.name, n.uuid)
|
|
|
|
_p('EndProject')
|
2013-01-08 18:19:56 +00:00
|
|
|
end,
|
2012-12-18 16:09:50 +00:00
|
|
|
})
|
2011-02-16 20:16:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the list of project dependencies for a particular project.
|
|
|
|
--
|
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
function sln2005.projectdependencies_ng(prj)
|
|
|
|
local deps = project.getdependencies(prj)
|
2011-02-16 20:16:07 +00:00
|
|
|
if #deps > 0 then
|
2012-01-12 21:59:15 +00:00
|
|
|
_p(1,'ProjectSection(ProjectDependencies) = postProject')
|
2011-02-16 20:16:07 +00:00
|
|
|
for _, dep in ipairs(deps) do
|
2012-01-12 21:59:15 +00:00
|
|
|
_p(2,'{%s} = {%s}', dep.uuid, dep.uuid)
|
2011-02-16 20:16:07 +00:00
|
|
|
end
|
2012-01-12 21:59:15 +00:00
|
|
|
_p(1,'EndProjectSection')
|
2011-02-16 20:16:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-11-17 20:49:06 +00:00
|
|
|
--
|
|
|
|
-- Write out the tables that map solution configurations to project configurations.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.configurationPlatforms(sln)
|
2013-05-21 12:48:22 +00:00
|
|
|
|
|
|
|
-- Build a VS cfg descriptor for each solution configuration.
|
|
|
|
|
2012-11-17 20:49:06 +00:00
|
|
|
local slncfg = {}
|
|
|
|
for cfg in solution.eachconfig(sln) do
|
|
|
|
local platform = vstudio.solutionPlatform(cfg)
|
|
|
|
slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform)
|
|
|
|
end
|
2013-01-08 18:19:56 +00:00
|
|
|
|
2013-05-21 12:48:22 +00:00
|
|
|
-- Make a working list of each solution configuration, and sort it into
|
|
|
|
-- Visual Studio's desired ordering. If I don't this, Visual Studio will
|
|
|
|
-- reshuffle everything on the first save.
|
|
|
|
|
|
|
|
local sorted = {}
|
2012-11-17 20:49:06 +00:00
|
|
|
for cfg in solution.eachconfig(sln) do
|
2013-05-21 12:48:22 +00:00
|
|
|
table.insert(sorted, cfg)
|
2012-11-17 20:49:06 +00:00
|
|
|
end
|
|
|
|
|
2013-05-21 12:48:22 +00:00
|
|
|
table.sort(sorted, function(a,b)
|
|
|
|
return slncfg[a]:lower() < slncfg[b]:lower()
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- Now use the sorted list to output the configuration maps.
|
|
|
|
|
|
|
|
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
|
|
|
|
table.foreachi(sorted, function (cfg)
|
|
|
|
_p(2,'%s = %s', slncfg[cfg], slncfg[cfg])
|
|
|
|
end)
|
|
|
|
_p(1,"EndGlobalSection")
|
|
|
|
|
|
|
|
_p(1,"GlobalSection(ProjectConfigurationPlatforms) = postSolution")
|
2013-01-08 18:19:56 +00:00
|
|
|
local tr = solution.grouptree(sln)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onleaf = function(n)
|
|
|
|
local prj = n.project
|
|
|
|
|
2013-05-21 12:48:22 +00:00
|
|
|
table.foreachi(sorted, function (cfg)
|
2013-01-08 18:19:56 +00:00
|
|
|
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
|
|
|
|
if prjcfg then
|
|
|
|
local prjplatform = vstudio.projectPlatform(prjcfg)
|
|
|
|
local architecture = vstudio.archFromConfig(prjcfg, true)
|
|
|
|
|
|
|
|
_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
|
2013-05-27 14:21:10 +00:00
|
|
|
if prjcfg.kind ~= premake.NONE then
|
|
|
|
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
|
|
|
|
end
|
2013-01-08 18:19:56 +00:00
|
|
|
end
|
2013-05-21 12:48:22 +00:00
|
|
|
end)
|
2012-11-17 20:49:06 +00:00
|
|
|
end
|
2013-01-08 18:19:56 +00:00
|
|
|
})
|
2013-05-21 12:48:22 +00:00
|
|
|
_p(1,"EndGlobalSection")
|
2012-11-17 20:49:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
--
|
|
|
|
-- Write out contents of the SolutionProperties section; currently unused.
|
|
|
|
--
|
|
|
|
|
2013-01-08 18:19:56 +00:00
|
|
|
function sln2005.properties(sln)
|
2012-01-12 21:59:15 +00:00
|
|
|
_p('\tGlobalSection(SolutionProperties) = preSolution')
|
|
|
|
_p('\t\tHideSolutionNode = FALSE')
|
|
|
|
_p('\tEndGlobalSection')
|
|
|
|
end
|
2012-12-18 16:09:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the NestedProjects block, which describes the structure of
|
|
|
|
-- any solution groups.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.NestedProjects(sln)
|
|
|
|
local tr = solution.grouptree(sln)
|
2013-01-09 15:03:50 +00:00
|
|
|
if tree.hasbranches(tr) then
|
2012-12-18 16:09:50 +00:00
|
|
|
_p(1,'GlobalSection(NestedProjects) = preSolution')
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onnode = function(n)
|
|
|
|
if n.parent.uuid then
|
|
|
|
_p(2,'{%s} = {%s}', (n.project or n).uuid, n.parent.uuid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
_p(1,'EndGlobalSection')
|
|
|
|
end
|
|
|
|
end
|