From 9aec994cdb4e21ae2f765898de28dacf3467bd77 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 21 Sep 2018 00:37:34 +0800 Subject: improve to find pkg_config package --- xmake/modules/lib/detect/pkg_config.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index fc991393d..e006a1cc5 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -58,17 +58,23 @@ function info(name, opt) return result and result or nil end - -- get pkg-config path from brew - local brew = find_brew() + -- attempt to find package without `brew --prefix` (brew is too slow!) + 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 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) + 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 end end @@ -81,7 +87,7 @@ function info(name, opt) end -- get libs and cflags - local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } + flags = flags or try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } if flags then -- init result -- cgit v1.3.1