implibprefix and implibextension
Hey,
I'm having issues attempting to use implibprefix and/or implibextension - which appear to have no effect.
My links are still having ".lib" appending, and no prefix. Is there something additional that I may need to get these options to work?
I just added some tests local and it seems to work. Can you show a premake file where it fails?
Hi @WorldofBay Could you post an example test? If I search the repo for 'implibextension' it seems there is no place it's used at all: https://github.com/premake/premake-core/search?q=implibextension&unscoped_q=implibextension
My solution to this was to override msc.getlinks and m.ignoreDefaultLibraries to add the implibprefix + implibextension as expected. The way they are currently written doesn't care about implibextension at all, and will just append .lib if there is no existing extension on the link.
Edit: Like this.
if not p.tools.msc.getLibraryExtensions()[ignored[i]:match("[^.]+$")] then
ignored[i] = path.appendextension(ignored[i], cfg.implibextension or ".lib")
end
if cfg.implibprefix then
ignored[i] = cfg.implibprefix .. ignored[i]
end
for an example of it failing:
filter { "system:ORBIS" }
implibextension (".a")
implibprefix "lib"
filter {}
--[[ Workspace setup ]]
project "TestProject"
links {
"SceSomeSystemLibrary"
}
It would, before the change, try to link SceSomeSystemLibrary.lib instead of libSceSomeSystemLibrary.a
In tests/config/test_linkinfo.lua there is a test at the bottom of the file:
--
-- The import library extension should not change if the a
-- custom target extension is set.
--
function suite.impLibExtensionUnmodified_OnCustomTargetExt()
system "windows"
kind "SharedLib"
targetextension ".mil"
i = prepare()
test.isequal("MyProject.lib", i.name)
end
I just copied and slightly modified it:
--
-- The import library extension should change if the
-- custom extension is set.
--
function suite.impLibExtensionModified_OnCustomImpLibExt_Windows()
system "windows"
kind "SharedLib"
implibextension ".mil"
i = prepare()
test.isequal("MyProject.mil", i.name)
end
--
-- The import library extension should change if the
-- custom extension is set.
--
function suite.impLibExtensionModified_OnCustomImpLibExt_Linux()
system "Linux"
kind "SharedLib"
implibextension ".mil"
i = prepare()
test.isequal("libMyProject.mil", i.name)
end
It worked for me (master branch).
I first wondered where it is evaluated too, so i looked through some files that looked promising (before writing the above tests). The field is read but it is hidden from searches: file base/config.lua:
---
-- Helper function for getlinkinfo() and gettargetinfo(); builds the
-- name parts for a configuration, for building or linking.
--
-- @param cfg
-- The configuration object being queried.
-- @param kind
-- The target kind (SharedLib, StaticLib).
-- @param field
-- One of "target" or "implib", used to locate the naming information
-- in the configuration object (i.e. targetdir, targetname, etc.)
-- @return
-- A target info object; see one of getlinkinfo() or gettargetinfo()
-- for more information.
---
function config.buildtargetinfo(cfg, kind, field)
local basedir = cfg.project.location
local targetdir
if cfg.platform then
targetdir = path.join(basedir, 'bin', cfg.platform, cfg.buildcfg)
else
targetdir = path.join(basedir, 'bin', cfg.buildcfg)
end
local directory = cfg[field.."dir"] or cfg.targetdir or targetdir
local basename = cfg[field.."name"] or cfg.targetname or cfg.project.name
local prefix = cfg[field.."prefix"] or cfg.targetprefix or ""
local suffix = cfg[field.."suffix"] or cfg.targetsuffix or ""
local extension = cfg[field.."extension"] or cfg.targetextension or ""
local bundlename = ""
local bundlepath = ""
if table.contains(os.getSystemTags(cfg.system), "darwin") and (kind == p.WINDOWEDAPP or (kind == p.SHAREDLIB and cfg.sharedlibtype)) then
bundlename = basename .. extension
bundlepath = path.join(bundlename, iif(kind == p.SHAREDLIB and cfg.sharedlibtype == "OSXFramework", "Versions/A", "Contents/MacOS"))
end
local info = {}
info.directory = directory
info.basename = basename .. suffix
info.name = prefix .. info.basename .. extension
info.extension = extension
info.abspath = path.join(directory, info.name)
info.fullpath = info.abspath
info.bundlename = bundlename
info.bundlepath = path.join(directory, bundlepath)
info.prefix = prefix
info.suffix = suffix
return info
end
Edit to clarify:
As mentioned in the comment, this function is called with field = "implib" and then the keywords are concatenated and the respective fields read (implibdir, implibname, implibprefix, implibsuffix, implibextension)
I'm going to close this issue - implib* APIs have no impact on links, see the wiki for those APIs they're for the .lib stub that is generated for DLLs in Visual Studio. Completely unrelated to the links API, and I'm not sure what connection was made between the two.
As for the comments about the links extensions; personally, I don't see any value in Premake attempting to support .a out of the box for VS or MSC, people will always be requesting more and more complicated features to handle some projects being lib*.a or whatever. Just using *.lib or *.obj is significantly simpler for everyone.