Merge pull request #48 from starkos/vs-platform-toolset
Modify toolset() to accept an option version number
This commit is contained in:
commit
f01d7f726c
@ -16,6 +16,7 @@
|
||||
"base/path.lua",
|
||||
"base/os.lua",
|
||||
"base/io.lua",
|
||||
"base/tools.lua",
|
||||
"base/tree.lua",
|
||||
"base/globals.lua",
|
||||
|
||||
|
@ -6,7 +6,8 @@
|
||||
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local api = premake.api
|
||||
local p = premake
|
||||
local api = p.api
|
||||
|
||||
local DOC_URL = "See https://github.com/premake/premake-core/wiki/"
|
||||
|
||||
@ -907,9 +908,10 @@
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
allowed = function(value)
|
||||
local key = value:lower()
|
||||
if premake.tools[key] ~= nil then
|
||||
return key
|
||||
value = value:lower()
|
||||
local tool, version = p.tools.canonical(value)
|
||||
if tool then
|
||||
return value
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
@ -1407,14 +1407,19 @@
|
||||
|
||||
|
||||
function m.platformToolset(cfg)
|
||||
local action = premake.action.current()
|
||||
local value = action.vstudio.platformToolset
|
||||
if value then
|
||||
local tool, version = p.config.toolset(cfg)
|
||||
if version then
|
||||
version = "v" .. version
|
||||
else
|
||||
local action = premake.action.current()
|
||||
version = action.vstudio.platformToolset
|
||||
end
|
||||
if version then
|
||||
-- should only be written if there is a C/C++ file in the config
|
||||
for i = 1, #cfg.files do
|
||||
if path.iscppfile(cfg.files[i]) then
|
||||
_p(2,'<PlatformToolset>%s</PlatformToolset>', value)
|
||||
return
|
||||
p.w('<PlatformToolset>%s</PlatformToolset>', version)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
premake = premake or {}
|
||||
premake.modules = {}
|
||||
premake.tools = {}
|
||||
|
||||
premake.extensions = premake.modules
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
--
|
||||
-- config.lua
|
||||
-- Premake configuration object API
|
||||
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2011-2015 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local p = premake
|
||||
@ -539,9 +539,12 @@
|
||||
|
||||
---
|
||||
-- Return the appropriate toolset adapter for the provided configuration,
|
||||
-- or nil if no toolset is specified.
|
||||
-- or nil if no toolset is specified. If a specific version was provided,
|
||||
-- returns that as a second argument.
|
||||
---
|
||||
|
||||
function config.toolset(cfg)
|
||||
return premake.tools[cfg.toolset]
|
||||
if cfg.toolset then
|
||||
return p.tools.canonical(cfg.toolset)
|
||||
end
|
||||
end
|
||||
|
40
src/base/tools.lua
Normal file
40
src/base/tools.lua
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
-- tools.lua
|
||||
-- Work with Premake's collection of tool adapters.
|
||||
-- Author Jason Perkins
|
||||
-- Copyright (c) 2015 Jason Perkins and the Premake project
|
||||
---
|
||||
|
||||
local p = premake
|
||||
p.tools = {}
|
||||
|
||||
|
||||
---
|
||||
-- Given a toolset identifier (e.g. "gcc" or "gcc-4.8") returns the
|
||||
-- corresponding tool adapter and the version, if one was provided.
|
||||
--
|
||||
-- @param identifier
|
||||
-- A toolset identifier composed of two parts: the toolset name,
|
||||
-- which should match of the name of the adapter object ("gcc",
|
||||
-- "clang", etc.) in the premake.tools namespace, and and optional
|
||||
-- version number, separated by a dash.
|
||||
--
|
||||
-- To make things more intuitive for Visual Studio users, supports
|
||||
-- identifiers like "v100" to represent the v100 Microsoft platform
|
||||
-- toolset.
|
||||
-- @return
|
||||
-- If successful, returns the toolset adapter object. If a version
|
||||
-- was specified as part of the identifier, that is returned as a
|
||||
-- second return value. If no corresponding tool adapter exists,
|
||||
-- returns nil.
|
||||
---
|
||||
|
||||
function p.tools.canonical(identifier)
|
||||
local parts
|
||||
if identifier:startswith("v") then
|
||||
parts = { "msc", identifier:sub(2) }
|
||||
else
|
||||
parts = identifier:explode("-")
|
||||
end
|
||||
return p.tools[parts[1]], parts[2]
|
||||
end
|
@ -118,6 +118,7 @@ return {
|
||||
"actions/vstudio/vc2010/test_manifest.lua",
|
||||
"actions/vstudio/vc2010/test_nmake_props.lua",
|
||||
"actions/vstudio/vc2010/test_output_props.lua",
|
||||
"actions/vstudio/vc2010/test_platform_toolset.lua",
|
||||
"actions/vstudio/vc2010/test_project_configs.lua",
|
||||
"actions/vstudio/vc2010/test_project_refs.lua",
|
||||
"actions/vstudio/vc2010/test_prop_sheet.lua",
|
||||
|
@ -302,52 +302,3 @@
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Visual Studio 2012 adds a new <PlatformToolset> element.
|
||||
---
|
||||
|
||||
function suite.addsPlatformToolset_onVS2012()
|
||||
_ACTION = "vs2012"
|
||||
files "hello.cpp"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function suite.addsPlatformToolset_onVS2013()
|
||||
_ACTION = "vs2013"
|
||||
files "hello.cpp"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function suite.excludesPlatformToolset_onNoRelevantSources()
|
||||
_ACTION = "vs2012"
|
||||
files "hello.x"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
]]
|
||||
end
|
||||
|
88
tests/actions/vstudio/vc2010/test_platform_toolset.lua
Normal file
88
tests/actions/vstudio/vc2010/test_platform_toolset.lua
Normal file
@ -0,0 +1,88 @@
|
||||
--
|
||||
-- tests/actions/vstudio/vc2010/test_platform_toolset.lua
|
||||
-- Validate VC platform toolset generation.
|
||||
-- Copyright (c) 2013-2015 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local suite = test.declare("vstudio_vs2010_platform_toolset")
|
||||
local vc2010 = premake.vstudio.vc2010
|
||||
|
||||
|
||||
--
|
||||
-- Setup
|
||||
--
|
||||
|
||||
local sln, prj
|
||||
|
||||
function suite.setup()
|
||||
_ACTION = "vs2012"
|
||||
sln, prj = test.createsolution()
|
||||
files "hello.cpp"
|
||||
end
|
||||
|
||||
local function prepare()
|
||||
cfg = test.getconfig(prj, "Debug")
|
||||
vc2010.platformToolset(cfg)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Check default values for each version.
|
||||
--
|
||||
|
||||
function suite.correctDefault_onVS2010()
|
||||
_ACTION = "vs2010"
|
||||
prepare()
|
||||
test.isemptycapture()
|
||||
end
|
||||
|
||||
|
||||
function suite.correctDefault_onVS2012()
|
||||
_ACTION = "vs2012"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
function suite.correctDefault_onVS2013()
|
||||
_ACTION = "vs2013"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Element should only be written if C++ files are present.
|
||||
--
|
||||
|
||||
function suite.empty_onNoRelevantSources()
|
||||
removefiles "hello.cpp"
|
||||
prepare()
|
||||
test.isemptycapture()
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Check for overrides from project scripts.
|
||||
--
|
||||
|
||||
function suite.canOverrideFromScript_withV()
|
||||
toolset "v90"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PlatformToolset>v90</PlatformToolset>
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.canOverrideFromScript_withMsc()
|
||||
toolset "msc-100"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<PlatformToolset>v100</PlatformToolset>
|
||||
]]
|
||||
end
|
Reference in New Issue
Block a user