Added tool interface for MSC command line

This commit is contained in:
Jason Perkins 2012-08-18 16:33:37 -04:00
parent dc7d776df0
commit 7a65362e40
4 changed files with 189 additions and 4 deletions

View File

@ -71,7 +71,7 @@
--
-- Returns list of CPPFLAGS for a specific configuration.
-- Returns list of C preprocessor flags for a configuration.
--
function gcc.getcppflags(cfg)
@ -86,7 +86,7 @@
end
--
-- Returns list of CFLAGS for a specific configuration.
-- Returns list of C compiler flags for a configuration.
--
gcc.cflags = {
@ -118,7 +118,7 @@
--
-- Returns a list of CXXFLAGS for a specific configuration.
-- Returns list of C++ compiler flags for a configuration.
--
gcc.cxxflags = {

View File

@ -1,9 +1,143 @@
--
-- msc.lua
-- Interface for the MS C/C++ compiler.
-- Copyright (c) 2009 Jason Perkins and the Premake project
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
--
premake.tools.msc = {}
local msc = premake.tools.msc
local project = premake5.project
local config = premake5.config
--
-- Returns list of C preprocessor flags for a configuration.
--
function msc.getcppflags(cfg)
return {}
end
--
-- Returns list of C compiler flags for a configuration.
--
msc.cflags = {
SEH = "/EHa",
OptimizeSpeed = "/O2",
}
function msc.getcflags(cfg)
local flags = table.translate(cfg.flags, msc.cflags)
local runtime = iif(cfg.flags.StaticRuntime, "/MT", "/MD")
if premake.config.isdebugbuild(cfg) then
runtime = runtime .. "d"
end
table.insert(flags, runtime)
if not premake.config.isoptimizedbuild(cfg) then
table.insert(flags, "/Od")
end
if cfg.flags.Symbols then
table.insert(flags, "/Z7")
end
if not cfg.flags.SEH then
table.insert(flags, "/EHsc")
end
return flags
end
--
-- Returns list of C++ compiler flags for a configuration.
--
msc.cxxflags = {
}
function msc.getcxxflags(cfg)
return table.translate(cfg.flags, msc.cxxflags)
end
msc.ldflags = {
Symbols = "/DEBUG",
}
--
-- Decorate defines for the MSVC command line.
--
function msc.getdefines(defines)
local result = {}
for _, define in ipairs(defines) do
table.insert(result, '-D' .. define)
end
return result
end
--
-- Decorate include file search paths for the MSVC command line.
--
function msc.getincludedirs(cfg, dirs)
local result = {}
for _, dir in ipairs(dirs) do
table.insert(result, "-I" .. project.getrelative(cfg.project, dir))
end
return result
end
--
-- Return a list of linker flags for a specific configuration.
--
msc.ldflags = {
Symbols = "/DEBUG",
}
function msc.getldflags(cfg)
local flags = table.translate(cfg.flags, msc.ldflags)
if not cfg.flags.NoManifest and cfg.kind ~= premake.STATICLIB then
table.insert(flags, "/MANIFEST")
end
if premake.config.isoptimizedbuild(cfg) then
table.insert(flags, "/OPT:REF /OPT:ICF")
end
for _, libdir in ipairs(project.getrelative(cfg.project, cfg.libdirs)) do
table.insert(flags, '/LIBPATH:"' .. libdir .. '"')
end
return flags
end
--
-- Return the list of libraries to link, decorated with flags as needed.
--
function msc.getlinks(cfg)
local links = config.getlinks(cfg, "system", "fullpath")
return links
end
-----------------------------------------------------------------------------
-- Everything below this point is a candidate for deprecation
-----------------------------------------------------------------------------
premake.msc = { }
premake.msc.namestyle = "windows"

View File

@ -92,6 +92,7 @@
-- Toolset tests
dofile("tools/test_gcc.lua")
dofile("tools/test_msc.lua")
dofile("tools/test_snc.lua")
-- Clean tests

50
tests/tools/test_msc.lua Normal file
View File

@ -0,0 +1,50 @@
--
-- tests/test_msc.lua
-- Automated test suite for the Microsoft C toolset interface.
-- Copyright (c) 2012 Jason Perkins and the Premake project
--
T.tools_msc = { }
local suite = T.tools_msc
local msc = premake.tools.msc
local project = premake5.project
--
-- Setup/teardown
--
local sln, prj, cfg
function suite.setup()
sln = test.createsolution()
kind "StaticLib"
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
cfg = premake5.project.getconfig(prj, "Debug")
end
--
-- Check handling of basic linker flags.
--
function suite.ldflags_onSymbols()
flags { "Symbols" }
prepare()
test.isequal({ "/DEBUG" }, msc.getldflags(cfg))
end
--
-- Check handling of library search paths.
--
function suite.libdirs_onLibdirs()
libdirs { "../libs", "libs" }
prepare()
test.isequal({ '/LIBPATH:"../libs"', '/LIBPATH:"libs"' }, msc.getldflags(cfg))
end