Added toolset() API to enable per-configuration tool selection

This commit is contained in:
Jason Perkins 2012-02-16 19:51:14 -05:00
parent 20598184fa
commit 458dcb8cbb
12 changed files with 458 additions and 91 deletions

View File

@ -4,6 +4,7 @@
* Completely overhauled the platform support; too many changes to list
* Enabled per-configuration file lists
* Enabled per-configuration toolset selection
* Added remove...() API to remove values from list fields
* Added debugformat with C7 support for Visual Studio
* The error message for invalid flags now includes the offending value

View File

@ -92,16 +92,25 @@
-- Studio compatible identifier.
--
vstudio.architectures =
{
vstudio.vs200x_architectures = {
x64 = "x64",
xbox360 = "Xbox 360",
}
vstudio.vs2010_architectures = {
}
function vstudio.architecture(cfg)
return vstudio.architectures[cfg.architecture] or
vstudio.architectures[cfg.system] or
"Win32"
local arch
if _ACTION >= "vs2010" then
arch = vstudio.vs2010_architectures[cfg.architecture] or
vstudio.vs2010_architectures[cfg.system]
end
arch = arch or vstudio.vs200x_architectures[cfg.architecture] or
vstudio.vs200x_architectures[cfg.system] or "Win32"
return arch
end

View File

@ -424,15 +424,7 @@
function vc200x.VCExternalLinkerTool(cfg, toolset)
-- temporary: some tools need rewriting for new platforms API
local flags
if toolset.getldflags_ng then
flags = toolset.getldflags(cfg)
else
flags = toolset.getldflags(cfg)
end
local buildoptions = table.join(flags, cfg.linkoptions)
local buildoptions = table.join(toolset.getldflags(cfg), cfg.linkoptions)
if #buildoptions > 0 then
_x(4,'AdditionalOptions="%s"', table.concat(buildoptions, " "))
end
@ -936,7 +928,7 @@
--
function vc200x.toolset(cfg)
return cfg.toolset or vc200x.toolsets[cfg.system]
return premake.tools[cfg.toolset] or vc200x.toolsets[cfg.system]
end

View File

@ -379,6 +379,15 @@
scope = "config",
},
toolset =
{
kind = "string",
scope = "config",
allowed = {
"gcc"
},
},
trimpaths =
{
kind = "dirlist",

View File

@ -12,6 +12,7 @@
premake = { }
premake5 = { }
premake.tools = { }
-- The list of supported platforms; also update list in cmdline.lua

View File

@ -13,6 +13,8 @@
premake.C7 = "c7"
premake.CONSOLEAPP = "ConsoleApp"
premake.CPP = "C++"
premake.GCC = "gcc"
premake.HAIKU = "haiku"
premake.MACOSX = "macosx"
premake.POSIX = "posix"
premake.PS3 = "ps3"

View File

@ -1,9 +1,139 @@
--
-- gcc.lua
-- Provides GCC-specific configuration strings.
-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
-- Copyright (c) 2002-2012 Jason Perkins and the Premake project
--
premake.tools.gcc = {}
local gcc = premake.tools.gcc
local config = premake5.config
--
-- GCC flags for specific systems and architectures.
--
gcc.sysflags = {
x32 = {
cflags = "-m32",
ldflags = { "-m32", "-L/usr/lib32" }
},
x64 = {
cflags = "-m64",
ldflags = { "-m64", "-L/usr/lib64" }
}
}
--
-- Returns list of CPPFLAGS for a specific configuration.
--
function gcc.getcppflags(cfg)
-- always use -MMD to generate dependency information
local flags = { "-MMD" }
-- We want the -MP flag for dependency generation (creates phony rules
-- for headers, prevents make errors if file is later deleted), but Haiku
-- OS doesn't support it (yet)
if cfg.system ~= premake.HAIKU then
table.insert(flags, "-MP")
end
return flags
end
--
-- Returns list of CFLAGS for a specific configuration.
--
gcc.cflags = {
EnableSSE = "-msse",
EnableSSE2 = "-msse2",
ExtraWarnings = "-Wall",
FatalWarnings = "-Werror",
FloatFast = "-ffast-math",
FloatStrict = "-ffloat-store",
NoFramePointer = "-fomit-frame-pointer",
Optimize = "-O2",
OptimizeSize = "-Os",
OptimizeSpeed = "-O3",
Symbols = "-g",
}
function gcc.getcflags(cfg)
local flags = table.translate(cfg.flags, gcc.cflags)
local sysflags = gcc.sysflags[cfg.architecture] or {}
flags = table.join(flags, sysflags.cflags)
if cfg.system ~= premake.WINDOWS and cfg.kind == premake.SHAREDLIB then
table.insert(flags, "-fPIC")
end
return flags
end
--
-- Returns a list of CXXFLAGS for a specific configuration.
--
gcc.cxxflags = {
NoExceptions = "-fno-exceptions",
NoRTTI = "-fno-rtti",
}
function gcc.getcxxflags(cfg)
local flags = table.translate(cfg.flags, gcc.cxxflags)
return flags
end
--
-- Return a list of LDFLAGS for a specific configuration.
--
function gcc.getldflags(cfg)
local flags = {}
if not cfg.flags.Symbols then
-- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html
if cfg.system == premake.MACOSX then
table.insert(flags, "-Wl,-x")
else
table.insert(flags, "-s")
end
end
if cfg.kind == premake.SHAREDLIB then
if cfg.system == premake.MACOSX then
flags = table.join(flags, { "-dynamiclib", "-flat_namespace" })
else
table.insert(flags, "-shared")
end
if cfg.system == "windows" and not cfg.flags.NoImportLib then
table.insert(flags, '-Wl,--out-implib="' .. config.getlinkinfo(cfg).fullpath .. '"')
end
end
if cfg.kind == premake.WINDOWEDAPP and cfg.system == premake.WINDOWS then
table.insert(flags, "-mwindows")
end
local sysflags = gcc.sysflags[cfg.architecture] or {}
flags = table.join(flags, sysflags.ldflags)
return flags
end
-----------------------------------------------------------------------------
-- Everything below this point is a candidate for deprecation
-----------------------------------------------------------------------------
premake.gcc = { }

View File

@ -4,9 +4,88 @@
-- Copyright (c) 2010-2012 Jason Perkins and the Premake project
--
premake.tools.snc = {}
local snc = premake.tools.snc
local config = premake5.config
--
-- SNC flags for specific systems and architectures.
--
snc.sysflags = {
}
--
-- Retrieve the CPPFLAGS for a specific configuration.
--
function snc.getcppflags(cfg)
return { "-MMD", "-MP" }
end
--
-- Retrieve the CFLAGS for a specific configuration.
--
snc.cflags = {
ExtraWarnings = "-Xdiag=2",
FatalWarnings = "-Xquit=2",
}
function snc.getcflags(cfg)
local flags = table.translate(cfg.flags, snc.cflags)
return flags
end
--
-- Retrieve the CXXFLAGS for a specific configuration.
--
snc.cxxflags = {
NoExceptions = "-Xc-=exceptions",
NoRTTI = "-Xc-=rtti",
}
function snc.getcxxflags(cfg)
local flags = table.translate(cfg.flags, snc.cxxflags)
-- turn on exceptions and RTTI by default, to match other toolsets
if not cfg.flags.NoExceptions then
table.insert(flags, "-Xc+=exceptions")
end
if not cfg.flags.NoRTTI then
table.insert(flags, "-Xc+=rtti")
end
return flags
end
--
-- Retrieve the LDFLAGS for a specific configuration.
--
function snc.getldflags(cfg)
local flags = { }
if not cfg.flags.Symbols then
table.insert(flags, "-s")
end
return flags
end
-----------------------------------------------------------------------------
-- Everything below this point is a candidate for deprecation
-----------------------------------------------------------------------------
premake.snc = { }
local config = premake5.config
-- TODO: Will cfg.system == "windows" ever be true for SNC? If
@ -86,27 +165,6 @@
-- Returns a list of linker flags, based on the supplied configuration.
--
function premake.snc.getldflags_ng(cfg)
local result = { }
if not cfg.flags.Symbols then
table.insert(result, "-s")
end
if cfg.kind == "SharedLib" then
table.insert(result, "-shared")
if not cfg.flags.NoImportLib then
table.insert(result, '-Wl,--out-implib="' .. config.getlinkinfo(cfg).fullpath .. '"')
end
end
local platform = platforms["PS3"]
table.insert(result, platform.flags)
table.insert(result, platform.ldflags)
return result
end
function premake.snc.getldflags(cfg)
local result = { }

View File

@ -54,7 +54,6 @@
dofile("base/test_path.lua")
dofile("base/test_table.lua")
dofile("base/test_tree.lua")
dofile("tools/test_gcc.lua")
dofile("base/test_config_bug.lua")
-- Project object tests
@ -76,6 +75,10 @@
-- Baking tests
dofile("base/test_baking.lua")
-- Toolset tests
dofile("tools/test_gcc.lua")
dofile("tools/test_snc.lua")
-- Clean tests
dofile("actions/test_clean.lua")
@ -155,6 +158,7 @@
dofile("actions/codeblocks/test_filters.lua")
dofile("actions/codeblocks/environment_variables.lua")
--
-- Register a test action
--

View File

@ -98,7 +98,10 @@
function test.isequal(expected, actual)
if (type(expected) == "table") then
if type(expected) == "table" then
if #expected < #actual then
test.fail("expected %d items, got %d", #expected, #actual)
end
for k,v in pairs(expected) do
if not (test.isequal(expected[k], actual[k])) then
test.fail("expected %s but was %s", expected, actual)

View File

@ -1,86 +1,177 @@
--
-- tests/test_gcc.lua
-- Automated test suite for the GCC toolset interface.
-- Copyright (c) 2009-2011 Jason Perkins and the Premake project
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
T.gcc = { }
local suite = T.gcc
T.tools_gcc = { }
local suite = T.tools_gcc
local gcc = premake.tools.gcc
--
-- Setup/teardown
--
local sln, prj, cfg
local cfg
function suite.setup()
cfg = { }
cfg.basedir = "."
cfg.location = "."
cfg.language = "C++"
cfg.project = { name = "MyProject" }
cfg.flags = { }
cfg.objectsdir = "obj"
cfg.platform = "Native"
cfg.links = { }
cfg.libdirs = { }
cfg.linktarget = { fullpath="libMyProject.a" }
sln, prj = test.createsolution()
system "Linux"
end
local function prepare()
cfg = premake5.project.getconfig(prj, "Debug")
end
--
-- CPPFLAGS tests
-- By default, the -MMD -MP are used to generate dependencies.
--
function suite.cppflags_OnWindows()
cfg.system = "windows"
local r = premake.gcc.getcppflags(cfg)
test.isequal("-MMD -MP", table.concat(r, " "))
function suite.cppflags_defaultWithMMD()
prepare()
test.isequal({ "-MMD", "-MP" }, gcc.getcppflags(cfg))
end
function suite.cppflags_OnHaiku()
cfg.system = "haiku"
local r = premake.gcc.getcppflags(cfg)
test.isequal("-MMD", table.concat(r, " "))
--
-- Haiku OS doesn't support the -MP flag yet (that's weird, isn't it?)
--
function suite.cppflagsExcludeMP_onHaiku()
system "Haiku"
prepare()
test.isequal({ "-MMD" }, gcc.getcppflags(cfg))
end
--
-- Check the translation of CFLAGS.
--
function suite.cflags_onEnableSSE()
flags { "EnableSSE" }
prepare()
test.isequal({ "-msse" }, gcc.getcflags(cfg))
end
function suite.cflags_onFatalWarnings()
flags { "FatalWarnings" }
prepare()
test.isequal({ "-Werror" }, gcc.getcflags(cfg))
end
--
-- Check the translation of CXXFLAGS.
--
function suite.cflags_onNoExceptions()
flags { "NoExceptions" }
prepare()
test.isequal({ "-fno-exceptions" }, gcc.getcxxflags(cfg))
end
--
-- Check the basic translation of LDFLAGS for a Posix system.
--
function suite.ldflags_defaultOnLinux()
prepare()
test.isequal({ "-s" }, gcc.getldflags(cfg))
end
function suite.ldflags_onSymbols()
flags { "Symbols" }
prepare()
test.isequal({}, gcc.getldflags(cfg))
end
function suite.ldflags_onSharedLib()
kind "SharedLib"
prepare()
test.isequal({ "-s", "-shared" }, gcc.getldflags(cfg))
end
--
-- Check Mac OS X variants on LDFLAGS.
--
function suite.ldflags_onMacOSXStrip()
system "MacOSX"
prepare()
test.isequal({ "-Wl,-x" }, gcc.getldflags(cfg))
end
function suite.ldflags_onMacOSXSharedLib()
system "MacOSX"
kind "SharedLib"
prepare()
test.isequal({ "-Wl,-x", "-dynamiclib", "-flat_namespace" }, gcc.getldflags(cfg))
end
--
-- Check Windows variants on LDFLAGS.
--
function suite.ldflags_onWindowsharedLib()
system "Windows"
kind "SharedLib"
prepare()
test.isequal({ "-s", "-shared", '-Wl,--out-implib="MyProject.lib"' }, gcc.getldflags(cfg))
end
function suite.ldflags_onWindowsApp()
system "Windows"
kind "WindowedApp"
prepare()
test.isequal({ "-s", "-mwindows" }, gcc.getldflags(cfg))
end
--
-- CFLAGS tests
-- Make sure system or architecture flags are added properly.
--
function suite.cflags_SharedLib_Windows()
cfg.kind = "SharedLib"
cfg.system = "windows"
local r = premake.gcc.getcflags(cfg)
test.isequal('', table.concat(r,"|"))
function suite.cflags_onX32()
architecture "x32"
prepare()
test.isequal({ "-m32" }, gcc.getcflags(cfg))
end
function suite.cflags_OnFpFast()
cfg.flags = { "FloatFast" }
local r = premake.gcc.getcflags(cfg)
test.isequal('-ffast-math', table.concat(r,"|"))
function suite.ldflags_onX32()
architecture "x32"
prepare()
test.isequal({ "-s", "-m32", "-L/usr/lib32" }, gcc.getldflags(cfg))
end
function suite.cflags_onX64()
architecture "x64"
prepare()
test.isequal({ "-m64" }, gcc.getcflags(cfg))
end
function suite.cflags_OnFpStrict()
cfg.flags = { "FloatStrict" }
local r = premake.gcc.getcflags(cfg)
test.isequal('-ffloat-store', table.concat(r,"|"))
function suite.ldflags_onX64()
architecture "x64"
prepare()
test.isequal({ "-s", "-m64", "-L/usr/lib64" }, gcc.getldflags(cfg))
end
--
-- LDFLAGS tests
-- Non-Windows shared libraries should marked as position independent.
--
function suite.ldflags_SharedLib_Windows()
cfg.kind = "SharedLib"
cfg.system = "windows"
local r = premake.gcc.getldflags(cfg)
test.isequal('-s|-shared|-Wl,--out-implib="libMyProject.a"', table.concat(r,"|"))
function suite.cflags_onWindowsSharedLib()
system "MacOSX"
kind "SharedLib"
prepare()
test.isequal({ "-fPIC" }, gcc.getcflags(cfg))
end
function suite.linkflags_OnFrameworks()
cfg.links = { "Cocoa.framework" }
local r = premake.gcc.getlinkflags(cfg)
test.isequal('-framework Cocoa', table.concat(r,"|"))
end

67
tests/tools/test_snc.lua Normal file
View File

@ -0,0 +1,67 @@
--
-- tests/test_snc.lua
-- Automated test suite for the SNC toolset interface.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.tools_snc = {}
local suite = T.tools_snc
local snc = premake.tools.snc
--
-- Setup/teardown
--
local sln, prj, cfg
function suite.setup()
sln, prj = test.createsolution()
system "PS3"
end
local function prepare()
cfg = premake5.project.getconfig(prj, "Debug")
end
--
-- By default, the -MMD -MP are used to generate dependencies.
--
function suite.cppflags_defaultWithMMD()
prepare()
test.isequal({ "-MMD", "-MP" }, snc.getcppflags(cfg))
end
--
-- Check the translation of CFLAGS.
--
function suite.cflags_onFatalWarnings()
flags { "FatalWarnings" }
prepare()
test.isequal({ "-Xquit=2" }, snc.getcflags(cfg))
end
--
-- Turn on exceptions and RTTI by default, to match the other Premake supported toolsets.
--
function suite.cxxflags_onDefault()
prepare()
test.isequal({ "-Xc+=exceptions", "-Xc+=rtti" }, snc.getcxxflags(cfg))
end
--
-- Check the translation of LDFLAGS.
--
function suite.cflags_onDefaults()
prepare()
test.isequal({ "-s" }, snc.getldflags(cfg))
end