summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/pkg_config.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2018-09-21 00:46:42 +0800
committerruki <[email protected]>2018-09-20 22:40:15 +0800
commit057a81d3365f6c706bb15c215f5ac6a860a29ce9 (patch)
tree074f7bf8d5118e277ab9e6b4141548b92ebd8969 /xmake/modules/lib/detect/pkg_config.lua
parent72cae54191c2eab872d660e8eae0a4e8b1803351 (diff)
improve to find package with pkg-config
Diffstat (limited to 'xmake/modules/lib/detect/pkg_config.lua')
-rw-r--r--xmake/modules/lib/detect/pkg_config.lua28
1 files changed, 15 insertions, 13 deletions
diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua
index e006a1cc5..965879f4c 100644
--- a/xmake/modules/lib/detect/pkg_config.lua
+++ b/xmake/modules/lib/detect/pkg_config.lua
@@ -23,6 +23,8 @@
--
-- imports
+import("core.project.target")
+import("lib.detect.find_file")
import("lib.detect.find_library")
import("detect.tools.find_brew")
import("detect.tools.find_pkg_config")
@@ -58,24 +60,18 @@ function info(name, opt)
return result and result or nil
end
- -- attempt to find package without `brew --prefix` (brew is too slow!)
+ -- attempt to find package without `brew --prefix` first
local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end }
-- attempt to get pkg-config path from `brew --prefix` if no flags
- local brew = nil
local brewprefix = nil
local configdirs = opt.configdirs or {}
if not flags then
- brew = find_brew()
- if brew then
- brewprefix = try { function () return os.iorunv(brew, {"--prefix", name}) end }
- if brewprefix then
- brewprefix = brewprefix:trim()
- local configdir = path.join(brewprefix, "lib", "pkgconfig")
- if os.isdir(configdir) then
- table.insert(configdirs, configdir)
- end
- end
+ -- find the prefix directory of brew directly, because `brew --prefix name` is too slow!
+ local pcfile = find_file("*.pc", "/usr/local/Cellar/" .. name .. "/*/lib/pkgconfig")
+ if pcfile then
+ brewprefix = path.directory(path.directory(path.directory(pcfile)))
+ table.insert(configdirs, path.directory(pcfile))
end
end
@@ -118,7 +114,13 @@ function info(name, opt)
end
end
elseif brewprefix then
- result = {linkdirs = {path.join(brewprefix, "lib")}, includedirs = {path.join(brewprefix, "include")}}
+ local links = {}
+ for _, file in ipairs(os.files(path.join(brewprefix, "lib", "*.a"))) do
+ table.insert(links, target.linkname(path.filename(file)))
+ end
+ if #links > 0 then
+ result = {links = links, linkdirs = {path.join(brewprefix, "lib")}, includedirs = {path.join(brewprefix, "include")}}
+ end
end
-- get version