Remove ".lib" extension from system library links in generated makefiles on Windows

This commit is contained in:
Jason Perkins 2015-02-14 14:56:02 -05:00
parent 494196598e
commit f5abdb9d69
7 changed files with 50 additions and 73 deletions

View File

@ -314,6 +314,39 @@
end
---
-- Assemble the list of links just the way Visual Studio likes them.
--
-- @param cfg
-- The active configuration.
-- @param explicit
-- True to explicitly include sibling project libraries; if false Visual
-- Studio's default implicit linking will be used.
-- @return
-- The list of linked libraries, ready to be used in Visual Studio's
-- AdditionalDependencies element.
---
function vstudio.getLinks(cfg, explicit)
local links = {}
-- If we need sibling projects to be listed explicitly, grab them first
if explicit 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
table.insert(links, path.appendextension(system[i], ".lib"))
end
return links
end
--
-- Return true if the configuration kind is one of "Makefile" or "None". The
-- latter is generated like a Makefile project and excluded from the solution.

View File

@ -294,8 +294,8 @@
config.getlinks(cfg, "system", function(original, decorated)
if decorated:find("/", nil, true) then
_x(2,'<Reference Include="%s">', path.getbasename(decorated))
_x(3,'<HintPath>%s</HintPath>', path.translate(decorated))
_x(2,'<Reference Include="%s">', path.getname(decorated))
_x(3,'<HintPath>%s</HintPath>', path.appendextension(path.translate(decorated), ".dll"))
if not config.isCopyLocal(prj, original, true) then
_p(3,"<Private>False</Private>")
@ -303,7 +303,7 @@
_p(2,'</Reference>')
else
_x(2,'<Reference Include="%s" />', path.getbasename(decorated))
_x(2,'<Reference Include="%s" />', path.getname(decorated))
end
end)

View File

@ -789,8 +789,7 @@
local links
if not toolset then
local scope = iif(ex, "all", "system")
links = config.getlinks(cfg, scope, "fullpath")
links = vstudio.getLinks(cfg, ex)
for i, link in ipairs(links) do
if link:find(" ", 1, true) then
link = '"' .. link .. '"'

View File

@ -876,8 +876,7 @@
if toolset then
links = toolset.getlinks(cfg, not explicit)
else
local scope = iif(explicit, "all", "system")
links = config.getlinks(cfg, scope, "fullpath")
links = vstudio.getLinks(cfg, explicit)
end
if #links > 0 then

View File

@ -140,55 +140,6 @@
--
-- Given a raw link target filename, properly format it for the given
-- configuration. Adds file decorations, and handles relative path
-- conversions.
--
-- @param cfg
-- The configuration that is linking.
-- @param target
-- The file name of the library being linked.
-- @param linkage
-- Optional. For languages or environments that support different kinds of
-- linking (i.e. Managed/CLR C++, which can link both managed and unmanaged
-- libs), which one to return. One of "unmanaged", "managed". If not
-- specified, the default for the configuration will be used.
-- @return
-- The decorated library file name.
--
function config.decoratelink(cfg, target, linkage)
-- Determine if a file extension is required, and append if so
local ext
if cfg.system == premake.WINDOWS then
if project.isdotnet(cfg.project) or linkage == "managed" then
ext = ".dll"
elseif project.iscpp(cfg.project) then
ext = ".lib"
end
elseif cfg.system == premake.XBOX360 then
if project.iscpp(cfg.project) then
ext = ".lib"
end
end
target = path.appendextension(target, ext)
-- if the target is listed via an explicit path (i.e. not a
-- system library or assembly), make it project-relative
if target:find("/", nil, true) then
target = project.getrelative(cfg.project, target)
end
return target
end
--
-- Check a configuration for a source code file with the specified
-- extension. Used for locating special files, such as Windows
@ -318,7 +269,12 @@
-- link managed .DLLs into unmanaged code, etc.
if config.canLink(cfg, link, linkage) then
item = config.decoratelink(cfg, link, linkage)
-- if the target is listed via an explicit path (i.e. not a
-- system library or assembly), make it project-relative
item = link
if item:find("/", nil, true) then
item = project.getrelative(cfg.project, item)
end
end
end

View File

@ -44,20 +44,10 @@
location "build"
links { "../libs/z" }
local r = prepare("all", "fullpath")
test.isequal({ "../../libs/z.lib" }, r)
test.isequal({ "../../libs/z" }, r)
end
--
-- On Windows, system libraries get the ".lib" file extensions.
--
function suite.libAdded_onWindowsSystemLibs()
links { "user32" }
local r = prepare("all", "fullpath")
test.isequal({ "user32.lib" }, r)
end
--
-- Handle the case where the library extension has been explicitly
@ -81,7 +71,7 @@
location "build"
links { "$(SN_PS3_PATH)/sdk/lib/PS3TMAPI" }
local r = prepare("all", "fullpath")
test.isequal({ "$(SN_PS3_PATH)/sdk/lib/PS3TMAPI.lib" }, r)
test.isequal({ "$(SN_PS3_PATH)/sdk/lib/PS3TMAPI" }, r)
end
function suite.variableMaintained_onQuotedVariable()
@ -114,7 +104,7 @@
clr "On"
links { "user32", "System.dll" }
local r = prepare("all", "fullpath")
test.isequal({ "user32.lib" }, r)
test.isequal({ "user32" }, r)
end

View File

@ -283,10 +283,10 @@
end
function suite.links_onSystemLibs_onWindows()
_OS = "windows"
links { "user32", "ole32" }
system "windows"
links { "ole32" }
prepare()
test.contains({ "-luser32", "-lole32" }, gcc.getlinks(cfg))
test.contains({ "-lole32" }, gcc.getlinks(cfg))
end