Ported GCC and SNC linker flag generation to new tool APIs
This commit is contained in:
parent
9377e7b415
commit
5761e86cb6
@ -424,7 +424,7 @@
|
||||
end
|
||||
|
||||
if #cfg.links > 0 then
|
||||
_x(4,'AdditionalDependencies="%s"', table.concat(config.getlinks(cfg, "all", "fullpath"), " "))
|
||||
_x(4,'AdditionalDependencies="%s"', table.concat(toolset.getlinks(cfg), " "))
|
||||
end
|
||||
|
||||
_x(4,'OutputFile="$(OutDir)\\%s"', config.gettargetinfo(cfg).name)
|
||||
@ -674,7 +674,7 @@
|
||||
--
|
||||
|
||||
vc200x.toolsets = {
|
||||
ps3 = premake.snc
|
||||
ps3 = premake.tools.snc
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,8 +29,6 @@
|
||||
local basedir = project.getlocation(cfg.project)
|
||||
|
||||
local directory = cfg[field.."dir"] or cfg.targetdir or basedir
|
||||
directory = project.getrelative(cfg.project, directory)
|
||||
|
||||
local basename = cfg[field.."name"] or cfg.targetname or cfg.project.name
|
||||
|
||||
local bundlename = ""
|
||||
@ -44,8 +42,7 @@
|
||||
-- Mac .app requires more logic than I can bundle up in a table right now
|
||||
if cfg.system == premake.MACOSX and kind == premake.WINDOWEDAPP then
|
||||
bundlename = basename .. ".app"
|
||||
bundlepath = path.join(directory, bundlename)
|
||||
bundlepath = path.join(bundlepath, "Contents/MacOS")
|
||||
bundlepath = path.join(bundlename, "Contents/MacOS")
|
||||
end
|
||||
|
||||
prefix = cfg[field.."prefix"] or cfg.targetprefix or prefix
|
||||
@ -53,13 +50,14 @@
|
||||
extension = cfg[field.."extension"] or cfg.targetextension or extension
|
||||
|
||||
local info = {}
|
||||
info.directory = directory
|
||||
info.directory = project.getrelative(cfg.project, directory)
|
||||
info.basename = prefix .. basename .. suffix
|
||||
info.name = info.basename .. extension
|
||||
info.extension = extension
|
||||
info.abspath = path.join(directory, info.name)
|
||||
info.fullpath = path.join(info.directory, info.name)
|
||||
info.bundlename = bundlename
|
||||
info.bundlepath = bundlepath
|
||||
info.bundlepath = path.join(info.directory, bundlepath)
|
||||
info.prefix = prefix
|
||||
info.suffix = suffix
|
||||
return info
|
||||
@ -103,7 +101,8 @@
|
||||
-- extension - the file extension
|
||||
-- prefix - the file name prefix
|
||||
-- suffix - the file name suffix
|
||||
-- fullpath - directory, name, and extension
|
||||
-- fullpath - directory, name, and extension relative to project
|
||||
-- abspath - absolute directory, name, and extension
|
||||
--
|
||||
|
||||
function config.getlinkinfo(cfg)
|
||||
@ -125,7 +124,7 @@
|
||||
local info = buildtargetinfo(cfg, kind, field)
|
||||
|
||||
-- cache the results for future calls
|
||||
cfg.linktinfo = info
|
||||
cfg.linkinfo = info
|
||||
return info
|
||||
end
|
||||
|
||||
@ -258,7 +257,8 @@
|
||||
-- extension - the file extension
|
||||
-- prefix - the file name prefix
|
||||
-- suffix - the file name suffix
|
||||
-- fullpath - directory, name, and extension
|
||||
-- fullpath - directory, name, and extension, relative to project
|
||||
-- abspath - absolute directory, name, and extension
|
||||
-- bundlepath - the relative path and file name of the bundle
|
||||
--
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
premake.tools.gcc = {}
|
||||
local gcc = premake.tools.gcc
|
||||
local project = premake5.project
|
||||
local config = premake5.config
|
||||
|
||||
|
||||
@ -130,6 +131,39 @@
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Return the list of libraries to link, decorated with flags as needed.
|
||||
--
|
||||
|
||||
function gcc.getlinks(cfg)
|
||||
local result = {}
|
||||
|
||||
local links = config.getlinks(cfg, "siblings", "object")
|
||||
for _, link in ipairs(links) do
|
||||
if link.kind == premake.STATICLIB then
|
||||
-- Don't use "-l" flag when linking static libraries; instead use
|
||||
-- path/libname.a to avoid linking a shared library of the same
|
||||
-- name if one is present
|
||||
local linkinfo = config.getlinkinfo(link)
|
||||
table.insert(result, project.getrelative(cfg.project, linkinfo.abspath))
|
||||
else
|
||||
table.insert(result, "-l" .. link.basename)
|
||||
end
|
||||
end
|
||||
|
||||
-- The "-l" flag is fine for system libraries
|
||||
links = config.getlinks(cfg, "system", "basename")
|
||||
for _, link in ipairs(links) do
|
||||
if path.getextension(link) == ".framework" then
|
||||
table.insert(result, "-framework " .. path.getbasename(link))
|
||||
else
|
||||
table.insert(result, "-l" .. link)
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Everything below this point is a candidate for deprecation
|
||||
|
@ -80,6 +80,20 @@
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Return the list of libraries to link, formatted for the linker command line.
|
||||
--
|
||||
|
||||
function snc.getlinks(cfg)
|
||||
local result = {}
|
||||
local links = config.getlinks(cfg, "all", "basename")
|
||||
for _, link in ipairs(links) do
|
||||
table.insert(result, "-l" .. link)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Everything below this point is a candidate for deprecation
|
||||
|
@ -37,6 +37,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
AdditionalOptions="-Xc+=exceptions -Xc+=rtti"
|
||||
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"
|
||||
@ -56,6 +57,7 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="0"
|
||||
AdditionalOptions="-Xc+=exceptions -Xc+=rtti"
|
||||
AdditionalIncludeDirectories="..\include;include"
|
||||
]]
|
||||
end
|
||||
|
@ -64,3 +64,20 @@
|
||||
/>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Verify the handling of system libraries.
|
||||
--
|
||||
|
||||
function suite.additionalDependencies_onSystemLibs()
|
||||
kind "ConsoleApp"
|
||||
links { "fs_stub", "net_stub" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalOptions="-s"
|
||||
AdditionalDependencies="-lfs_stub -lnet_stub"
|
||||
]]
|
||||
end
|
||||
|
@ -175,3 +175,36 @@
|
||||
test.isequal({ "-fPIC" }, gcc.getcflags(cfg))
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Check the formatting of linked system libraries.
|
||||
--
|
||||
|
||||
function suite.links_onSystemLibs()
|
||||
links { "fs_stub", "net_stub" }
|
||||
prepare()
|
||||
test.isequal({ "-lfs_stub", "-lnet_stub" }, gcc.getlinks(cfg))
|
||||
end
|
||||
|
||||
function suite.links_onFramework()
|
||||
links { "Cocoa.framework" }
|
||||
prepare()
|
||||
test.isequal({ "-framework Cocoa" }, gcc.getlinks(cfg))
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- When linking to a static sibling library, the relative path to the library
|
||||
-- should be used instead of the "-l" flag. This prevents linking against a
|
||||
-- shared library of the same name, should one be present.
|
||||
--
|
||||
|
||||
function suite.links_onStaticSiblingLibrary()
|
||||
links { "MyProject2" }
|
||||
test.createproject(sln)
|
||||
kind "StaticLib"
|
||||
location "MyProject2"
|
||||
targetdir "lib"
|
||||
prepare()
|
||||
test.isequal({ "lib/libMyProject2.a" }, gcc.getlinks(cfg))
|
||||
end
|
||||
|
@ -65,3 +65,15 @@
|
||||
prepare()
|
||||
test.isequal({ "-s" }, snc.getldflags(cfg))
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Check the formatting of linked libraries.
|
||||
--
|
||||
|
||||
function suite.links_onSystemLibs()
|
||||
links { "fs_stub", "net_stub" }
|
||||
prepare()
|
||||
test.isequal({ "-lfs_stub", "-lnet_stub" }, snc.getlinks(cfg))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user