summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-11 22:47:44 +0800
committerruki <[email protected]>2019-08-11 22:49:06 +0800
commit7204438408a9cd31209af408d911ea45cdcb080e (patch)
tree482e739cbed1ce9b2c3a17b9d8b4c3449f1281e1 /xmake
parent5488ec859886b483dd6cfdf624d9deb58471f1a7 (diff)
improve find_package for pkg-config
Diffstat (limited to 'xmake')
-rw-r--r--xmake/modules/lib/detect/pkg_config.lua28
-rw-r--r--xmake/modules/package/manager/brew/find_package.lua9
2 files changed, 30 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
diff --git a/xmake/modules/package/manager/brew/find_package.lua b/xmake/modules/package/manager/brew/find_package.lua
index 5eb2beba3..0a2648eb7 100644
--- a/xmake/modules/package/manager/brew/find_package.lua
+++ b/xmake/modules/package/manager/brew/find_package.lua
@@ -21,6 +21,7 @@
-- imports
import("lib.detect.find_tool")
import("lib.detect.find_file")
+import("lib.detect.pkg_config")
import("package.manager.find_package")
-- find package from the brew package manager
@@ -50,6 +51,14 @@ function main(name, opt)
if pcfile then
opt.configdirs = path.directory(pcfile)
result = find_package("pkg_config::" .. pcname, opt)
+ if not result then
+ -- attempt to get includedir variable from pkg-config/xx.pc
+ local pkginfo = pkg_config.info(pcname, table.join(opt, {variables = "includedir"}))
+ if pkginfo.includedir then
+ result = result or {}
+ result.includedirs = pkginfo.includedir
+ end
+ end
end
-- find package from xxx/lib, xxx/include