summaryrefslogtreecommitdiff
path: root/xmake/modules/package/manager/pacman/find_package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-07 23:55:42 +0800
committerruki <[email protected]>2024-08-07 23:55:42 +0800
commit7b7e98eaf4bc8358beca3bedd8a549f6a05418e3 (patch)
tree70373bd2ec30208f41829568a12655fbce00009b /xmake/modules/package/manager/pacman/find_package.lua
parent988d038bb95e83325d2bac655a0886f623844d91 (diff)
find libfiles from pkg-config
Diffstat (limited to 'xmake/modules/package/manager/pacman/find_package.lua')
-rw-r--r--xmake/modules/package/manager/pacman/find_package.lua67
1 files changed, 46 insertions, 21 deletions
diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua
index efd7cae37..c9329be55 100644
--- a/xmake/modules/package/manager/pacman/find_package.lua
+++ b/xmake/modules/package/manager/pacman/find_package.lua
@@ -46,11 +46,12 @@ function _find_package_from_list(list, name, pacman, opt)
end
-- iterate over each file path inside the pacman package
- local result = {includedirs = {}, linkdirs = {}, links = {}}
+ local result = {}
for _, line in ipairs(list:split('\n', {plain = true})) do -- on msys cygpath should be used to convert local path to windows path
line = line:trim():split('%s+')[2]
if line:find("/include/", 1, true) and (line:endswith(".h") or line:endswith(".hpp")) then
if not line:startswith("/usr/include/") then
+ result.includedirs = result.includedirs or {}
local hpath = line
if is_subhost("msys") and opt.plat == "mingw" then
hpath = path.join(pathtomsys, line)
@@ -63,12 +64,18 @@ function _find_package_from_list(list, name, pacman, opt)
elseif line:endswith(".dll.a") then -- only for mingw
local apath = path.join(pathtomsys, line)
apath = apath:trim()
+ result.linkdirs = result.linkdirs or {}
+ result.links = result.links or {}
table.insert(result.linkdirs, path.directory(apath))
table.insert(result.links, target.linkname(path.filename(apath), {plat = opt.plat}))
elseif line:endswith(".so") then
+ result.linkdirs = result.linkdirs or {}
+ result.links = result.links or {}
table.insert(result.linkdirs, path.directory(line))
table.insert(result.links, target.linkname(path.filename(line), {plat = opt.plat}))
elseif line:endswith(".a") then
+ result.linkdirs = result.linkdirs or {}
+ result.links = result.links or {}
local apath = line
if is_subhost("msys") and opt.plat == "mingw" then
apath = path.join(pathtomsys, line)
@@ -78,9 +85,15 @@ function _find_package_from_list(list, name, pacman, opt)
table.insert(result.links, target.linkname(path.filename(apath), {plat = opt.plat}))
end
end
- result.includedirs = table.unique(result.includedirs)
- result.linkdirs = table.unique(result.linkdirs)
- result.links = table.reverse_unique(result.links)
+ if result.includedirs then
+ result.includedirs = table.unique(result.includedirs)
+ end
+ if result.linkdirs then
+ result.linkdirs = table.unique(result.linkdirs)
+ end
+ if result.links then
+ result.links = table.reverse_unique(result.links)
+ end
-- use pacman package version as version
local version = try { function() return os.iorunv(pacman.program, {"-Q", name}) end }
@@ -192,7 +205,7 @@ function main(name, opt)
-- we iterate over each pkgconfig file to extract the required data
local foundpc = false
- local result = {includedirs = {}, linkdirs = {}, links = {}}
+ local result = {}
for _, pkgconfig_file in ipairs(pkgconfig_files) do
local pkgconfig_dir = path.directory(pkgconfig_file)
local pkgconfig_name = path.basename(pkgconfig_file)
@@ -201,43 +214,55 @@ function main(name, opt)
-- the pkgconfig file has been parse successfully
if pcresult then
for _, includedir in ipairs(pcresult.includedirs) do
+ result.includedirs = result.includedirs or {}
table.insert(result.includedirs, includedir)
end
for _, linkdir in ipairs(pcresult.linkdirs) do
+ result.linkdirs = result.linkdirs or {}
table.insert(result.linkdirs, linkdir)
end
for _, link in ipairs(pcresult.links) do
+ result.links = result.links or {}
table.insert(result.links, link)
end
+ for _, libfile in ipairs(pcresult.libfiles) do
+ result.libfiles = result.libfiles or {}
+ table.insert(result.libfiles, libfile)
+ end
-- version should be the same if a pacman package contains multiples .pc
result.version = pcresult.version
+ result.shared = pcresult.shared
+ result.static = pcresult.static
foundpc = true
end
end
if foundpc == true then
- result.includedirs = table.unique(result.includedirs)
- result.linkdirs = table.unique(result.linkdirs)
- result.links = table.reverse_unique(result.links)
+ if result.includedirs then
+ result.includedirs = table.unique(result.includedirs)
+ end
+ if result.linkdirs then
+ result.linkdirs = table.unique(result.linkdirs)
+ end
+ if result.libfiles then
+ result.libfiles = table.unique(result.libfiles)
+ end
+ if result.links then
+ result.links = table.reverse_unique(result.links)
+ end
else
-- if there is no .pc, we parse the package content to obtain the data we want
result = _find_package_from_list(list, name, pacman, opt)
end
if result then
- if result.linkdirs and #result.linkdirs == 0 then
- result.linkdirs = nil
- end
- if result.includedirs and #result.includedirs == 0 then
- result.includedirs = nil
- end
if not result.libfiles then
- result.libfiles = _find_libfiles_from_list(list, name, pacman, opt)
- end
- for _, libfile in ipairs(result.libfiles) do
- if libfile:endswith(".so") then
- result.shared = true
- elseif libfile:endswith(".a") then
- result.static = true
+ result.libfiles = _find_libfiles_from_list(list, name, pacman, opt)
+ for _, libfile in ipairs(result.libfiles) do
+ if libfile:endswith(".so") then
+ result.shared = true
+ elseif libfile:endswith(".a") then
+ result.static = true
+ end
end
end
end