diff options
| author | ruki <[email protected]> | 2022-05-28 00:19:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-28 00:19:01 +0800 |
| commit | 2e6fb83447a0ff31c763a823b00ecd46dbe930c9 (patch) | |
| tree | 47e10a8ae65fa5753bd168849abcc55745485f95 /xmake/modules/lib/detect/pkgconfig.lua | |
| parent | 8fc4d25edd38fe9f3b469e328d7580408e814cde (diff) | |
improve pkgconfig
Diffstat (limited to 'xmake/modules/lib/detect/pkgconfig.lua')
| -rw-r--r-- | xmake/modules/lib/detect/pkgconfig.lua | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/xmake/modules/lib/detect/pkgconfig.lua b/xmake/modules/lib/detect/pkgconfig.lua index cf6b6d97d..bd60c3769 100644 --- a/xmake/modules/lib/detect/pkgconfig.lua +++ b/xmake/modules/lib/detect/pkgconfig.lua @@ -148,37 +148,54 @@ function libinfo(name, opt) envs.PKG_CONFIG_PATH = path.joinenv(configdirs) end - -- get libs and cflags + -- get cflags local result = nil - local flags = try { function () return os.iorunv(pkgconfig, {"--libs", "--cflags", name}, {envs = envs}) end } - if flags then + local cflags = try { function () return os.iorunv(pkgconfig, {"--cflags", name}, {envs = envs}) 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) + if includedir and os.isdir(includedir) then + result.includedirs = result.includedirs or {} + table.insert(result.includedirs, includedir) + end + elseif flag:startswith("-D") and #flag > 2 then + local define = flag:sub(3) + result.defines = result.defines or {} + table.insert(result.defines, define) + elseif flag:startswith("-") and #flag > 1 then + result.cxflags = result.cxflags or {} + table.insert(result.cxflags, flag) + end + end + end - -- init result - result = {} - for _, flag in ipairs(os.argv(flags)) do + -- 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 - -- get linkdirs local linkdir = flag:sub(3) if linkdir and os.isdir(linkdir) then result.linkdirs = result.linkdirs or {} table.insert(result.linkdirs, linkdir) end - elseif flag:startswith("-I") and #flag > 2 then - -- get includedirs - local includedir = flag:sub(3) - if includedir and os.isdir(includedir) then - result.includedirs = result.includedirs or {} - table.insert(result.includedirs, includedir) - end elseif flag:startswith("-l") and #flag > 2 then - -- get links local link = flag:sub(3) result.links = result.links or {} table.insert(result.links, link) + elseif flag:startswith("-") and #flag > 1 then + result.ldflags = result.ldflags or {} + result.shflags = result.shflags or {} + table.insert(result.ldflags, flag) + table.insert(result.shflags, flag) end end end + -- get version local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}, {envs = envs}) end } if version then |
