summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-07-24 23:29:40 +0800
committerruki <[email protected]>2023-07-24 23:29:40 +0800
commitf79ebdd7c8ae625a995c99e58b4cd8dbd5c502ee (patch)
tree8097867cf43caacc63526a1f2048cac6e9c9e1e6
parent2d76e97e891dc655df0fe97c02c626b6497c0b45 (diff)
improve to scan lib links
-rw-r--r--xmake/modules/package/manager/xmake/find_package.lua32
1 files changed, 24 insertions, 8 deletions
diff --git a/xmake/modules/package/manager/xmake/find_package.lua b/xmake/modules/package/manager/xmake/find_package.lua
index 10c58436a..a1f2dfac2 100644
--- a/xmake/modules/package/manager/xmake/find_package.lua
+++ b/xmake/modules/package/manager/xmake/find_package.lua
@@ -107,17 +107,33 @@ function _find_package_from_repo(name, opt)
links = table.reverse_unique(links)
else
-- we scan links automatically
- local found = false
+ local symrefs = {}
+ local libfiles = {}
for _, libdir in ipairs(vars.linkdirs or "lib") do
for _, file in ipairs(os.files(path.join(installdir, libdir, "*"))) do
- if file:endswith(".lib") or file:endswith(".a") then
- found = true
- table.insert(links, target.linkname(path.filename(file), {plat = opt.plat}))
+ table.insert(libfiles, file)
+ if os.islink(file) then
+ local reallink = os.readlink(file)
+ if reallink then
+ symrefs[reallink] = file
+ end
end
end
- if not found then
- for _, file in ipairs(os.files(path.join(installdir, libdir, "*"))) do
- if file:endswith(".so") or file:match(".+%.so%..+$") or file:endswith(".dylib") then -- maybe symlink to libxxx.so.1
+ end
+ local found = false
+ for _, file in ipairs(libfiles) do
+ if file:endswith(".lib") or file:endswith(".a") then
+ found = true
+ table.insert(links, target.linkname(path.filename(file), {plat = opt.plat}))
+ end
+ end
+ if not found then
+ for _, file in ipairs(libfiles) do
+ -- if this library file has been referenced (libfoo.so.1), e.g. libfoo.so -> libfoo.so.1,
+ -- we need ignore it and only use -lfoo
+ local filename = path.filename(file)
+ if not symrefs[filename] then
+ if file:endswith(".so") or file:match(".+%.so%..+$") or file:endswith(".dylib") then
table.insert(links, target.linkname(path.filename(file), {plat = opt.plat}))
end
end
@@ -140,7 +156,7 @@ function _find_package_from_repo(name, opt)
end
end
for _, file in ipairs(os.files(path.join(installdir, libdir, "*"))) do
- if file:endswith(".so") or file:match(".+%.so%..+$") or file:endswith(".dylib") or file:endswith("*.dll") then -- maybe symlink to libxxx.so.1
+ if file:endswith(".so") or file:match(".+%.so%..+$") or file:endswith(".dylib") or file:endswith("*.dll") then
result.shared = true
table.insert(libfiles, file)
end