Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve to find package from pkg-config #3777 #3797

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading