diff options
| author | ruki <[email protected]> | 2018-10-04 00:46:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-10-03 22:41:37 +0800 |
| commit | 922a1f5d89ddd79f9413bd4fa4c98903cfc2bdde (patch) | |
| tree | 11faff854b885f848eff888bc135cdb0c82ac2e8 /xmake/modules/lib/detect/pkg_config.lua | |
| parent | 9b4d2611b05065bfc0c9ac8a7b3c1e80cedb7e82 (diff) | |
improve
Diffstat (limited to 'xmake/modules/lib/detect/pkg_config.lua')
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 965879f4c..3b3a6658b 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -23,7 +23,9 @@ -- -- imports +import("core.base.global") import("core.project.target") +import("core.project.config") import("lib.detect.find_file") import("lib.detect.find_library") import("detect.tools.find_brew") @@ -60,28 +62,33 @@ function info(name, opt) return result and result or nil end + -- add PKG_CONFIG_PATH + local configdirs_old = os.getenv("PKG_CONFIG_PATH") + local configdirs = opt.configdirs or {} + if #configdirs > 0 then + os.addenv("PKG_CONFIG_PATH", unpack(configdirs)) + end + -- 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 brewprefix = nil - local configdirs = opt.configdirs or {} if not flags then + + -- find the config directories from the prefix directories of xmake + local platsubdirs = path.join(config.get("plat") or os.host(), config.get("arch") or os.arch(), "release") + os.addenv("PKG_CONFIG_PATH", path.join(config.directory(), "prefix", platsubdirs, "lib", "pkgconfig")) + os.addenv("PKG_CONFIG_PATH", path.join(global.directory(), "prefix", platsubdirs, "lib", "pkgconfig")) + -- 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)) + os.addenv("PKG_CONFIG_PATH", path.directory(pcfile)) end end - -- add PKG_CONFIG_PATH - local configdirs_old = nil - if #configdirs > 0 then - configdirs_old = os.getenv("PKG_CONFIG_PATH") - os.addenv("PKG_CONFIG_PATH", unpack(configdirs)) - end - -- get libs and cflags flags = flags or try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } if flags then |
