summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-10-20 00:49:17 +0800
committerruki <[email protected]>2022-10-20 00:49:17 +0800
commit7f7cd68284676f7969d99e2e7d54b91275ef5569 (patch)
tree46760934e310e77595acc9141198552e43842459
parenta89822b7530c98914109cecc770dfef15e707e23 (diff)
find components from brew
-rw-r--r--tests/projects/package/components/xmake.lua2
-rw-r--r--xmake/core/package/package.lua5
-rw-r--r--xmake/modules/package/manager/brew/find_package.lua59
3 files changed, 50 insertions, 16 deletions
diff --git a/tests/projects/package/components/xmake.lua b/tests/projects/package/components/xmake.lua
index eb18d7bb0..fb3758df2 100644
--- a/tests/projects/package/components/xmake.lua
+++ b/tests/projects/package/components/xmake.lua
@@ -57,7 +57,7 @@ package("sfml")
end
if is_plat("macosx") then
- add_extsources("brew::sfml")
+ add_extsources("brew::sfml/sfml-all")
end
on_component("graphics", function (package, component)
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 0ccdf42b0..fb52da8fd 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -1515,8 +1515,9 @@ function _instance:_fetch_library(opt)
local components_extsources = {}
for name, comp in pairs(self:components()) do
for _, extsource in ipairs(table.wrap(comp:get("extsources"))) do
- if fetchname:split("::")[1] == extsource:split("::")[1] then
- components_extsources[name] = extsource
+ local extsource_info = extsource:split("::")
+ if fetchname:split("::")[1] == extsource_info[1] then
+ components_extsources[name] = extsource_info[2]
break
end
end
diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua
index 9706bfd8e..4c0061bb8 100644
--- a/xmake/modules/package/manager/brew/find_package.lua
+++ b/xmake/modules/package/manager/brew/find_package.lua
@@ -47,19 +47,10 @@ function _brew_pkg_rootdir()
return brew_pkg_rootdir or nil
end
--- find package from the brew package manager
---
--- @param name the package name, e.g. zlib, pcre/libpcre16
--- @param opt the options, e.g. {verbose = true, version = "1.12.x")
---
-function main(name, opt)
-
- -- find the prefix directory of brew
- local brew_pkg_rootdir = _brew_pkg_rootdir()
- if not brew_pkg_rootdir then
- return
- end
- brew_pkg_rootdir = path.join(brew_pkg_rootdir, opt.plat == "macosx" and "Cellar" or "opt")
+-- find package from pkg-config
+function _find_package_from_pkgconfig(name, opt)
+ opt = opt or {}
+ local brew_pkg_rootdir = opt.brew_pkg_rootdir
-- parse name, e.g. pcre/libpcre16
local nameinfo = name:split('/')
@@ -92,9 +83,51 @@ function main(name, opt)
end
end
end
+ return result
+end
+
+-- find package from the brew package manager
+--
+-- @param name the package name, e.g. zlib, pcre/libpcre16
+-- @param opt the options, e.g. {verbose = true, version = "1.12.x")
+--
+function main(name, opt)
+
+ -- find the prefix directory of brew
+ opt = opt or {}
+ local brew_pkg_rootdir = _brew_pkg_rootdir()
+ if not brew_pkg_rootdir then
+ return
+ end
+ brew_pkg_rootdir = path.join(brew_pkg_rootdir, opt.plat == "macosx" and "Cellar" or "opt")
+
+ -- find package from pkg-config
+ local result = _find_package_from_pkgconfig(name,
+ table.join(opt, {brew_pkg_rootdir = brew_pkg_rootdir}))
+
+ -- find components
+ local components
+ local components_extsources = opt.components_extsources
+ for _, comp in ipairs(opt.components) do
+ local extsource = components_extsources and components_extsources[comp]
+ if extsource then
+ local component_result = _find_package_from_pkgconfig(extsource,
+ table.join(opt, {brew_pkg_rootdir = brew_pkg_rootdir}))
+ if component_result then
+ components = components or {}
+ components[comp] = component_result
+ end
+ end
+ end
+ if components then
+ result = result or {}
+ result.components = components
+ components.__base = {}
+ end
-- find package from xxx/lib, xxx/include
if not result then
+ local nameinfo = name:split('/')
local pkgdir = find_path("lib", path.join(brew_pkg_rootdir, nameinfo[1], "*"))
if pkgdir then
local links = {}