summaryrefslogtreecommitdiff
path: root/xmake/modules/lib/detect/pkgconfig.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-07 23:55:42 +0800
committerruki <[email protected]>2024-08-07 23:55:42 +0800
commit7b7e98eaf4bc8358beca3bedd8a549f6a05418e3 (patch)
tree70373bd2ec30208f41829568a12655fbce00009b /xmake/modules/lib/detect/pkgconfig.lua
parent988d038bb95e83325d2bac655a0886f623844d91 (diff)
find libfiles from pkg-config
Diffstat (limited to 'xmake/modules/lib/detect/pkgconfig.lua')
-rw-r--r--xmake/modules/lib/detect/pkgconfig.lua63
1 files changed, 31 insertions, 32 deletions
diff --git a/xmake/modules/lib/detect/pkgconfig.lua b/xmake/modules/lib/detect/pkgconfig.lua
index c86154e6e..3a4fe6035 100644
--- a/xmake/modules/lib/detect/pkgconfig.lua
+++ b/xmake/modules/lib/detect/pkgconfig.lua
@@ -79,41 +79,47 @@ end
-- @param opt the argument options, {configdirs = {"/xxxx/pkgconfig/"}}
--
function variables(name, variables, opt)
-
- -- attempt to add search paths from pkg-config
+ opt = opt or {}
local pkgconfig = _get_pkgconfig()
if not pkgconfig then
return
end
- -- init options
- opt = opt or {}
-
- -- init PKG_CONFIG_PATH
- local configdirs_old = os.getenv("PKG_CONFIG_PATH")
- local configdirs = table.wrap(opt.configdirs)
- if #configdirs > 0 then
- os.setenv("PKG_CONFIG_PATH", table.unpack(configdirs))
- end
-
- -- get variable value
local result = nil
+ local envs = {PKG_CONFIG_PATH = opt.configdirs}
if variables then
for _, variable in ipairs(table.wrap(variables)) do
- local value = try { function () return os.iorunv(pkgconfig, {"--variable=" .. variable, name}) end }
+ local value = try { function ()
+ return os.iorunv(pkgconfig, {"--variable=" .. variable, name}, {envs = envs})
+ end }
if value ~= nil then
result = result or {}
result[variable] = value:trim()
end
end
end
+ return result
+end
- -- restore PKG_CONFIG_PATH
- if configdirs_old then
- os.setenv("PKG_CONFIG_PATH", configdirs_old)
+-- get pcfile path
+--
+-- @param name the package name
+-- @param opt the argument options, {configdirs = {"/xxxx/pkgconfig/"}}
+--
+function pcfile(name, opt)
+ opt = opt or {}
+ local pkgconfig = _get_pkgconfig()
+ if not pkgconfig then
+ return
end
- -- ok?
+ local envs = {PKG_CONFIG_PATH = opt.configdirs}
+ local result = try { function ()
+ return os.iorunv(pkgconfig, {"--path", name}, {envs = envs})
+ end }
+ if result then
+ result = result:trim()
+ end
return result
end
@@ -131,28 +137,21 @@ end
-- @endcode
--
function libinfo(name, opt)
-
- -- attempt to add search paths from pkg-config
+ opt = opt or {}
local pkgconfig = _get_pkgconfig()
if not pkgconfig then
return
end
- -- init options
- opt = opt or {}
-
- -- init PKG_CONFIG_PATH
- local envs = {}
- local configdirs = table.wrap(opt.configdirs)
- if #configdirs > 0 then
- envs.PKG_CONFIG_PATH = path.joinenv(configdirs)
- end
-
-- get cflags
local found
local result = {}
- local cflags = try {function () return os.iorunv(pkgconfig, {"--cflags", name}, {envs = envs}) end,
- catch {function (errs) found = false end}}
+ local envs = {PKG_CONFIG_PATH = opt.configdirs}
+ local cflags = try {function ()
+ return os.iorunv(pkgconfig, {"--cflags", name}, {envs = envs})
+ end, catch {function (errs)
+ found = false
+ end}}
if cflags then
for _, flag in ipairs(os.argv(cflags)) do
if flag:startswith("-I") and #flag > 2 then