summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-28 23:46:31 +0800
committerGitHub <[email protected]>2021-12-28 23:46:31 +0800
commit467b48b8320a7392f281a9f80b8428125f4bb96a (patch)
tree8023d0551fb26506f0a532326f24ded56f5f97fc
parent82b3bb99bfe8f441d77a07c29c31d4953eebf697 (diff)
Update find_package.lua
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua50
1 files changed, 50 insertions, 0 deletions
diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua
index c28f62b07..e61e56c29 100644
--- a/xmake/modules/package/manager/vcpkg/find_package.lua
+++ b/xmake/modules/package/manager/vcpkg/find_package.lua
@@ -26,6 +26,42 @@ import("core.project.config")
import("core.project.target")
import("detect.sdks.find_vcpkgdir")
import("package.manager.vcpkg.configurations")
+import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"})
+
+-- we iterate over each pkgconfig file to extract the required data
+function _find_package_from_pkgconfig(pkgconfig_files, opt)
+ opt = opt or {}
+ local foundpc = false
+ local result = {includedirs = {}, linkdirs = {}, links = {}}
+ for _, pkgconfig_file in ipairs(pkgconfig_files) do
+ local pkgconfig_dir = path.join(opt.installdir, path.directory(pkgconfig_file))
+ local pkgconfig_name = path.basename(pkgconfig_file)
+ local pcresult = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = opt.linkdirs})
+
+ -- the pkgconfig file has been parse successfully
+ if pcresult then
+ for _, includedir in ipairs(pcresult.includedirs) do
+ table.insert(result.includedirs, includedir)
+ end
+ for _, linkdir in ipairs(pcresult.linkdirs) do
+ table.insert(result.linkdirs, linkdir)
+ end
+ for _, link in ipairs(pcresult.links) do
+ table.insert(result.links, link)
+ end
+ -- version should be the same if a pacman package contains multiples .pc
+ result.version = pcresult.version
+ 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)
+ return result
+ end
+end
function _find_package(vcpkgdir, name, opt)
@@ -65,6 +101,7 @@ function _find_package(vcpkgdir, name, opt)
-- save includedirs, linkdirs and links
local result = nil
+ local pkgconfig_files = {}
local info = io.readfile(infofile)
if info then
for _, line in ipairs(info:split('\n')) do
@@ -73,6 +110,11 @@ function _find_package(vcpkgdir, name, opt)
line = line:lower()
end
+ -- get pkgconfig files
+ if line:find(triplet .. (mode == "debug" and "/debug" or "") .. "/lib/pkgconfig/", 1, true) and line:endswith(".pc") then
+ table.insert(pkgconfig_files, line)
+ end
+
-- get includedirs
if line:endswith("/include/") then
result = result or {}
@@ -106,6 +148,14 @@ function _find_package(vcpkgdir, name, opt)
end
end
+ -- find result from pkgconfig first
+ if #pkgconfig_files > 0 then
+ local pkgconfig_result = _find_package_from_pkgconfig(pkgconfig_files, {installdir = installdir, linkdirs = result and result.linkdirs})
+ if pkgconfig_result then
+ result = pkgconfig_result
+ end
+ end
+
-- save version
if result then
local infoname = path.basename(infofile)