diff options
| author | ruki <[email protected]> | 2021-05-21 00:43:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-05-21 00:43:46 +0800 |
| commit | e65399c1d6d2a3ecd4f13f82cfe18c70e41182f3 (patch) | |
| tree | 5c2d3386111336a22c4e800767106df3e7829dfa | |
| parent | 16a421fdcae87814b8ca5fbb53c63ddfcd688380 (diff) | |
improve pacman::find_package
| -rw-r--r-- | xmake/modules/lib/detect/pkgconfig.lua | 18 | ||||
| -rw-r--r-- | xmake/modules/package/manager/find_package.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/package/manager/pacman/find_package.lua | 21 |
3 files changed, 36 insertions, 9 deletions
diff --git a/xmake/modules/lib/detect/pkgconfig.lua b/xmake/modules/lib/detect/pkgconfig.lua index 9cd07a1e7..f47cd70be 100644 --- a/xmake/modules/lib/detect/pkgconfig.lua +++ b/xmake/modules/lib/detect/pkgconfig.lua @@ -171,6 +171,24 @@ function libinfo(name, opt) end end + -- get includedirs + if not result or not result.includedirs then + local varinfo = variables(name, "includedir", opt) + if varinfo and varinfo.includedir then + result = result or {} + result.includedirs = varinfo.includedir + end + end + + -- get linkdirs + if not result or not result.linkdirs then + local varinfo = variables(name, "libdir", opt) + if varinfo and varinfo.libdir then + result = result or {} + result.linkdirs = varinfo.libdir + end + end + -- get version local version = try { function() return os.iorunv(pkgconfig, {"--modversion", name}, {envs = envs}) end } if version then diff --git a/xmake/modules/package/manager/find_package.lua b/xmake/modules/package/manager/find_package.lua index 0f8013b9c..41c110796 100644 --- a/xmake/modules/package/manager/find_package.lua +++ b/xmake/modules/package/manager/find_package.lua @@ -56,6 +56,9 @@ function _find_package_with_builtin_rule(package_name, opt) -- only support the current sub-host platform and sub-architecture, e.g. linux, macosx, or msys (subsystem) if opt.plat == os.subhost() and opt.arch == os.subarch() then + -- find it from pkg-config + table.insert(managers, "pkgconfig") + -- find it from pacman if is_subhost("linux", "msys") and not is_plat("windows") and find_tool("pacman") then table.insert(managers, "pacman") @@ -66,9 +69,6 @@ function _find_package_with_builtin_rule(package_name, opt) table.insert(managers, "portage") end - -- find it from pkg-config - table.insert(managers, "pkgconfig") - -- find it from system table.insert(managers, "system") end diff --git a/xmake/modules/package/manager/pacman/find_package.lua b/xmake/modules/package/manager/pacman/find_package.lua index ba5b58c21..8b1b01abe 100644 --- a/xmake/modules/package/manager/pacman/find_package.lua +++ b/xmake/modules/package/manager/pacman/find_package.lua @@ -51,15 +51,13 @@ function main(name, opt) end -- parse package files list - local pkgconfig_dir = nil - local pkgconfig_name = nil local linkdirs = {} local has_includes = false + local pkgconfig_files = {} for _, line in ipairs(list:split('\n', {plain = true})) do line = line:trim():split('%s+')[2] if not pkgconfig_dir and line:find("/pkgconfig/", 1, true) and line:endswith(".pc") then - pkgconfig_dir = path.directory(line) - pkgconfig_name = path.basename(line) + pkgconfig_files[path.basename(line)] = line end if line:endswith(".so") or line:endswith(".a") or line:endswith(".lib") then table.insert(linkdirs, path.directory(line)) @@ -68,12 +66,23 @@ function main(name, opt) end end + -- get pkgconfig file + local pkgconfig_file = pkgconfig_files[name] + if not pkgconfig_file then + for _, file in pairs(pkgconfig_files) do + pkgconfig_file = file + break + end + end + -- find package local result = nil - if pkgconfig_dir then + if pkgconfig_file then + local pkgconfig_dir = path.directory(pkgconfig_file) + local pkgconfig_name = path.basename(pkgconfig_file) linkdirs = table.unique(linkdirs) includedirs = table.unique(includedirs) - result = find_package_from_pkgconfig(pkgconfig_name or name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) + result = find_package_from_pkgconfig(pkgconfig_name, {configdirs = pkgconfig_dir, linkdirs = linkdirs}) if not result and has_includes then -- header only and hidden /usr/include? we need only return empty {} result = {} |
