Improved handling of architecture and .NET projects in VS solution configurations
This commit is contained in:
parent
72d4331f65
commit
1bdf2f2e31
@ -6,6 +6,7 @@
|
||||
|
||||
premake.vstudio = { }
|
||||
local vstudio = premake.vstudio
|
||||
local solution = premake.solution
|
||||
local project = premake5.project
|
||||
|
||||
|
||||
@ -192,6 +193,8 @@
|
||||
|
||||
function vstudio.architecture(cfg)
|
||||
local arch
|
||||
|
||||
-- allow add-ons to override the architecture for VS2010 specifically
|
||||
if _ACTION >= "vs2010" then
|
||||
arch = vstudio.vs2010_architectures[cfg.architecture] or
|
||||
vstudio.vs2010_architectures[cfg.system]
|
||||
@ -216,6 +219,56 @@
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Returns the Visual Studio solution configuration identifier corresponding
|
||||
-- to the given Premake configuration.
|
||||
--
|
||||
-- @param cfg
|
||||
-- The configuration to query.
|
||||
-- @return
|
||||
-- A solution configuration identifier of the format BuildCfg|Platform,
|
||||
-- corresponding to the Premake values of the same names. If no platform
|
||||
-- was specified by the script, the architecture is used instead.
|
||||
--
|
||||
|
||||
function vstudio.solutionconfig(cfg)
|
||||
local platform = cfg.platform
|
||||
|
||||
-- if no platform name was specified, use the architecture instead;
|
||||
-- since architectures are defined in the projects and not at the
|
||||
-- solution level, need to poke around to figure this out
|
||||
if not platform then
|
||||
local hascpp = false
|
||||
local hasdotnet = false
|
||||
|
||||
for prj in premake.solution.eachproject_ng(cfg.solution) do
|
||||
if premake.iscppproject(prj) then
|
||||
hascpp = true
|
||||
elseif premake.isdotnetproject(prj) then
|
||||
hasdotnet = true
|
||||
end
|
||||
|
||||
-- map the solution config to the corresponding project cfg
|
||||
local prjcfg = project.getconfig(prj, cfg.buildcfg, cfg.platform)
|
||||
if prjcfg then
|
||||
if prjcfg.architecture then
|
||||
platform = vstudio.architecture(prjcfg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- use a default if no other architecture was specified
|
||||
if hascpp and hasdotnet then
|
||||
platform = "Mixed Platforms"
|
||||
else
|
||||
platform = platform or iif(hascpp, "Win32", "Any CPU")
|
||||
end
|
||||
end
|
||||
|
||||
return string.format("%s|%s", cfg.buildcfg, platform)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Returns the full, absolute path to the Visual Studio project file
|
||||
-- corresponding to a particular project object.
|
||||
@ -398,15 +451,6 @@
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Given a project configuration, return a Visual Studio compatible platform name.
|
||||
--
|
||||
|
||||
function vstudio.platform(cfg)
|
||||
return cfg.platform or "Win32"
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Returns the project platform name for a specified configuration. Each build
|
||||
-- configuration/platform pairing set in the solution gets mapped to a project
|
||||
|
@ -93,10 +93,8 @@
|
||||
function sln2005.solutionConfigurationPlatforms(sln)
|
||||
_p(1,'GlobalSection(SolutionConfigurationPlatforms) = preSolution')
|
||||
for cfg in solution.eachconfig(sln) do
|
||||
local platforms = sln2005.getcfgplatforms(sln, cfg)
|
||||
for _, platform in ipairs(platforms) do
|
||||
_p(2,'%s|%s = %s|%s', cfg.buildcfg, platform, cfg.buildcfg, platform)
|
||||
end
|
||||
local ident = vstudio.solutionconfig(cfg)
|
||||
_p(2,'%s = %s', ident, ident)
|
||||
end
|
||||
_p(1,'EndGlobalSection')
|
||||
end
|
||||
@ -113,12 +111,12 @@
|
||||
for slncfg in solution.eachconfig(sln) do
|
||||
local prjcfg = project.getconfig(prj, slncfg.buildcfg, slncfg.platform)
|
||||
if prjcfg then
|
||||
local slnplatform = vstudio.platform(slncfg)
|
||||
local slnident = vstudio.solutionconfig(slncfg)
|
||||
local prjplatform = vstudio.projectplatform(prjcfg)
|
||||
local architecture = vstudio.architecture(prjcfg)
|
||||
|
||||
_p(2,'{%s}.%s|%s.ActiveCfg = %s|%s', prj.uuid, slncfg.buildcfg, slnplatform, prjplatform, architecture)
|
||||
_p(2,'{%s}.%s|%s.Build.0 = %s|%s', prj.uuid, slncfg.buildcfg, slnplatform, prjplatform, architecture)
|
||||
_p(2,'{%s}.%s.ActiveCfg = %s|%s', prj.uuid, slnident, prjplatform, architecture)
|
||||
_p(2,'{%s}.%s.Build.0 = %s|%s', prj.uuid, slnident, prjplatform, architecture)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -137,50 +135,6 @@
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Return a list of required platforms for a specific configuration.
|
||||
-- Depending on mix of languages used by the solution, a configuration
|
||||
-- may need multiple platforms listed.
|
||||
--
|
||||
-- @param sln
|
||||
-- The current solution.
|
||||
-- @param cfg
|
||||
-- The configuration to query.
|
||||
-- @return
|
||||
-- A array of one or more platform identifiers.
|
||||
--
|
||||
|
||||
function sln2005.getcfgplatforms(sln, cfg)
|
||||
local r = {}
|
||||
|
||||
local hasdotnet = solution.hasdotnetproject(sln)
|
||||
local hascpp = solution.hascppproject(sln)
|
||||
local is2010 = _ACTION > "vs2008"
|
||||
|
||||
if hasdotnet then
|
||||
if not hascpp or not is2010 then
|
||||
table.insert(r, "Any CPU")
|
||||
end
|
||||
if hascpp or is2010 then
|
||||
table.insert(r, "Mixed Platforms")
|
||||
end
|
||||
end
|
||||
|
||||
if cfg.platform then
|
||||
table.insert(r, cfg.platform)
|
||||
else
|
||||
if hascpp or not is2010 then
|
||||
table.insert(r, "Win32")
|
||||
end
|
||||
if hasdotnet and is2010 then
|
||||
table.insert(r, "x86")
|
||||
end
|
||||
end
|
||||
|
||||
return r
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Everything below this point is a candidate for deprecation
|
||||
|
@ -123,6 +123,7 @@
|
||||
|
||||
-- fill in any calculated values
|
||||
for _, cfg in ipairs(configs) do
|
||||
cfg.solution = sln
|
||||
premake5.config.bake(cfg)
|
||||
end
|
||||
|
||||
|
@ -29,11 +29,10 @@
|
||||
|
||||
|
||||
--
|
||||
-- Check the basic form of C++ solutions: only the specified build configurations
|
||||
-- should be listed, and the architecture should default to Win32.
|
||||
-- If no platforms are specified, the architecture should be used as a default.
|
||||
--
|
||||
|
||||
function suite.buildCfgAndWin32Used_onNoPlatformsSet()
|
||||
function suite.useArchAsPlatform_onCppAndNoArch()
|
||||
prepare()
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -43,12 +42,56 @@
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.useArchAsPlatform_onCppAnd32()
|
||||
architecture "x32"
|
||||
prepare()
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.useArchAsPlatform_onCppAnd64()
|
||||
architecture "x64"
|
||||
prepare()
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.useArchAsPlatform_onCs()
|
||||
prepare("C#")
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.useArchAsPlatform_onMixedLanguage()
|
||||
project("MyProject2")
|
||||
language "C++"
|
||||
prepare("C#")
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- When a platform is specified, it should be listed instead of the default Win32.
|
||||
-- When a platform is specified, it should be listed instead of the architecture default.
|
||||
--
|
||||
|
||||
function suite.buildCfgAndPlatformUsed_onPlatformsSet()
|
||||
function suite.buildCfgAndPlatformUsed_onPlatformsSet_onCpp()
|
||||
platforms { "Static" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
@ -59,6 +102,17 @@
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.buildCfgAndPlatformUsed_onPlatformsSet_onCs()
|
||||
platforms { "Static" }
|
||||
prepare("C#")
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Static = Debug|Static
|
||||
Release|Static = Release|Static
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- When multiple platforms are provided, the sort order should match Visual Studio.
|
||||
@ -77,85 +131,3 @@
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- When the only project language is C#, the Any CPU configuration should be added.
|
||||
--
|
||||
|
||||
function suite.addsAnyCPU_onCsOnly()
|
||||
prepare("C#")
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- If projects in the solution use both C# and C++, the Mixed Platforms
|
||||
-- configuration should be added.
|
||||
--
|
||||
|
||||
function suite.addsMixedPlatforms_onMixedLanguages()
|
||||
project("MyProject2")
|
||||
language "C#"
|
||||
prepare()
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Visual Studio 2010 does things a little differently: x86 instead of
|
||||
-- Win32, and Mixed Platforms are always listed.
|
||||
--
|
||||
|
||||
function suite.onCsharpAndVs2010()
|
||||
_ACTION = "vs2010"
|
||||
prepare("C#")
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- On mixed language projects, Visual Studio 2010 lists both x86 and
|
||||
-- Win32 architectures by default.
|
||||
--
|
||||
|
||||
function suite.onMixedLanguageAndVs2010()
|
||||
_ACTION = "vs2010"
|
||||
project("MyProject2")
|
||||
language "C#"
|
||||
prepare()
|
||||
test.capture [[
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Mixed Platforms = Release|Mixed Platforms
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
]]
|
||||
end
|
||||
|
@ -115,7 +115,6 @@
|
||||
-- Visual Studio 2005-2010 solutions
|
||||
dofile("actions/vstudio/sln2005/test_dependencies.lua")
|
||||
dofile("actions/vstudio/sln2005/test_header.lua")
|
||||
dofile("actions/vstudio/sln2005/projectplatforms.lua")
|
||||
dofile("actions/vstudio/sln2005/test_projects.lua")
|
||||
dofile("actions/vstudio/sln2005/test_project_platforms.lua")
|
||||
dofile("actions/vstudio/sln2005/test_solution_platforms.lua")
|
||||
|
Loading…
Reference in New Issue
Block a user