summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/find_package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-14 00:08:37 +0800
committerruki <[email protected]>2021-08-14 00:08:37 +0800
commitc5f2a58cf57ad72d4e2bc39a6dc196550804d013 (patch)
tree9941797fce724a48429175e058680d0222177ae8 /xmake/modules/lib/detect/find_package.lua
parentb950a171ca39e649385d7ab1f96bb0c28948fa78 (diff)
concat package
Diffstat (limited to 'xmake/modules/lib/detect/find_package.lua')
-rw-r--r--xmake/modules/lib/detect/find_package.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/xmake/modules/lib/detect/find_package.lua b/xmake/modules/lib/detect/find_package.lua
index 7b7ba7032..b38e55e39 100644
--- a/xmake/modules/lib/detect/find_package.lua
+++ b/xmake/modules/lib/detect/find_package.lua
@@ -24,6 +24,38 @@ import("core.project.config")
import("core.cache.detectcache")
import("package.manager.find_package")
+-- concat packages
+function _concat_packages(a, b)
+ local result = table.copy(a)
+ for k, v in pairs(b) do
+ local o = result[k]
+ if o ~= nil then
+ v = table.join(o, v)
+ end
+ result[k] = v
+ end
+ for k, v in pairs(result) do
+ if k == "links" then
+ if type(v) == "table" and #v > 1 then
+ -- we need ensure link orders when removing repeat values
+ local v2 = {}
+ local map = {}
+ for _, _v in irpairs(v) do
+ if not map[_v] then
+ table.insert(v2, 1, _v)
+ map[_v] = true
+ end
+ end
+ v = v2
+ end
+ else
+ v = table.unique(v)
+ end
+ result[k] = v
+ end
+ return result
+end
+
-- find package using the package manager
--
-- @param name the package name
@@ -113,5 +145,10 @@ function main(name, opt)
if not opt.version and result then
result.version = nil
end
+
+ -- register concat
+ if result and type(result) == "table" then
+ debug.setmetatable(result, {__concat = _concat_packages})
+ end
return result and result or nil
end