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.
|
2012-01-12 21:59:15 +00:00
|
|
|
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
|
2009-03-25 23:04:32 +00:00
|
|
|
--
|
|
|
|
|
2011-02-02 18:27:52 +00:00
|
|
|
premake.vstudio.sln2005 = { }
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
io.eol = '\r\n'
|
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
|
|
|
|
2011-02-16 20:16:07 +00:00
|
|
|
sln2005.header(sln)
|
2009-04-09 20:02:49 +00:00
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
for prj in premake.solution.eachproject_ng(sln) do
|
|
|
|
sln2005.project_ng(prj)
|
2009-03-25 23:04:32 +00:00
|
|
|
end
|
|
|
|
|
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)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('EndGlobal')
|
2009-03-25 23:04:32 +00:00
|
|
|
end
|
|
|
|
|
2011-02-16 20:16:07 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Generate the solution header
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.header(sln)
|
2012-06-08 19:07:49 +00:00
|
|
|
local version = {
|
|
|
|
vs2005 = 9,
|
|
|
|
vs2008 = 10,
|
|
|
|
vs2010 = 11,
|
|
|
|
vs2012 = 12,
|
|
|
|
}
|
2011-02-16 20:16:07 +00:00
|
|
|
_p('Microsoft Visual Studio Solution File, Format Version %d.00', version[_ACTION])
|
|
|
|
_p('# Visual Studio %s', _ACTION:sub(3))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out an entry for a project
|
|
|
|
--
|
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
function sln2005.project_ng(prj)
|
2011-02-16 20:16:07 +00:00
|
|
|
-- Build a relative path from the solution file to the project file
|
2012-01-12 21:59:15 +00:00
|
|
|
local slnpath = premake.solution.getlocation(prj.solution)
|
2012-09-25 14:20:14 +00:00
|
|
|
local prjpath = vstudio.projectfile(prj)
|
2012-01-12 21:59:15 +00:00
|
|
|
prjpath = path.translate(path.getrelative(slnpath, prjpath))
|
|
|
|
|
2012-01-12 23:27:30 +00:00
|
|
|
_x('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, prjpath, prj.uuid)
|
2012-06-08 19:07:49 +00:00
|
|
|
if _ACTION < "vs2012" then
|
|
|
|
sln2005.projectdependencies_ng(prj)
|
|
|
|
end
|
2011-02-16 20:16:07 +00:00
|
|
|
_p('EndProject')
|
|
|
|
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)
|
|
|
|
-- build a VS cfg descriptor for each solution configuration
|
|
|
|
local slncfg = {}
|
|
|
|
for cfg in solution.eachconfig(sln) do
|
|
|
|
local platform = vstudio.solutionPlatform(cfg)
|
|
|
|
slncfg[cfg] = string.format("%s|%s", cfg.buildcfg, platform)
|
|
|
|
end
|
|
|
|
|
|
|
|
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
|
|
|
|
for cfg in solution.eachconfig(sln) do
|
|
|
|
_p(2,'%s = %s', slncfg[cfg], slncfg[cfg])
|
|
|
|
end
|
|
|
|
_p(1,'EndGlobalSection')
|
|
|
|
|
|
|
|
_p(1,'GlobalSection(ProjectConfigurationPlatforms) = postSolution')
|
|
|
|
for prj in solution.eachproject_ng(sln) do
|
|
|
|
for cfg in solution.eachconfig(sln) do
|
|
|
|
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)
|
|
|
|
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slncfg[cfg], prjplatform, architecture)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
_p(1,'EndGlobalSection')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-01-12 21:59:15 +00:00
|
|
|
--
|
|
|
|
-- Write out contents of the SolutionProperties section; currently unused.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.properties(sln)
|
|
|
|
_p('\tGlobalSection(SolutionProperties) = preSolution')
|
|
|
|
_p('\t\tHideSolutionNode = FALSE')
|
|
|
|
_p('\tEndGlobalSection')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- Everything below this point is a candidate for deprecation
|
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Entry point; creates the solution file.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.generate(sln)
|
|
|
|
io.eol = '\r\n'
|
|
|
|
|
|
|
|
-- Precompute Visual Studio configurations
|
|
|
|
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
|
|
|
|
|
|
|
|
-- Mark the file as Unicode
|
|
|
|
_p('\239\187\191')
|
|
|
|
|
|
|
|
sln2005.header(sln)
|
|
|
|
|
|
|
|
for prj in premake.solution.eachproject(sln) do
|
|
|
|
sln2005.project(prj)
|
|
|
|
end
|
|
|
|
|
|
|
|
_p('Global')
|
|
|
|
sln2005.platforms(sln)
|
|
|
|
sln2005.project_platforms(sln)
|
|
|
|
sln2005.properties(sln)
|
|
|
|
_p('EndGlobal')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out an entry for a project
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.project(prj)
|
|
|
|
-- Build a relative path from the solution file to the project file
|
2012-09-25 14:20:14 +00:00
|
|
|
local projpath = path.translate(path.getrelative(prj.solution.location, vstudio.projectfile_old(prj)), "\\")
|
2012-01-12 21:59:15 +00:00
|
|
|
|
|
|
|
_p('Project("{%s}") = "%s", "%s", "{%s}"', vstudio.tool(prj), prj.name, projpath, prj.uuid)
|
|
|
|
sln2005.projectdependencies(prj)
|
|
|
|
_p('EndProject')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the list of project dependencies for a particular project.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.projectdependencies(prj)
|
|
|
|
local deps = premake.getdependencies(prj)
|
|
|
|
if #deps > 0 then
|
|
|
|
_p('\tProjectSection(ProjectDependencies) = postProject')
|
|
|
|
for _, dep in ipairs(deps) do
|
|
|
|
_p('\t\t{%s} = {%s}', dep.uuid, dep.uuid)
|
|
|
|
end
|
|
|
|
_p('\tEndProjectSection')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the contents of the SolutionConfigurationPlatforms section, which
|
|
|
|
-- lists all of the configuration/platform pairs that exist in the solution.
|
|
|
|
--
|
|
|
|
|
|
|
|
function sln2005.platforms(sln)
|
|
|
|
_p('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution')
|
|
|
|
for _, cfg in ipairs(sln.vstudio_configs) do
|
|
|
|
_p('\t\t%s = %s', cfg.name, cfg.name)
|
|
|
|
end
|
|
|
|
_p('\tEndGlobalSection')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Write out the contents of the ProjectConfigurationPlatforms section, which maps
|
|
|
|
-- the configuration/platform pairs into each project of the solution.
|
|
|
|
--
|
|
|
|
|
2011-02-02 18:27:52 +00:00
|
|
|
function sln2005.project_platforms(sln)
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution')
|
2009-11-04 18:25:08 +00:00
|
|
|
for prj in premake.solution.eachproject(sln) do
|
2009-05-06 23:25:50 +00:00
|
|
|
for _, cfg in ipairs(sln.vstudio_configs) do
|
|
|
|
|
|
|
|
-- .NET projects always map to the "Any CPU" platform (for now, at
|
|
|
|
-- least). For C++, "Any CPU" and "Mixed Platforms" map to the first
|
|
|
|
-- C++ compatible target platform in the solution list.
|
|
|
|
local mapped
|
|
|
|
if premake.isdotnetproject(prj) then
|
|
|
|
mapped = "Any CPU"
|
|
|
|
else
|
|
|
|
if cfg.platform == "Any CPU" or cfg.platform == "Mixed Platforms" then
|
|
|
|
mapped = sln.vstudio_configs[3].platform
|
2009-04-09 20:02:49 +00:00
|
|
|
else
|
2009-05-06 23:25:50 +00:00
|
|
|
mapped = cfg.platform
|
2009-04-09 20:02:49 +00:00
|
|
|
end
|
2009-05-06 23:25:50 +00:00
|
|
|
end
|
2009-04-09 20:02:49 +00:00
|
|
|
|
2009-05-06 23:25:50 +00:00
|
|
|
_p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped)
|
|
|
|
if mapped == cfg.platform or cfg.platform == "Mixed Platforms" then
|
|
|
|
_p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfg.name, cfg.buildcfg, mapped)
|
2009-03-25 23:04:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-04-11 11:49:07 +00:00
|
|
|
_p('\tEndGlobalSection')
|
2009-03-25 23:04:32 +00:00
|
|
|
end
|