diff options
| author | ruki <[email protected]> | 2019-08-11 22:47:44 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-11 22:49:06 +0800 |
| commit | 7204438408a9cd31209af408d911ea45cdcb080e (patch) | |
| tree | 482e739cbed1ce9b2c3a17b9d8b4c3449f1281e1 /xmake/modules/lib/detect | |
| parent | 5488ec859886b483dd6cfdf624d9deb58471f1a7 (diff) | |
improve find_package for pkg-config
Diffstat (limited to 'xmake/modules/lib/detect')
| -rw-r--r-- | xmake/modules/lib/detect/pkg_config.lua | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/xmake/modules/lib/detect/pkg_config.lua b/xmake/modules/lib/detect/pkg_config.lua index 2e645379f..e50360f13 100644 --- a/xmake/modules/lib/detect/pkg_config.lua +++ b/xmake/modules/lib/detect/pkg_config.lua @@ -24,13 +24,12 @@ import("core.project.target") import("core.project.config") import("lib.detect.find_file") import("lib.detect.find_library") -import("detect.tools.find_brew") import("detect.tools.find_pkg_config") -- get package info -- -- @param name the package name --- @param opt the argument options, {version = true, configdirs = {"/xxxx/pkgconfig/"}} +-- @param opt the argument options, {version = true, variables = "includedir", configdirs = {"/xxxx/pkgconfig/"}} -- -- @return {links = {"ssl", "crypto", "z"}, linkdirs = {""}, includedirs = {""}, version = ""} -- @@ -58,8 +57,20 @@ function info(name, opt) os.setenv("PKG_CONFIG_PATH", unpack(configdirs)) end - -- get libs and cflags + -- get variable value local result = nil + if opt.variables then + for _, variable in ipairs(table.wrap(opt.variables)) do + local value = try { function () return os.iorunv(pkg_config, {"--variable=" .. variable, name}) end } + if value ~= nil then + result = result or {} + result[variable] = value:trim() + end + end + return result + end + + -- get libs and cflags local flags = try { function () return os.iorunv(pkg_config, {"--libs", "--cflags", name}) end } if flags then @@ -149,11 +160,14 @@ function find(name, opt) result.linkdirs = table.join(result.linkdirs or {}, libinfo.linkdir) end end - - -- found? if result and result.links then - result.linkdirs = table.unique(result.linkdirs) - result.includedirs = table.join(result.includedirs or {}, pkginfo.includedirs) + result.linkdirs = table.unique(result.linkdirs) + end + + -- get includedirs + if pkginfo.includedirs then + result = result or {} + result.includedirs = pkginfo.includedirs end -- save version |
