Ported VS2008 .vcproj Platforms and Configuration blocks to new platforms API

This commit is contained in:
Jason Perkins 2012-01-04 17:16:06 -05:00
parent 8f8a1a989f
commit 2baa0ce3ad
7 changed files with 276 additions and 92 deletions

View File

@ -52,8 +52,10 @@
--
function vstudio.architecture(cfg)
local architecture = cfg.architecture or "Win32"
return architecture
if cfg.architecture == "x32" then
return "Win32"
end
return cfg.architecture or "Win32"
end

View File

@ -10,6 +10,7 @@
--
premake.vstudio.vc200x = { }
local vstudio = premake.vstudio
local vc200x = premake.vstudio.vc200x
local tree = premake.tree
@ -72,7 +73,41 @@
--
-- Write out the <Configuration> element.
--
function vc200x.configuration(cfg)
_p(2,'<Configuration')
local platform = vstudio.projectplatform(cfg)
local architecture = vstudio.architecture(cfg)
_p(3,'Name="%s|%s"', premake.esc(platform), premake.esc(architecture))
_p(3,'OutputDirectory="%s"', premake.esc("."))
_p(3,'IntermediateDirectory="%s"', premake.esc("obj\\" .. cfg.buildcfg .. "\\" .. cfg.project.name))
local cfgtype
if (cfg.kind == "SharedLib") then
cfgtype = 2
elseif (cfg.kind == "StaticLib") then
cfgtype = 4
else
cfgtype = 1
end
_p(3,'ConfigurationType="%s"', cfgtype)
if (cfg.flags.MFC) then
_p(3, 'UseOfMFC="%d"', iif(cfg.flags.StaticRuntime, 1, 2))
end
_p(3,'CharacterSet="%s"', iif(cfg.flags.Unicode, 1, 2))
if cfg.flags.Managed then
_p(3,'ManagedExtensions="1"')
end
_p(3,'>')
end
-- TODO: REMOVE, OBSOLETE
function vc200x.Configuration(name, cfg)
_p(2,'<Configuration')
_p(3,'Name="%s"', premake.esc(name))
@ -178,12 +213,30 @@
end
--
-- Write out the <Platforms> element; ensures that each target platform
-- is listed only once. Skips over .NET's pseudo-platforms (like "Any CPU").
-- Write out the <Platforms> element, listing each architecture used
-- by the project's configurations.
--
function vc200x.platforms(prj)
_p(1,'<Platforms>')
architectures = { }
for cfg in premake5.project.eachconfig(prj) do
local arch = vstudio.architecture(cfg)
if not architectures[arch] then
_p(2,'<Platform')
_p(3,'Name="%s"', arch)
_p(2,'/>')
architectures[arch] = true
end
end
_p(1,'</Platforms>')
end
-- TODO: REMOVE, OBSOLETE
function vc200x.Platforms(prj)
local used = { }
_p(1,'<Platforms>')
@ -805,4 +858,18 @@
end
--
-- Enumerate the project's configurations.
--
function vc200x.configurations(prj)
_p(1,'<Configurations>')
for cfg in premake5.project.eachconfig(prj) do
-- write the opening <Configuration> element
vc200x.configuration(cfg)
_p(2,'</Configuration>')
end
_p(1,'</Configurations>')
end

View File

@ -32,19 +32,19 @@
-- configurations should be listed, and the architecture should default to Win32.
--
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.Build.0 = Debug|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
]]
end
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.ActiveCfg = Debug|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Win32.Build.0 = Debug|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.ActiveCfg = Release|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
]]
end
--
-- When a platform is specified, it should be listed instead of the default Win32
-- in the solution platform. Solution platforms should map to the correct project
@ -55,47 +55,47 @@
platforms { "Static" }
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Static.ActiveCfg = Debug Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Static.Build.0 = Debug Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Static.ActiveCfg = Release Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Static.Build.0 = Release Static|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Static.ActiveCfg = Debug Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|Static.Build.0 = Debug Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Static.ActiveCfg = Release Static|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|Static.Build.0 = Release Static|Win32
EndGlobalSection
]]
end
--
-- The x32 architecture should get mapped to "Win32".
--
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
platforms { "x32" }
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x32.ActiveCfg = Debug x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x32.Build.0 = Debug x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x32.ActiveCfg = Release x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x32.Build.0 = Release x32|Win32
EndGlobalSection
]]
end
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
platforms { "x32" }
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x32.ActiveCfg = Debug x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x32.Build.0 = Debug x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x32.ActiveCfg = Release x32|Win32
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x32.Build.0 = Release x32|Win32
EndGlobalSection
]]
end
--
-- The x64 architecture should remain "x64".
--
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
platforms { "x64" }
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.Build.0 = Debug x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.Build.0 = Release x64|x64
EndGlobalSection
]]
end
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
platforms { "x64" }
prepare()
test.capture [[
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.ActiveCfg = Debug x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Debug|x64.Build.0 = Debug x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.ActiveCfg = Release x64|x64
{C9135098-6047-8142-B10E-D27E7F73FCB3}.Release|x64.Build.0 = Release x64|x64
EndGlobalSection
]]
end

View File

@ -235,46 +235,6 @@
end
--
-- Test multiple platforms
--
function suite.Platforms_OnMultiplePlatforms()
platforms { "x32", "x64" }
prepare()
vc200x.generate(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
--
-- Test x64 handling
--
function suite.PlatformsList_OnX64()
platforms { "Native", "x64" }
prepare()
vc200x.Platforms(prj)
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
]]
end
--
-- Test Xbox360 handling
--

View File

@ -0,0 +1,74 @@
--
-- tests/actions/vstudio/vc200x/test_configuration.lua
-- Test the Visual Studio 2002-2008 project's Configuration block
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.vstudio_vc200x_configuration = { }
local suite = T.vstudio_vc200x_configuration
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = "vs2008"
sln, prj = test.createsolution()
end
local function prepare()
local it = premake5.project.eachconfig(prj)
local cfg = it()
vc200x.configuration(cfg)
end
--
-- Check the results of generating with the default project settings
-- (C++ console application).
--
function suite.defaultSettings()
prepare()
test.capture [[
<Configuration
Name="Debug|Win32"
OutputDirectory="."
IntermediateDirectory="obj\Debug\MyProject"
ConfigurationType="1"
CharacterSet="2"
>
]]
end
--
-- If a platform is specified, it should be included in the platform name.
--
function suite.usesWin32_onX32()
platforms { "x32" }
prepare()
test.capture [[
<Configuration
Name="Debug x32|Win32"
]]
end
--
-- Check the x64 architecture handling.
--
function suite.usesX64Architecture_onX64Platform()
platforms { "x64" }
prepare()
test.capture [[
<Configuration
Name="Debug x64|x64"
]]
end

View File

@ -0,0 +1,79 @@
--
-- tests/actions/vstudio/vc200x/test_platforms.lua
-- Test the Visual Studio 2002-2008 project's Platforms block
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.vstudio_vc200x_platforms = { }
local suite = T.vstudio_vc200x_platforms
local vc200x = premake.vstudio.vc200x
--
-- Setup
--
local sln, prj
function suite.setup()
_ACTION = "vs2008"
sln, prj = test.createsolution()
end
local function prepare()
vc200x.platforms(prj)
end
--
-- If no architectures are specified, Win32 should be the default.
--
function suite.win32Listed_onNoPlatforms()
prepare()
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
]]
end
--
-- If multiple configurations use the same architecture, it should
-- still only be listed once.
--
function suite.architectureListedOnlyOnce_onMultipleConfigurations()
platforms { "Static", "Dynamic" }
prepare()
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
]]
end
--
-- If multiple architectures are used, they should all be listed.
--
function suite.allArchitecturesListed_onMultipleArchitectures()
platforms { "x32", "x64" }
prepare()
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
]]
end

View File

@ -104,10 +104,12 @@
dofile("actions/vstudio/vc200x/test_compiler_block.lua")
dofile("actions/vstudio/vc200x/debugdir.lua")
dofile("actions/vstudio/vc200x/header.lua")
dofile("actions/vstudio/vc200x/test_configuration.lua")
dofile("actions/vstudio/vc200x/test_files.lua")
dofile("actions/vstudio/vc200x/test_filters.lua")
dofile("actions/vstudio/vc200x/test_linker_block.lua")
dofile("actions/vstudio/vc200x/test_mfc.lua")
dofile("actions/vstudio/vc200x/test_platforms.lua")
-- Visual Studio 2010 C/C++ projects
dofile("actions/vstudio/vc2010/test_compile_settings.lua")