Initial community commit

This commit is contained in:
Jef
2024-09-24 14:54:57 +02:00
parent 537bcbc862
commit 20d28e80a5
16810 changed files with 4640254 additions and 2 deletions

View File

@@ -0,0 +1,336 @@
--
-- clang.lua
-- Clang toolset adapter for Premake
-- Copyright (c) 2013 Jason Perkins and the Premake project
--
local p = premake
p.tools.clang = {}
local clang = p.tools.clang
local gcc = p.tools.gcc
local config = p.config
--
-- Build a list of flags for the C preprocessor corresponding to the
-- settings in a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C preprocessor flags.
--
function clang.getcppflags(cfg)
-- Just pass through to GCC for now
local flags = gcc.getcppflags(cfg)
return flags
end
--
-- Build a list of C compiler flags corresponding to the settings in
-- a particular project configuration. These flags are exclusive
-- of the C++ compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C compiler flags.
--
clang.shared = {
architecture = gcc.shared.architecture,
flags = gcc.shared.flags,
floatingpoint = {
Fast = "-ffast-math",
},
strictaliasing = gcc.shared.strictaliasing,
optimize = {
Off = "-O0",
On = "-O2",
Debug = "-O0",
Full = "-O3",
Size = "-Os",
Speed = "-O3",
},
pic = gcc.shared.pic,
vectorextensions = gcc.shared.vectorextensions,
isaextensions = gcc.shared.isaextensions,
warnings = gcc.shared.warnings,
symbols = gcc.shared.symbols,
unsignedchar = gcc.shared.unsignedchar,
omitframepointer = gcc.shared.omitframepointer,
compileas = gcc.shared.compileas
}
clang.cflags = table.merge(gcc.cflags, {
})
function clang.getcflags(cfg)
local shared = config.mapFlags(cfg, clang.shared)
local cflags = config.mapFlags(cfg, clang.cflags)
local flags = table.join(shared, cflags)
flags = table.join(flags, clang.getwarnings(cfg), clang.getsystemversionflags(cfg))
return flags
end
function clang.getwarnings(cfg)
return gcc.getwarnings(cfg)
end
--
-- Returns C/C++ system version related build flags
--
function clang.getsystemversionflags(cfg)
local flags = {}
if cfg.system == p.MACOSX or cfg.system == p.IOS then
local minVersion = p.project.systemversion(cfg)
if minVersion ~= nil then
local name = iif(cfg.system == p.MACOSX, "macosx", "iphoneos")
table.insert (flags, "-m" .. name .. "-version-min=" .. p.project.systemversion(cfg))
end
end
return flags
end
--
-- Build a list of C++ compiler flags corresponding to the settings
-- in a particular project configuration. These flags are exclusive
-- of the C compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C++ compiler flags.
--
clang.cxxflags = table.merge(gcc.cxxflags, {
})
function clang.getcxxflags(cfg)
local shared = config.mapFlags(cfg, clang.shared)
local cxxflags = config.mapFlags(cfg, clang.cxxflags)
local flags = table.join(shared, cxxflags)
flags = table.join(flags, clang.getwarnings(cfg), clang.getsystemversionflags(cfg))
return flags
end
--
-- Returns a list of defined preprocessor symbols, decorated for
-- the compiler command line.
--
-- @param defines
-- An array of preprocessor symbols to define; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function clang.getdefines(defines)
-- Just pass through to GCC for now
local flags = gcc.getdefines(defines)
return flags
end
function clang.getundefines(undefines)
-- Just pass through to GCC for now
local flags = gcc.getundefines(undefines)
return flags
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function clang.getforceincludes(cfg)
-- Just pass through to GCC for now
local flags = gcc.getforceincludes(cfg)
return flags
end
--
-- Returns a list of include file search directories, decorated for
-- the compiler command line.
--
-- @param cfg
-- The project configuration.
-- @param dirs
-- An array of include file search directories; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function clang.getincludedirs(cfg, dirs, sysdirs, frameworkdirs)
-- Just pass through to GCC for now
local flags = gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs)
return flags
end
clang.getrunpathdirs = gcc.getrunpathdirs
--
-- get the right output flag.
--
function clang.getsharedlibarg(cfg)
return gcc.getsharedlibarg(cfg)
end
--
-- Build a list of linker flags corresponding to the settings in
-- a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of linker flags.
--
clang.ldflags = {
architecture = {
x86 = "-m32",
x86_64 = "-m64",
},
flags = {
LinkTimeOptimization = "-flto",
},
kind = {
SharedLib = function(cfg)
local r = { clang.getsharedlibarg(cfg) }
if cfg.system == "windows" and not cfg.flags.NoImportLib then
table.insert(r, '-Wl,--out-implib="' .. cfg.linktarget.relpath .. '"')
elseif cfg.system == p.LINUX then
table.insert(r, '-Wl,-soname=' .. p.quoted(cfg.linktarget.name))
elseif table.contains(os.getSystemTags(cfg.system), "darwin") then
table.insert(r, '-Wl,-install_name,' .. p.quoted('@rpath/' .. cfg.linktarget.name))
end
return r
end,
WindowedApp = function(cfg)
if cfg.system == p.WINDOWS then return "-mwindows" end
end,
},
system = {
wii = "$(MACHDEP)",
}
}
function clang.getldflags(cfg)
local flags = config.mapFlags(cfg, clang.ldflags)
return flags
end
--
-- Build a list of additional library directories for a particular
-- project configuration, decorated for the tool command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of decorated additional library directories.
--
function clang.getLibraryDirectories(cfg)
-- Just pass through to GCC for now
local flags = gcc.getLibraryDirectories(cfg)
return flags
end
--
-- Build a list of libraries to be linked for a particular project
-- configuration, decorated for the linker command line.
--
-- @param cfg
-- The project configuration.
-- @param systemOnly
-- Boolean flag indicating whether to link only system libraries,
-- or system libraries and sibling projects as well.
-- @return
-- A list of libraries to link, decorated for the linker.
--
function clang.getlinks(cfg, systemonly, nogroups)
return gcc.getlinks(cfg, systemonly, nogroups)
end
--
-- Return a list of makefile-specific configuration rules. This will
-- be going away when I get a chance to overhaul these adapters.
--
-- @param cfg
-- The project configuration.
-- @return
-- A list of additional makefile rules.
--
function clang.getmakesettings(cfg)
-- Just pass through to GCC for now
local flags = gcc.getmakesettings(cfg)
return flags
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment. I will
-- be moving these into global configuration blocks when I get
-- the chance.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
clang.tools = {
cc = "clang",
cxx = "clang++",
ar = function(cfg) return iif(cfg.flags.LinkTimeOptimization, "llvm-ar", "ar") end
}
function clang.gettoolname(cfg, tool)
local value = clang.tools[tool]
if type(value) == "function" then
value = value(cfg)
end
return value
end

View File

@@ -0,0 +1,329 @@
--
-- dotnet.lua
-- Interface for the C# compilers, all of which are flag compatible.
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project
--
local p = premake
p.tools.dotnet = {}
local dotnet = p.tools.dotnet
local project = p.project
local config = p.config
--
-- Examine the file and project configurations to glean additional
-- information about a source code in a C# project.
--
-- @param fcfg
-- The file configuration to consider.
-- @return
-- A table containing the following keys:
--
-- action: the build action for the file; one of "Compile", "Copy",
-- "EmbeddedResource", or "None".
-- subtype: an additional categorization of the file type, or nil if
-- no subtype is required.
-- dependency: a related file name, (i.e. *.Designer.cs) if appropriate
-- for the file action and subtype.
--
function dotnet.fileinfo(fcfg)
local info = {}
if (fcfg == nil) then
return info
end
local fname = fcfg.abspath
local ext = path.getextension(fname):lower()
-- Determine the build action for the file, falling back to the file
-- extension if no explicit action is available.
if fcfg.buildaction == "Compile" or ext == ".cs" or ext == ".fs" then
info.action = "Compile"
elseif fcfg.buildaction == "Embed" or ext == ".resx" then
info.action = "EmbeddedResource"
elseif fcfg.buildaction == "Copy" or ext == ".asax" or ext == ".aspx" or ext == ".dll" or ext == ".tt" then
info.action = "Content"
elseif fcfg.buildaction == "Resource" then
info.action = "Resource"
elseif ext == ".xaml" then
if fcfg.buildaction == "Application" or path.getbasename(fname) == "App" then
if fcfg.project.kind == p.SHAREDLIB then
info.action = "None"
else
info.action = "ApplicationDefinition"
end
else
info.action = "Page"
end
else
info.action = "None"
end
-- Try to work out any subtypes, based on the files in the project
if info.action == "Compile" and fname:endswith(".cs") then
if fname:endswith(".Designer.cs") then
local basename = fname:sub(1, -13)
-- Look for associated files: .resx, .settings, .cs, .xsd
local testname = basename .. ".resx"
if project.hasfile(fcfg.project, testname) then
info.AutoGen = "True"
info.DependentUpon = testname
end
testname = basename .. ".settings"
if project.hasfile(fcfg.project, testname) then
info.AutoGen = "True"
info.DependentUpon = testname
info.DesignTimeSharedInput = "True"
end
testname = basename .. ".cs"
if project.hasfile(fcfg.project, testname) then
info.AutoGen = nil
info.SubType = "Dependency"
info.DependentUpon = testname
end
testname = basename .. ".xsd"
if project.hasfile(fcfg.project, testname) then
info.AutoGen = "True"
info.DesignTime = "True"
info.DependentUpon = testname
end
elseif fname:endswith(".xaml.cs") then
info.SubType = "Code"
info.DependentUpon = fname:sub(1, -4)
else
local basename = fname:sub(1, -4)
-- Is there a matching *.xsd?
testname = basename .. ".xsd"
if project.hasfile(fcfg.project, testname) then
info.DependentUpon = testname
end
-- Is there a matching *.Designer.cs?
testname = basename .. ".Designer.cs"
if project.hasfile(fcfg.project, testname) then
info.SubType = "Form"
end
testname = basename .. ".tt"
if project.hasfile(fcfg.project, testname) then
info.AutoGen = "True"
info.DesignTime = "True"
info.DependentUpon = testname
end
end
-- Allow C# object type build actions to override the default
if fcfg.buildaction == "Component" or
fcfg.buildaction == "Form" or
fcfg.buildaction == "UserControl"
then
info.SubType = fcfg.buildaction
end
-- This flag is deprecated, will remove eventually
if fcfg.flags and fcfg.flags.Component then
info.SubType = "Component"
end
end
if info.action == "Content" then
info.CopyToOutputDirectory = "PreserveNewest"
end
if info.action == "EmbeddedResource" and fname:endswith(".resx") then
local basename = fname:sub(1, -6)
-- Is there a matching *.cs file?
local testname = basename .. ".cs"
if project.hasfile(fcfg.project, testname) then
info.DependentUpon = testname
if project.hasfile(fcfg.project, basename .. ".Designer.cs") then
info.SubType = "DesignerType"
end
else
-- Is there a matching *.Designer.cs?
testname = basename .. ".Designer.cs"
if project.hasfile(fcfg.project, testname) then
info.SubType = "Designer"
local resourceAccessGenerator = "ResXFileCodeGenerator"
if fcfg.project.resourcegenerator then
if fcfg.project.resourcegenerator == "public" then
resourceAccessGenerator = "PublicResXFileCodeGenerator"
end
end
info.Generator = resourceAccessGenerator
info.LastGenOutput = path.getname(testname)
end
end
end
if info.action == "None" and fname:endswith(".settings") then
local testname = fname:sub(1, -10) .. ".Designer.cs"
if project.hasfile(fcfg.project, testname) then
info.Generator = "SettingsSingleFileGenerator"
info.LastGenOutput = path.getname(testname)
end
end
if info.action == "Content" and fname:endswith(".tt") then
local testname = fname:sub(1, -4) .. ".cs"
if project.hasfile(fcfg.project, testname) then
info.Generator = "TextTemplatingFileGenerator"
info.LastGenOutput = path.getname(testname)
info.CopyToOutputDirectory = nil
end
end
if info.action == "None" and fname:endswith(".xsd") then
local testname = fname:sub(1, -5) .. ".Designer.cs"
if project.hasfile(fcfg.project, testname) then
info.SubType = "Designer"
info.Generator = "MSDataSetGenerator"
info.LastGenOutput = path.getname(testname)
end
end
if info.action == "None" and (fname:endswith(".xsc") or fname:endswith(".xss")) then
local testname = fname:sub(1, -5) .. ".xsd"
if project.hasfile(fcfg.project, testname) then
info.DependentUpon = testname
end
end
if fname:endswith(".xaml") then
local testname = fname .. ".cs"
if project.hasfile(fcfg.project, testname) then
info.SubType = "Designer"
info.Generator = "MSBuild:Compile"
end
end
if info.DependentUpon then
info.DependentUpon = path.getname(info.DependentUpon)
end
return info
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "csc" for the C# compiler, or
-- "resgen" for the resource compiler.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
function dotnet.gettoolname(cfg, tool)
local compilers = {
msnet = "csc",
mono = "mcs",
pnet = "cscc",
}
if tool == "csc" then
local toolset = _OPTIONS.dotnet or "msnet"
return compilers[toolset]
else
return "resgen"
end
end
--
-- Returns a list of compiler flags, based on the supplied configuration.
--
dotnet.flags = {
clr = {
Unsafe = "/unsafe",
},
flags = {
FatalWarning = "/warnaserror",
},
optimize = {
On = "/optimize",
Size = "/optimize",
Speed = "/optimize",
},
symbols = {
On = "/debug",
}
}
function dotnet.getflags(cfg)
local flags = config.mapFlags(cfg, dotnet.flags)
-- Tells the compiler not to include the csc.rsp response file which
-- it does by default and references all the assemblies shipped with
-- the .NET Framework. VS sets this flag by default for C# projects.
table.insert(flags, '/noconfig')
if cfg.project.icon then
local fn = project.getrelative(cfg.project, cfg.project.icon)
table.insert(flags, string.format('/win32icon:"%s"', fn))
end
if #cfg.defines > 0 then
table.insert(flags, table.implode(cfg.defines, "/d:", "", " "))
end
if cfg.csversion ~= nil then
table.insert(flags, '/langversion:' .. cfg.csversion)
end
return table.join(flags, cfg.buildoptions)
end
--
-- Translates the Premake kind into the CSC kind string.
--
function dotnet.getkind(cfg)
if (cfg.kind == "ConsoleApp") then
return "Exe"
elseif (cfg.kind == "WindowedApp") then
return "WinExe"
elseif (cfg.kind == "SharedLib") then
return "Library"
else
error("invalid dotnet kind " .. cfg.kind .. ". Valid kinds are ConsoleApp, WindowsApp, SharedLib")
end
end
--
-- Returns makefile-specific configuration rules.
--
function dotnet.getmakesettings(cfg)
return nil
end

View File

@@ -0,0 +1,639 @@
---
-- gcc.lua
-- Provides GCC-specific configuration strings.
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project
---
local p = premake
p.tools.gcc = {}
local gcc = p.tools.gcc
local project = p.project
local config = p.config
--
-- Returns list of C preprocessor flags for a configuration.
--
gcc.cppflags = {
system = {
haiku = "-MMD",
wii = { "-MMD", "-MP", "-I$(LIBOGC_INC)", "$(MACHDEP)" },
_ = { "-MMD", "-MP" }
}
}
function gcc.getcppflags(cfg)
local flags = config.mapFlags(cfg, gcc.cppflags)
return flags
end
--
-- Returns string to be appended to -g
--
function gcc.getdebugformat(cfg)
local flags = {
Default = "",
Dwarf = "dwarf",
SplitDwarf = "split-dwarf",
}
return flags
end
--
-- Returns list of C compiler flags for a configuration.
--
gcc.shared = {
architecture = {
x86 = "-m32",
x86_64 = "-m64",
},
flags = {
FatalCompileWarnings = "-Werror",
LinkTimeOptimization = "-flto",
ShadowedVariables = "-Wshadow",
UndefinedIdentifiers = "-Wundef",
},
floatingpoint = {
Fast = "-ffast-math",
Strict = "-ffloat-store",
},
strictaliasing = {
Off = "-fno-strict-aliasing",
Level1 = { "-fstrict-aliasing", "-Wstrict-aliasing=1" },
Level2 = { "-fstrict-aliasing", "-Wstrict-aliasing=2" },
Level3 = { "-fstrict-aliasing", "-Wstrict-aliasing=3" },
},
optimize = {
Off = "-O0",
On = "-O2",
Debug = "-Og",
Full = "-O3",
Size = "-Os",
Speed = "-O3",
},
pic = {
On = "-fPIC",
},
vectorextensions = {
AVX = "-mavx",
AVX2 = "-mavx2",
SSE = "-msse",
SSE2 = "-msse2",
SSE3 = "-msse3",
SSSE3 = "-mssse3",
["SSE4.1"] = "-msse4.1",
["SSE4.2"] = "-msse4.2",
},
isaextensions = {
MOVBE = "-mmovbe",
POPCNT = "-mpopcnt",
PCLMUL = "-mpclmul",
LZCNT = "-mlzcnt",
BMI = "-mbmi",
BMI2 = "-mbmi2",
F16C = "-mf16c",
AES = "-maes",
FMA = "-mfma",
FMA4 = "-mfma4",
RDRND = "-mrdrnd",
},
warnings = {
Off = "-w",
High = "-Wall",
Extra = {"-Wall", "-Wextra"},
Everything = "-Weverything",
},
symbols = function(cfg, mappings)
local values = gcc.getdebugformat(cfg)
local debugformat = values[cfg.debugformat] or ""
return {
On = "-g" .. debugformat,
FastLink = "-g" .. debugformat,
Full = "-g" .. debugformat,
}
end,
unsignedchar = {
On = "-funsigned-char",
Off = "-fno-unsigned-char"
},
omitframepointer = {
On = "-fomit-frame-pointer",
Off = "-fno-omit-frame-pointer"
},
compileas = {
["Objective-C"] = "-x objective-c",
["Objective-C++"] = "-x objective-c++",
}
}
gcc.cflags = {
cdialect = {
["C89"] = "-std=c89",
["C90"] = "-std=c90",
["C99"] = "-std=c99",
["C11"] = "-std=c11",
["gnu89"] = "-std=gnu89",
["gnu90"] = "-std=gnu90",
["gnu99"] = "-std=gnu99",
["gnu11"] = "-std=gnu11",
}
}
function gcc.getcflags(cfg)
local shared_flags = config.mapFlags(cfg, gcc.shared)
local cflags = config.mapFlags(cfg, gcc.cflags)
local flags = table.join(shared_flags, cflags, gcc.getsystemversionflags(cfg))
flags = table.join(flags, gcc.getwarnings(cfg))
return flags
end
function gcc.getwarnings(cfg)
local result = {}
for _, enable in ipairs(cfg.enablewarnings) do
table.insert(result, '-W' .. enable)
end
for _, disable in ipairs(cfg.disablewarnings) do
table.insert(result, '-Wno-' .. disable)
end
for _, fatal in ipairs(cfg.fatalwarnings) do
table.insert(result, '-Werror=' .. fatal)
end
return result
end
--
-- Returns C/C++ system version build flags
--
function gcc.getsystemversionflags(cfg)
local flags = {}
if cfg.system == p.MACOSX then
local minVersion = p.project.systemversion(cfg)
if minVersion ~= nil then
table.insert (flags, "-mmacosx-version-min=" .. minVersion)
end
end
return flags
end
--
-- Returns list of C++ compiler flags for a configuration.
--
gcc.cxxflags = {
exceptionhandling = {
Off = "-fno-exceptions"
},
flags = {
NoBufferSecurityCheck = "-fno-stack-protector",
},
cppdialect = {
["C++98"] = "-std=c++98",
["C++0x"] = "-std=c++0x",
["C++11"] = "-std=c++11",
["C++1y"] = "-std=c++1y",
["C++14"] = "-std=c++14",
["C++1z"] = "-std=c++1z",
["C++17"] = "-std=c++17",
["C++2a"] = "-std=c++2a",
["C++20"] = "-std=c++20",
["gnu++98"] = "-std=gnu++98",
["gnu++0x"] = "-std=gnu++0x",
["gnu++11"] = "-std=gnu++11",
["gnu++1y"] = "-std=gnu++1y",
["gnu++14"] = "-std=gnu++14",
["gnu++1z"] = "-std=gnu++1z",
["gnu++17"] = "-std=gnu++17",
["gnu++2a"] = "-std=gnu++2a",
["gnu++20"] = "-std=gnu++20",
["C++latest"] = "-std=c++20",
},
rtti = {
Off = "-fno-rtti"
},
visibility = {
Default = "-fvisibility=default",
Hidden = "-fvisibility=hidden",
Internal = "-fvisibility=internal",
Protected = "-fvisibility=protected",
},
inlinesvisibility = {
Hidden = "-fvisibility-inlines-hidden"
}
}
function gcc.getcxxflags(cfg)
local shared_flags = config.mapFlags(cfg, gcc.shared)
local cxxflags = config.mapFlags(cfg, gcc.cxxflags)
local flags = table.join(shared_flags, cxxflags)
flags = table.join(flags, gcc.getwarnings(cfg), gcc.getsystemversionflags(cfg))
return flags
end
--
-- Decorate defines for the GCC command line.
--
function gcc.getdefines(defines)
local result = {}
for _, define in ipairs(defines) do
table.insert(result, '-D' .. p.esc(define))
end
return result
end
function gcc.getundefines(undefines)
local result = {}
for _, undefine in ipairs(undefines) do
table.insert(result, '-U' .. p.esc(undefine))
end
return result
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function gcc.getforceincludes(cfg)
local result = {}
table.foreachi(cfg.forceincludes, function(value)
local fn = project.getrelative(cfg.project, value)
table.insert(result, string.format('-include %s', p.quoted(fn)))
end)
return result
end
--
-- Decorate include file search paths for the GCC command line.
--
function gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs)
local result = {}
for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-I' .. p.quoted(dir))
end
if table.contains(os.getSystemTags(cfg.system), "darwin") then
for _, dir in ipairs(frameworkdirs or {}) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-F' .. p.quoted(dir))
end
end
for _, dir in ipairs(sysdirs or {}) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-isystem ' .. p.quoted(dir))
end
return result
end
-- relative pch file path if any
function gcc.getpch(cfg)
-- If there is no header, or if PCH has been disabled, I can early out
if not cfg.pchheader or cfg.flags.NoPCH then
return nil
end
-- Visual Studio requires the PCH header to be specified in the same way
-- it appears in the #include statements used in the source code; the PCH
-- source actual handles the compilation of the header. GCC compiles the
-- header file directly, and needs the file's actual file system path in
-- order to locate it.
-- To maximize the compatibility between the two approaches, see if I can
-- locate the specified PCH header on one of the include file search paths
-- and, if so, adjust the path automatically so the user doesn't have
-- add a conditional configuration to the project script.
local pch = cfg.pchheader
local found = false
-- test locally in the project folder first (this is the most likely location)
local testname = path.join(cfg.project.basedir, pch)
if os.isfile(testname) then
return project.getrelative(cfg.project, testname)
else
-- else scan in all include dirs.
for _, incdir in ipairs(cfg.includedirs) do
testname = path.join(incdir, pch)
if os.isfile(testname) then
return project.getrelative(cfg.project, testname)
end
end
end
return project.getrelative(cfg.project, path.getabsolute(pch))
end
--
-- Return a list of decorated rpaths
--
-- @param cfg
-- The configuration to query.
-- @param dirs
-- List of absolute paths
-- @param mode
-- Output mode
-- - "linker" (default) Linker rpath instructions
-- - "path" List of path relative to configuration target directory
--
function gcc.getrunpathdirs(cfg, dirs, mode)
local result = {}
mode = iif (mode == nil, "linker", mode)
if not (table.contains(os.getSystemTags(cfg.system), "darwin")
or (cfg.system == p.LINUX)) then
return result
end
for _, fullpath in ipairs(dirs) do
local rpath = path.getrelative(cfg.buildtarget.directory, fullpath)
if table.contains(os.getSystemTags(cfg.system), "darwin") then
rpath = "@loader_path/" .. rpath
elseif (cfg.system == p.LINUX) then
rpath = iif(rpath == ".", "", "/" .. rpath)
rpath = "$$ORIGIN" .. rpath
end
if mode == "linker" then
rpath = "-Wl,-rpath,'" .. rpath .. "'"
end
table.insert(result, rpath)
end
return result
end
--
-- get the right output flag.
--
function gcc.getsharedlibarg(cfg)
if table.contains(os.getSystemTags(cfg.system), "darwin") then
if cfg.sharedlibtype == "OSXBundle" then
return "-bundle"
elseif cfg.sharedlibtype == "XCTest" then
return "-bundle"
elseif cfg.sharedlibtype == "OSXFramework" then
return "-framework"
else
return "-dynamiclib"
end
else
return "-shared"
end
end
--
-- Return a list of LDFLAGS for a specific configuration.
--
function gcc.ldsymbols(cfg)
-- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html
return iif(table.contains(os.getSystemTags(cfg.system), "darwin"), "-Wl,-x", "-s")
end
gcc.ldflags = {
architecture = {
x86 = "-m32",
x86_64 = "-m64",
},
flags = {
LinkTimeOptimization = "-flto",
},
kind = {
SharedLib = function(cfg)
local r = { gcc.getsharedlibarg(cfg) }
if cfg.system == p.WINDOWS and not cfg.flags.NoImportLib then
table.insert(r, '-Wl,--out-implib="' .. cfg.linktarget.relpath .. '"')
elseif cfg.system == p.LINUX then
table.insert(r, '-Wl,-soname=' .. p.quoted(cfg.linktarget.name))
elseif table.contains(os.getSystemTags(cfg.system), "darwin") then
table.insert(r, '-Wl,-install_name,' .. p.quoted('@rpath/' .. cfg.linktarget.name))
end
return r
end,
WindowedApp = function(cfg)
if cfg.system == p.WINDOWS then return "-mwindows" end
end,
},
system = {
wii = "$(MACHDEP)",
},
symbols = {
Off = gcc.ldsymbols,
Default = gcc.ldsymbols,
}
}
function gcc.getldflags(cfg)
local flags = config.mapFlags(cfg, gcc.ldflags)
return flags
end
--
-- Return a list of decorated additional libraries directories.
--
gcc.libraryDirectories = {
architecture = {
x86 = function (cfg)
local r = {}
if not table.contains(os.getSystemTags(cfg.system), "darwin") then
table.insert (r, "-L/usr/lib32")
end
return r
end,
x86_64 = function (cfg)
local r = {}
if not table.contains(os.getSystemTags(cfg.system), "darwin") then
table.insert (r, "-L/usr/lib64")
end
return r
end,
},
system = {
wii = "-L$(LIBOGC_LIB)",
}
}
function gcc.getLibraryDirectories(cfg)
local flags = {}
-- Scan the list of linked libraries. If any are referenced with
-- paths, add those to the list of library search paths. The call
-- config.getlinks() all includes cfg.libdirs.
for _, dir in ipairs(config.getlinks(cfg, "system", "directory")) do
table.insert(flags, '-L' .. p.quoted(dir))
end
if table.contains(os.getSystemTags(cfg.system), "darwin") then
for _, dir in ipairs(cfg.frameworkdirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(flags, '-F' .. p.quoted(dir))
end
end
if cfg.flags.RelativeLinks then
for _, dir in ipairs(config.getlinks(cfg, "siblings", "directory")) do
local libFlag = "-L" .. p.project.getrelative(cfg.project, dir)
if not table.contains(flags, libFlag) then
table.insert(flags, libFlag)
end
end
end
for _, dir in ipairs(cfg.syslibdirs) do
table.insert(flags, '-L' .. p.quoted(dir))
end
local gccFlags = config.mapFlags(cfg, gcc.libraryDirectories)
flags = table.join(flags, gccFlags)
return flags
end
--
-- Return the list of libraries to link, decorated with flags as needed.
--
function gcc.getlinks(cfg, systemonly, nogroups)
local result = {}
if not systemonly then
if cfg.flags.RelativeLinks then
local libFiles = config.getlinks(cfg, "siblings", "basename")
for _, link in ipairs(libFiles) do
if string.startswith(link, "lib") then
link = link:sub(4)
end
table.insert(result, "-l" .. link)
end
else
-- Don't use the -l form for sibling libraries, since they may have
-- custom prefixes or extensions that will confuse the linker. Instead
-- just list out the full relative path to the library.
result = config.getlinks(cfg, "siblings", "fullpath")
end
end
-- The "-l" flag is fine for system libraries
local links = config.getlinks(cfg, "system", "fullpath")
local static_syslibs = {"-Wl,-Bstatic"}
local shared_syslibs = {}
for _, link in ipairs(links) do
if path.isframework(link) then
table.insert(result, "-framework")
table.insert(result, path.getbasename(link))
elseif path.isobjectfile(link) then
table.insert(result, link)
else
local endswith = function(s, ptrn)
return ptrn == string.sub(s, -string.len(ptrn))
end
local name = path.getname(link)
-- Check whether link mode decorator is present
if endswith(name, ":static") then
name = string.sub(name, 0, -8)
table.insert(static_syslibs, "-l" .. name)
elseif endswith(name, ":shared") then
name = string.sub(name, 0, -8)
table.insert(shared_syslibs, "-l" .. name)
else
table.insert(shared_syslibs, "-l" .. name)
end
end
end
local move = function(a1, a2)
local t = #a2
for i = 1, #a1 do a2[t + i] = a1[i] end
end
if #static_syslibs > 1 then
table.insert(static_syslibs, "-Wl,-Bdynamic")
move(static_syslibs, result)
end
move(shared_syslibs, result)
if not nogroups and #result > 1 and (cfg.linkgroups == p.ON) then
table.insert(result, 1, "-Wl,--start-group")
table.insert(result, "-Wl,--end-group")
end
return result
end
--
-- Returns makefile-specific configuration rules.
--
gcc.makesettings = {
system = {
wii = [[
ifeq ($(strip $(DEVKITPPC)),)
$(error "DEVKITPPC environment variable is not set")'
endif
include $(DEVKITPPC)/wii_rules']]
}
}
function gcc.getmakesettings(cfg)
local settings = config.mapFlags(cfg, gcc.makesettings)
return table.concat(settings)
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
gcc.tools = {
cc = "gcc",
cxx = "g++",
ar = "ar",
rc = "windres"
}
function gcc.gettoolname(cfg, tool)
if (cfg.gccprefix and gcc.tools[tool]) or tool == "rc" then
return (cfg.gccprefix or "") .. gcc.tools[tool]
end
return nil
end

View File

@@ -0,0 +1,8 @@
--
-- mingw.lua
-- MinGW toolset adapter for Premake
-- Copyright (c) 2018 Jason Perkins and the Premake project
--
local p = premake
p.tools.mingw = p.tools.gcc

View File

@@ -0,0 +1,400 @@
---
-- msc.lua
-- Interface for the MS C/C++ compiler.
-- Author Jason Perkins
-- Modified by Manu Evans
-- Copyright (c) 2009-2015 Jason Perkins and the Premake project
---
local p = premake
p.tools.msc = {}
local msc = p.tools.msc
local project = p.project
local config = p.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.
--
local function getRuntimeFlag(cfg, isstatic)
local rt = cfg.runtime
local flag = iif(isstatic, "/MT", "/MD")
if (rt == "Debug") or (rt == nil and config.isDebugBuild(cfg)) then
flag = flag .. "d"
end
return flag
end
msc.shared = {
clr = {
On = "/clr",
Unsafe = "/clr",
Pure = "/clr:pure",
Safe = "/clr:safe",
},
flags = {
FatalCompileWarnings = "/WX",
LinkTimeOptimization = "/GL",
MultiProcessorCompile = "/MP",
NoMinimalRebuild = "/Gm-",
OmitDefaultLibrary = "/Zl"
},
floatingpoint = {
Fast = "/fp:fast",
Strict = "/fp:strict",
},
floatingpointexceptions = {
On = "/fp:except",
Off = "/fp:except-",
},
functionlevellinking = {
On = "/Gy",
Off = "/Gy-",
},
callingconvention = {
Cdecl = "/Gd",
FastCall = "/Gr",
StdCall = "/Gz",
VectorCall = "/Gv",
},
intrinsics = {
On = "/Oi",
},
optimize = {
Off = "/Od",
On = "/Ot",
Debug = "/Od",
Full = "/Ox",
Size = "/O1",
Speed = "/O2",
},
vectorextensions = {
AVX = "/arch:AVX",
AVX2 = "/arch:AVX2",
SSE = "/arch:SSE",
SSE2 = "/arch:SSE2",
SSE3 = "/arch:SSE2",
SSSE3 = "/arch:SSE2",
["SSE4.1"] = "/arch:SSE2",
["SSE4.2"] = "/arch:SSE2",
},
warnings = {
Off = "/W0",
High = "/W4",
Extra = "/W4",
Everything = "/Wall",
},
staticruntime = {
-- this option must always be emit (does it??)
_ = function(cfg) return getRuntimeFlag(cfg, false) end,
-- runtime defaults to dynamic in VS
Default = function(cfg) return getRuntimeFlag(cfg, false) end,
On = function(cfg) return getRuntimeFlag(cfg, true) end,
Off = function(cfg) return getRuntimeFlag(cfg, false) end,
},
stringpooling = {
On = "/GF",
Off = "/GF-",
},
symbols = {
On = "/Z7"
},
unsignedchar = {
On = "/J",
},
omitframepointer = {
On = "/Oy"
},
justmycode = {
On = "/JMC",
Off = "/JMC-"
},
openmp = {
On = "/openmp",
Off = "/openmp-"
}
}
msc.cflags = {
}
function msc.getcflags(cfg)
local shared = config.mapFlags(cfg, msc.shared)
local cflags = config.mapFlags(cfg, msc.cflags)
local flags = table.join(shared, cflags, msc.getwarnings(cfg))
return flags
end
--
-- Returns list of C++ compiler flags for a configuration.
--
msc.cxxflags = {
exceptionhandling = {
Default = "/EHsc",
On = "/EHsc",
SEH = "/EHa",
},
rtti = {
Off = "/GR-"
}
}
function msc.getcxxflags(cfg)
local shared = config.mapFlags(cfg, msc.shared)
local cxxflags = config.mapFlags(cfg, msc.cxxflags)
local flags = table.join(shared, cxxflags, msc.getwarnings(cfg))
return flags
end
--
-- Decorate defines for the MSVC command line.
--
msc.defines = {
characterset = {
Default = { '/D"_UNICODE"', '/D"UNICODE"' },
MBCS = '/D"_MBCS"',
Unicode = { '/D"_UNICODE"', '/D"UNICODE"' },
ASCII = { },
}
}
function msc.getdefines(defines, cfg)
local result
-- HACK: I need the cfg to tell what the character set defines should be. But
-- there's lots of legacy code using the old getdefines(defines) signature.
-- For now, detect one or two arguments and apply the right behavior; will fix
-- it properly when the I roll out the adapter overhaul
if cfg and defines then
result = config.mapFlags(cfg, msc.defines)
else
result = {}
end
for _, define in ipairs(defines) do
table.insert(result, '/D"' .. define .. '"')
end
if cfg and cfg.exceptionhandling == p.OFF then
table.insert(result, "/D_HAS_EXCEPTIONS=0")
end
return result
end
function msc.getundefines(undefines)
local result = {}
for _, undefine in ipairs(undefines) do
table.insert(result, '/U"' .. undefine .. '"')
end
return result
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function msc.getforceincludes(cfg)
local result = {}
table.foreachi(cfg.forceincludes, function(value)
local fn = project.getrelative(cfg.project, value)
table.insert(result, "/FI" .. p.quoted(fn))
end)
return result
end
function msc.getrunpathdirs()
return {}
end
--
-- Decorate include file search paths for the MSVC command line.
--
function msc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs)
local result = {}
dirs = table.join(dirs, sysdirs)
for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-I' .. p.quoted(dir))
end
return result
end
--
-- Return a list of linker flags for a specific configuration.
--
msc.linkerFlags = {
flags = {
FatalLinkWarnings = "/WX",
LinkTimeOptimization = "/LTCG",
NoIncrementalLink = "/INCREMENTAL:NO",
NoManifest = "/MANIFEST:NO",
OmitDefaultLibrary = "/NODEFAULTLIB",
},
kind = {
SharedLib = "/DLL",
WindowedApp = "/SUBSYSTEM:WINDOWS"
},
symbols = {
On = "/DEBUG"
}
}
msc.librarianFlags = {
flags = {
FatalLinkWarnings = "/WX",
}
}
function msc.getldflags(cfg)
local map = iif(cfg.kind ~= p.STATICLIB, msc.linkerFlags, msc.librarianFlags)
local flags = config.mapFlags(cfg, map)
table.insert(flags, 1, "/NOLOGO")
-- Ignore default libraries
for i, ignore in ipairs(cfg.ignoredefaultlibraries) do
-- Add extension if required
if not msc.getLibraryExtensions()[ignore:match("[^.]+$")] then
ignore = path.appendextension(ignore, ".lib")
end
table.insert(flags, '/NODEFAULTLIB:' .. ignore)
end
return flags
end
--
-- Build a list of additional library directories for a particular
-- project configuration, decorated for the tool command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of decorated additional library directories.
--
function msc.getLibraryDirectories(cfg)
local flags = {}
local dirs = table.join(cfg.libdirs, cfg.syslibdirs)
for i, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(flags, '/LIBPATH:"' .. dir .. '"')
end
return flags
end
--
-- Return a list of valid library extensions
--
function msc.getLibraryExtensions()
return {
["lib"] = true,
["obj"] = true,
}
end
--
-- Return the list of libraries to link, decorated with flags as needed.
--
function msc.getlinks(cfg, systemonly, nogroups)
local links = {}
-- If we need sibling projects to be listed explicitly, grab them first
if not systemonly then
links = config.getlinks(cfg, "siblings", "fullpath")
end
-- Then the system libraries, which come undecorated
local system = config.getlinks(cfg, "system", "fullpath")
for i = 1, #system do
-- Add extension if required
local link = system[i]
if not p.tools.msc.getLibraryExtensions()[link:match("[^.]+$")] then
link = path.appendextension(link, ".lib")
end
table.insert(links, link)
end
return links
end
--
-- Returns makefile-specific configuration rules.
--
function msc.getmakesettings(cfg)
return nil
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
function msc.gettoolname(cfg, tool)
return nil
end
function msc.getwarnings(cfg)
local result = {}
for _, enable in ipairs(cfg.enablewarnings) do
table.insert(result, '/w1"' .. enable .. '"')
end
for _, disable in ipairs(cfg.disablewarnings) do
table.insert(result, '/wd"' .. disable .. '"')
end
for _, fatal in ipairs(cfg.fatalwarnings) do
table.insert(result, '/we"' .. fatal .. '"')
end
return result
end

View File

@@ -0,0 +1,144 @@
--
-- snc.lua
-- Provides Sony SNC-specific configuration strings.
-- Copyright (c) 2010-2016 Jason Perkins and the Premake project
--
local p = premake
p.tools.snc = {}
local snc = p.tools.snc
local gcc = p.tools.gcc
--
-- Retrieve the CFLAGS for a specific configuration.
--
snc.shared = {
flags = {
FatalCompileWarnings = "-Xquit=2",
},
optimize = {
Off = "-O0",
On = "-O1",
Debug = "-Od",
Full = "-O3",
Size = "-Os",
Speed = "-O2",
},
warnings = {
Extra = "-Xdiag=2",
}
}
snc.cflags = {
}
function snc.getcflags(cfg)
local shared = p.config.mapFlags(cfg, snc.shared)
local cflags = p.config.mapFlags(cfg, snc.cflags)
local flags = table.join(shared, cflags, snc.getwarnings(cfg))
return flags
end
--
-- Retrieve the CXXFLAGS for a specific configuration.
--
snc.cxxflags = {
exceptionhandling = {
Default = "-Xc+=exceptions",
On = "-Xc+=exceptions",
SEH = "-Xc-=exceptions",
},
rtti = {
Default = "-Xc+=rtti",
On = "-Xc+=rtti",
SEH = "-Xc-=rtti",
}
}
function snc.getcxxflags(cfg)
local shared = config.mapFlags(cfg, snc.shared)
local cxxflags = config.mapFlags(cfg, snc.cxxflags)
local flags = table.join(shared, cxxflags, snc.getwarnings(cfg))
return flags
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function snc.getforceincludes(cfg)
-- Just pass through to GCC for now
local flags = gcc.getforceincludes(cfg)
return flags
end
--
-- Retrieve the LDFLAGS for a specific configuration.
--
function snc.getldflags(cfg)
local flags = { }
if not (cfg.symbols == p.ON) then
table.insert(flags, "-s")
end
return flags
end
--
-- These are the same as GCC
--
snc.getcppflags = gcc.getcppflags
snc.getdefines = gcc.getdefines
snc.getincludedirs = gcc.getincludedirs
snc.getrunpathdirs = gcc.getrunpathdirs
snc.getLibraryDirectories = gcc.getLibraryDirectories
snc.getlinks = gcc.getlinks
--
-- Returns makefile-specific configuration rules.
--
function snc.getmakesettings(cfg)
return nil
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
snc.tools = {
}
function snc.gettoolname(cfg, tool)
local names = snc.tools[cfg.architecture] or snc.tools[cfg.system] or {}
return names[tool]
end