Refactored current platform code for VS2005 and VS2008
This commit is contained in:
parent
a16cdf5fe5
commit
ec90b60d94
@ -142,6 +142,32 @@
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Map a list of platforms to their Visual Studio equivalents, taking the
|
||||
-- Visual Studio version into account. Note that multiple target platforms
|
||||
-- is only supported for Visual Studio 2005 or later right now.
|
||||
--
|
||||
|
||||
function premake.vstudio_get_platforms(platforms, version)
|
||||
local result = { }
|
||||
if version > "vs2003" and platforms then
|
||||
for _, platform in ipairs(platforms) do
|
||||
if platform == "x32" then
|
||||
table.insert(result, "Win32")
|
||||
elseif platform == "x64" then
|
||||
table.insert(result, "x64")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- make sure I've got at least one
|
||||
if #result == 0 then
|
||||
result = { "Win32" }
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Write out entries for the files element; called from premake.walksources().
|
||||
--
|
||||
|
@ -8,6 +8,24 @@
|
||||
function premake.vs2005_solution(sln)
|
||||
io.eol = '\r\n'
|
||||
|
||||
-- Build the list of target platforms
|
||||
local hascpp = premake.hascppproject(sln)
|
||||
local hasdotnet = premake.hasdotnetproject(sln)
|
||||
|
||||
local platforms = { }
|
||||
if hasdotnet then
|
||||
table.insert(platforms, "Any CPU")
|
||||
end
|
||||
if hasdotnet and hascpp then
|
||||
table.insert(platforms, "Mixed Platforms")
|
||||
end
|
||||
if hascpp then
|
||||
platforms.cppdefault = #platforms + 1
|
||||
for _, p in ipairs(premake.vstudio_get_platforms(sln.platforms, _ACTION)) do
|
||||
table.insert(platforms, p)
|
||||
end
|
||||
end
|
||||
|
||||
-- Mark the file as Unicode
|
||||
io.printf('\239\187\191')
|
||||
|
||||
@ -19,7 +37,7 @@
|
||||
io.printf('Microsoft Visual Studio Solution File, Format Version 10.00')
|
||||
io.printf('# Visual Studio 2008')
|
||||
end
|
||||
|
||||
|
||||
-- Write out the list of project entries
|
||||
for prj in premake.eachproject(sln) do
|
||||
-- Build a relative path from the solution file to the project file
|
||||
@ -38,8 +56,8 @@
|
||||
end
|
||||
|
||||
io.printf('Global')
|
||||
premake.vs2005_solution_configurations(sln)
|
||||
premake.vs2005_solution_project_configurations(sln)
|
||||
premake.vs2005_solution_configurations(sln, platforms)
|
||||
premake.vs2005_solution_project_configurations(sln, platforms)
|
||||
premake.vs2005_solution_properties(sln)
|
||||
io.printf('EndGlobal')
|
||||
end
|
||||
@ -51,16 +69,13 @@
|
||||
-- lists all of the configuration/platform pairs that exist in the solution.
|
||||
--
|
||||
|
||||
function premake.vs2005_solution_configurations(sln)
|
||||
local platforms = premake.vs2005_solution_platforms(sln)
|
||||
function premake.vs2005_solution_configurations(sln, platforms)
|
||||
io.printf('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution')
|
||||
|
||||
for _, cfgname in ipairs(sln.configurations) do
|
||||
for _, platname in ipairs(platforms) do
|
||||
io.printf('\t\t%s|%s = %s|%s', cfgname, platname, cfgname, platname)
|
||||
end
|
||||
end
|
||||
|
||||
io.printf('\tEndGlobalSection')
|
||||
end
|
||||
|
||||
@ -71,10 +86,8 @@
|
||||
-- the configuration/platform pairs into each project of the solution.
|
||||
--
|
||||
|
||||
function premake.vs2005_solution_project_configurations(sln)
|
||||
local platforms = premake.vs2005_solution_platforms(sln)
|
||||
function premake.vs2005_solution_project_configurations(sln, platforms)
|
||||
io.printf('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution')
|
||||
|
||||
for prj in premake.eachproject(sln) do
|
||||
for _, cfgname in ipairs(sln.configurations) do
|
||||
for i, platname in ipairs(platforms) do
|
||||
@ -86,7 +99,6 @@
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
io.printf('\tEndGlobalSection')
|
||||
end
|
||||
|
||||
@ -104,53 +116,6 @@
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Translate the generic list of platforms into their Visual Studio equivalents.
|
||||
--
|
||||
|
||||
function premake.vs2005_solution_platforms(sln)
|
||||
-- see if I've already cached the list
|
||||
if sln.__vs2005_platforms then
|
||||
return sln.__vs2005_platforms
|
||||
end
|
||||
|
||||
local hascpp = premake.hascppproject(sln)
|
||||
local hasdotnet = premake.hasdotnetproject(sln)
|
||||
local result = { }
|
||||
|
||||
if hasdotnet then
|
||||
table.insert(result, "Any CPU")
|
||||
end
|
||||
|
||||
if hasdotnet and hascpp then
|
||||
table.insert(result, "Mixed Platforms")
|
||||
end
|
||||
|
||||
if hascpp then
|
||||
result._firstCppPlatform = #result + 1
|
||||
if sln.platforms then
|
||||
for _, pid in ipairs(sln.platforms) do
|
||||
if pid == "x32" then
|
||||
table.insert(result, "Win32")
|
||||
elseif pid == "x64" then
|
||||
table.insert(result, "x64")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- if no VS-compatible platforms were found, add a default
|
||||
if #result < result._firstCppPlatform then
|
||||
table.insert(result, "Win32")
|
||||
end
|
||||
end
|
||||
|
||||
-- cache the result; I need it pretty often
|
||||
sln.__vs2005_platforms = result
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Map a solution-level platform to one compatible with the provided project.
|
||||
-- C++ platforms are mapped to "Any CPU" for .NET projects, and vice versa.
|
||||
@ -164,5 +129,5 @@
|
||||
|
||||
-- C++ projects use the current platform, or the first C++ platform
|
||||
-- if the current one is for .NET
|
||||
return platforms[math.max(i, platforms._firstCppPlatform)]
|
||||
return platforms[math.max(i, platforms.cppdefault)]
|
||||
end
|
@ -4,17 +4,8 @@
|
||||
-- Copyright (c) 2009 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
--
|
||||
-- Write out an empty tool block; there are quite a few of these.
|
||||
--
|
||||
local function printemptyblock(name)
|
||||
io.printf('\t\t\t<Tool')
|
||||
io.printf('\t\t\t\tName="%s"', name)
|
||||
io.printf('\t\t\t/>')
|
||||
end
|
||||
|
||||
|
||||
-- Write out a custom build steps block.
|
||||
-- Write out a custom build steps block
|
||||
local function buildstepsblock(name, steps)
|
||||
io.printf('\t\t\t<Tool')
|
||||
io.printf('\t\t\t\tName="%s"', name)
|
||||
@ -50,7 +41,15 @@
|
||||
io.printf('\tKeyword="%s"', iif(prj.flags.Managed, "ManagedCProj", "Win32Proj"))
|
||||
io.printf('\t>')
|
||||
|
||||
premake.vs200x_vcproj_platforms(prj)
|
||||
-- list target platforms
|
||||
local platforms = premake.vstudio_get_platforms(prj.solution.platforms, _ACTION)
|
||||
io.printf('\t<Platforms>')
|
||||
for _, platform in ipairs(platforms) do
|
||||
io.printf('\t\t<Platform')
|
||||
io.printf('\t\t\tName="%s"', platform)
|
||||
io.printf('\t\t/>')
|
||||
end
|
||||
io.printf('\t</Platforms>')
|
||||
|
||||
if _ACTION > "vs2003" then
|
||||
io.printf('\t<ToolFiles>')
|
||||
@ -59,10 +58,7 @@
|
||||
|
||||
io.printf('\t<Configurations>')
|
||||
|
||||
local platforms = premake.vs2005_solution_platforms(prj.solution)
|
||||
for i = platforms._firstCppPlatform, #platforms do
|
||||
local platform = platforms[i]
|
||||
|
||||
for _, platform in ipairs(platforms) do
|
||||
for cfg in premake.eachconfig(prj) do
|
||||
-- Start a configuration
|
||||
io.printf('\t\t<Configuration')
|
||||
@ -217,7 +213,9 @@
|
||||
-- End build event blocks --
|
||||
|
||||
else
|
||||
printemptyblock(block)
|
||||
io.printf('\t\t\t<Tool')
|
||||
io.printf('\t\t\t\tName="%s"', block)
|
||||
io.printf('\t\t\t/>')
|
||||
end
|
||||
end
|
||||
io.printf('\t\t</Configuration>')
|
||||
|
@ -16,6 +16,7 @@
|
||||
dofile("test_api.lua")
|
||||
dofile("test_targets.lua")
|
||||
dofile("test_keywords.lua")
|
||||
dofile("test_vstudio.lua")
|
||||
dofile("test_vs2002_sln.lua")
|
||||
dofile("test_vs2003_sln.lua")
|
||||
dofile("test_vs2005_sln.lua")
|
||||
|
@ -63,12 +63,15 @@ EndGlobal
|
||||
-- Test a mixed runtime (C++/.NET) solution.
|
||||
--
|
||||
|
||||
function T.vs2005_sln.MixedRuntime()
|
||||
function T.vs2005_sln.MixedPlatformsAndRuntime()
|
||||
project "MyNetProject"
|
||||
language "C#"
|
||||
kind "ConsoleApp"
|
||||
uuid "C9135098-6047-8142-B10E-D27E7F73FCB3"
|
||||
|
||||
solution()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
io.capture()
|
||||
premake.buildconfigs()
|
||||
premake.vs2005_solution(sln)
|
||||
@ -85,97 +88,12 @@ Global
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.Build.0 = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Any CPU.ActiveCfg = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Mixed Platforms.Build.0 = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
]])
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Test combinations of C++ and .NET platforms
|
||||
--
|
||||
|
||||
function T.vs2005_sln.SolutionConfigs_OnMultipleCppPlatforms()
|
||||
solution()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
io.capture()
|
||||
premake.buildconfigs()
|
||||
premake.vs2005_solution_configurations(sln)
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function T.vs2005_sln.ProjectConfigs_OnMultipleCppPlatforms()
|
||||
solution()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
io.capture()
|
||||
premake.buildconfigs()
|
||||
premake.vs2005_solution_project_configurations(sln)
|
||||
test.capture [[
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|x64.Build.0 = Debug|x64
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|Win32.Build.0 = Release|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.ActiveCfg = Release|x64
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function T.vs2005_sln.ProjectConfigs_OnMultipleCppPlatformsAndMixedRuntimes()
|
||||
project "MyNetProject"
|
||||
language "C#"
|
||||
kind "ConsoleApp"
|
||||
uuid "C9135098-6047-8142-B10E-D27E7F73FCB3"
|
||||
|
||||
solution()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
io.capture()
|
||||
premake.buildconfigs()
|
||||
premake.vs2005_solution_project_configurations(sln)
|
||||
test.capture [[
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
||||
{AE61726D-187C-E440-BD07-2556188A6565}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
||||
@ -204,5 +122,9 @@ EndGlobal
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
]]
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
]])
|
||||
end
|
||||
|
@ -231,12 +231,11 @@
|
||||
-- Test multiple platforms
|
||||
--
|
||||
|
||||
function T.vs200x_vcproj.Platforms_OnMultiplePlatforms()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
function T.vs200x_vcproj.PlatformsBlock_OnMultiplePlatforms()
|
||||
platforms { "x32", "x64" }
|
||||
prepare()
|
||||
premake.vs200x_vcproj_platforms(prj)
|
||||
test.capture [[
|
||||
premake.vs200x_vcproj(prj)
|
||||
test.capturecontains [[
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
@ -245,20 +244,46 @@
|
||||
Name="x64"
|
||||
/>
|
||||
</Platforms>
|
||||
]]
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
|
||||
function T.vs200x_vcproj.Platforms_OnMultiplePlatforms()
|
||||
function T.vs200x_vcproj.PlatformConfigs_OnMultiplePlatforms()
|
||||
platforms { "x32", "x64" }
|
||||
|
||||
prepare()
|
||||
premake.vs200x_vcproj(prj)
|
||||
local result = io.endcapture()
|
||||
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|Win32"\r\n')
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|Win32"\r\n')
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|x64"\r\n')
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|x64"\r\n')
|
||||
end
|
||||
|
||||
|
||||
|
||||
function T.vs200x_vcproj.PlatformsBlock_Ignored_OnVs2003()
|
||||
platforms { "x32", "x64" }
|
||||
_ACTION = "vs2003"
|
||||
prepare()
|
||||
premake.vs200x_vcproj(prj)
|
||||
test.capturecontains [[
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function T.vs200x_vcproj.PlatformConfigs_Ignored_OnMultiplePlatforms()
|
||||
platforms { "x32", "x64" }
|
||||
_ACTION = "vs2003"
|
||||
prepare()
|
||||
premake.vs200x_vcproj(prj)
|
||||
local result = io.endcapture()
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Debug|Win32"\r\n')
|
||||
test.istrue(result:find '<Configuration\r\n\t\t\tName="Release|Win32"\r\n')
|
||||
test.isfalse(result:find '<Configuration\r\n\t\t\tName="Debug|x64"\r\n')
|
||||
test.isfalse(result:find '<Configuration\r\n\t\t\tName="Release|x64"\r\n')
|
||||
end
|
||||
|
34
tests/test_vstudio.lua
Normal file
34
tests/test_vstudio.lua
Normal file
@ -0,0 +1,34 @@
|
||||
--
|
||||
-- tests/test_vstudio.lua
|
||||
-- Automated test suite for Visual Studio 200* general functions.
|
||||
-- Copyright (c) 2009 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
T.vstudio = { }
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Test platform mapping
|
||||
--
|
||||
|
||||
function T.vstudio.Platforms_OnVs2002()
|
||||
local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2002")
|
||||
test.isequal("Win32", table.concat(result, "|"))
|
||||
end
|
||||
|
||||
function T.vstudio.Platforms_OnVs2003()
|
||||
local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2003")
|
||||
test.isequal("Win32", table.concat(result, "|"))
|
||||
end
|
||||
|
||||
function T.vstudio.Platforms_OnVs2005()
|
||||
local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2005")
|
||||
test.isequal("Win32|x64", table.concat(result, "|"))
|
||||
end
|
||||
|
||||
function T.vstudio.Platforms_OnVs2008()
|
||||
local result = premake.vstudio_get_platforms(premake.fields.platforms.allowed, "vs2008")
|
||||
test.isequal("Win32|x64", table.concat(result, "|"))
|
||||
end
|
||||
|
@ -39,6 +39,15 @@
|
||||
end
|
||||
|
||||
|
||||
function test.capturecontains(expected)
|
||||
local actual = io.endcapture()
|
||||
expected = expected:gsub("\n", io.eol)
|
||||
if (not actual:find(expected)) then
|
||||
test.fail("result did not contain the expected text")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function test.fail(format, ...)
|
||||
-- convert nils into something more usefuls
|
||||
for i = 1, arg.n do
|
||||
|
Loading…
Reference in New Issue
Block a user