Skip to content

Commit

Permalink
improve to check pkgconfig/importfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 10, 2025
1 parent 4810c79 commit 1f34ccd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
11 changes: 7 additions & 4 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2721,14 +2721,17 @@ end
--
function _instance:check_importfiles(names, opt)
opt = opt or {}
if opt.configdirs == nil then
local configdirs = {}
if opt.PKG_CONFIG_PATH == nil then
local PKG_CONFIG_PATH = {}
local linkdirs = table.wrap(self:get("linkdirs") or "lib")
local installdir = self:installdir()
for _, linkdir in ipairs(linkdirs) do
table.insert(configdirs, path.join(installdir, linkdir))
table.insert(PKG_CONFIG_PATH, path.join(installdir, linkdir, "pkgconfig"))
end
opt.configdirs = configdirs
opt.PKG_CONFIG_PATH = PKG_CONFIG_PATH
end
if opt.CMAKE_PREFIX_PATH == nil then
opt.CMAKE_PREFIX_PATH = self:installdir()
end
return sandbox_module.import("lib.detect.check_importfiles", {anonymous = true})(names or ("pkgconfig::" .. self:name()), opt)
end
Expand Down
29 changes: 24 additions & 5 deletions xmake/modules/lib/detect/check_importfiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
-- imports
import("core.base.option")
import("lib.detect.pkgconfig")
import("package.manager.cmake.find_package", {alias = "cmake_find_package"})

-- check the given importfiles for pkgconfig/cmake
--
-- @param names the import filenames (without .pc/.cmake suffix), e.g. pkgconfig::libxml-2.0, cmake::CURL
-- @param opt the argument options, e.g. { verbose = true, configdirs = {"lib"}}
--
function main(names, opt)
local verbose
if opt.verbose or option.get("verbose") or option.get("diagnosis") then
verbose = true
end
for _, name in ipairs(names) do
local kind
local parts = name:split("::")
Expand All @@ -38,17 +43,31 @@ function main(names, opt)
if kind == nil then
kind = "pkgconfig"
end
if verbose then
cprint("${dim}> checking for %s/%s", kind, name)
end
if kind == "pkgconfig" then
opt.configdirs = opt.PKG_CONFIG_PATH
local result = pkgconfig.libinfo(name, opt)
if opt.verbose or option.get("verbose") or option.get("diagnosis") then
cprint("${dim}> checking for pkgconfig/%s.pc", name)
if result then
print(result)
end
if verbose and result then
print(result)
end
if not result then
return false, string.format("pkgconfig/%s.pc not found!", name)
end
elseif kind == "cmake" then
if opt.CMAKE_PREFIX_PATH then
opt.configs = opt.configs or {}
opt.configs.envs = opt.configs.envs or {}
opt.configs.envs.CMAKE_PREFIX_PATH = path.joinenv(opt.CMAKE_PREFIX_PATH)
end
local result = cmake_find_package(name, opt)
if verbose and result then
print(result)
end
if not result then
return false, string.format("cmake/%s.cmake not found!", name)
end
end
end
return true
Expand Down

0 comments on commit 1f34ccd

Please sign in to comment.