Only add extension to libraries if it doesn't already exist; handle ending quote, if present, when appending extension

This commit is contained in:
Jason Perkins 2012-03-22 19:30:34 -04:00
parent cc0c541843
commit f8fa020d64
3 changed files with 50 additions and 4 deletions

View File

@ -5,6 +5,24 @@
--
--
-- Appends a file extension to the path. Verifies that the extension
-- isn't already present, and adjusts quotes as necessary.
--
function path.appendextension(p, ext)
if not p:endswith(ext) then
-- if the path ends with a quote, move it to the end of the string
if p:endswith('"') then
p = p:sub(1, -2) .. ext .. '"'
else
p = p .. ext
end
end
return p
end
--
-- Get the absolute file path from a relative path. The requested
-- file path doesn't actually need to exist.

View File

@ -233,9 +233,9 @@
item = link
if cfg.system == premake.WINDOWS then
if premake.iscppproject(cfg.project) then
item = item .. ".lib"
item = path.appendextension(item, ".lib")
elseif premake.isdotnetproject(cfg.project) then
item = item .. ".dll"
item = path.appendextension(item, ".dll")
end
end
if item:find("/", nil, true) then

View File

@ -46,7 +46,7 @@
location "build"
links { "../libs/z" }
local r = prepare("all", "fullpath")
test.isequal("../../libs/z", r[1])
test.isequal({ "../../libs/z" }, r)
end
@ -58,5 +58,33 @@
system "windows"
links { "user32" }
local r = prepare("all", "fullpath")
test.isequal("user32.lib", r[1])
test.isequal({ "user32.lib" }, r)
end
function suite.libAdded_onWindowsSystemLibs()
system "windows"
links { "user32.lib" }
local r = prepare("all", "fullpath")
test.isequal({ "user32.lib" }, r)
end
--
-- Check handling of shell variables in library paths.
--
function suite.variableMaintained_onLeadingVariable()
system "windows"
location "build"
links { "$(SN_PS3_PATH)/sdk/lib/PS3TMAPI" }
local r = prepare("all", "fullpath")
test.isequal({ "$(SN_PS3_PATH)/sdk/lib/PS3TMAPI.lib" }, r)
end
function suite.variableMaintained_onQuotedVariable()
system "windows"
location "build"
links { '"$(SN_PS3_PATH)/sdk/lib/PS3TMAPI"' }
local r = prepare("all", "fullpath")
test.isequal({ '"$(SN_PS3_PATH)/sdk/lib/PS3TMAPI.lib"' }, r)
end