Skip to content

Commit

Permalink
improve to find package from pkg-config #3777
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed May 31, 2023
1 parent 853d25d commit 2c4e281
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions xmake/modules/lib/detect/pkgconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ function libinfo(name, opt)
end

-- get cflags
local result = nil
local cflags = try { function () return os.iorunv(pkgconfig, {"--cflags", name}, {envs = envs}) end }
local found
local result = {}
local cflags = try {function () return os.iorunv(pkgconfig, {"--cflags", name}, {envs = envs}) end,
catch {function (errs) found = false end}}
if cflags then
result = result or {}
for _, flag in ipairs(os.argv(cflags)) do
if flag:startswith("-I") and #flag > 2 then
local includedir = flag:sub(3)
Expand All @@ -171,10 +172,15 @@ function libinfo(name, opt)
end
end

-- libinfo may be empty body, but it's also valid
-- @see https://github.com/xmake-io/xmake/issues/3777#issuecomment-1568453316
if found == false then
return
end

-- get libs and ldflags
local ldflags = try { function () return os.iorunv(pkgconfig, {"--libs", name}, {envs = envs}) end }
if ldflags then
result = result or {}
for _, flag in ipairs(os.argv(ldflags)) do
if flag:startswith("-L") and #flag > 2 then
local linkdir = flag:sub(3)
Expand All @@ -198,7 +204,6 @@ function libinfo(name, opt)
-- get version
local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}, {envs = envs}) end }
if version then
result = result or {}
result.version = version:trim()
end
return result
Expand Down
5 changes: 3 additions & 2 deletions xmake/modules/package/manager/pkgconfig/find_package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ function main(name, opt)
end
end

-- get result
-- get result, libinfo may be empty body, but it's also valid
-- @see https://github.com/xmake-io/xmake/issues/3777#issuecomment-1568453316
local result = nil
if libinfo.links or libinfo.includedirs then
if libinfo then
result = result or {}
result.includedirs = libinfo.includedirs
result.linkdirs = libinfo.linkdirs
Expand Down

0 comments on commit 2c4e281

Please sign in to comment.