diff options
| author | ruki <[email protected]> | 2017-06-13 09:36:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-13 09:36:27 +0800 |
| commit | 3c2de8ed5b50203ebed47f774c51792ee8c4ae80 (patch) | |
| tree | 13b17c67932f6bf3df8ff84e9c1e523c51ed695c | |
| parent | 0fc304af564ce6215df38fbda571d3ee204e585d (diff) | |
improve pkg-config
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_package.lua | 28 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 42 |
2 files changed, 43 insertions, 27 deletions
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index 3062d6799..a77601b50 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -39,7 +39,12 @@ local import = require("sandbox/modules/import") local find_file = import("lib.detect.find_file") local find_library = import("lib.detect.find_library") local pkg_config = import("lib.detect.pkg_config") -local find_brew = import("detect.tool.find_brew") + +-- find package from project package directories +function sandbox_lib_detect_find_package._find_from_project_packagedirs(name, opt) + + -- TODO +end -- find package from repositories function sandbox_lib_detect_find_package._find_from_repositories(name, opt) @@ -61,23 +66,7 @@ end -- find package from pkg-config function sandbox_lib_detect_find_package._find_from_pkg_config(name, opt) - - -- get pkg-config path from brew - local brew = find_brew() - local configdirs = nil - if brew then - local ok, prefix = os.iorunv(brew, {"--prefix", name}) - if ok and prefix then - prefix = path.join(prefix:trim(), "lib", "pkgconfig") - if os.isdir(prefix) then - configdirs = prefix - end - end - end - - - -- find package - return pkg_config.find(name, {version = true, configdirs = configdirs}) + return pkg_config.find(name, {version = true}) end -- find package from system directories @@ -133,7 +122,8 @@ function sandbox_lib_detect_find_package._find(name, opt) -- init find scripts local findscripts = { - sandbox_lib_detect_find_package._find_from_repositories + sandbox_lib_detect_find_package._find_from_project_packagedirs + , sandbox_lib_detect_find_package._find_from_repositories , sandbox_lib_detect_find_package._find_from_modules , sandbox_lib_detect_find_package._find_from_pkg_config , sandbox_lib_detect_find_package._find_from_systemdirs diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 4a7140471..15cb2a391 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -24,6 +24,7 @@ -- imports import("lib.detect.find_library") +import("detect.tool.find_brew") import("detect.tool.find_pkg_config") -- get package info @@ -47,15 +48,37 @@ function info(name, opt) return end + -- init options and cache + opt = opt or {} + _g._INFO = _g._INFO or {} + + -- get it from cache first + local result = _g._INFO[name] + if result then + return result + end + + -- get pkg-config path from brew + local brew = find_brew() + local configdirs = opt.configdirs or {} + if brew then + local prefix = try { function () return os.iorunv(brew, {"--prefix", name}) end } + if prefix then + prefix = path.join(prefix:trim(), "lib", "pkgconfig") + if os.isdir(prefix) then + table.insert(configdirs, prefix) + end + end + end + -- add PKG_CONFIG_PATH - local configdirs = nil - if opt and opt.configdirs then - configdirs = os.getenv("PKG_CONFIG_PATH") - os.addenv("PKG_CONFIG_PATH", unpack(table.wrap(opt.configdirs))) + 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 - local result = nil local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } if flags then @@ -89,7 +112,7 @@ function info(name, opt) end -- get version - if opt and opt.version then + if opt.version then -- get version local version = try { function() return os.iorunv(pkg_config, {"--modversion", name}) end } @@ -100,10 +123,13 @@ function info(name, opt) end -- restore PKG_CONFIG_PATH - if configdirs then - os.setenv("PKG_CONFIG_PATH", configdirs) + if configdirs_old then + os.setenv("PKG_CONFIG_PATH", configdirs_old) end + -- save result to cache + _g._INFO[name] = result + -- ok? return result end |
