diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f81bf2a0a4..ea33e24fae 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -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 diff --git a/xmake/modules/lib/detect/check_importfiles.lua b/xmake/modules/lib/detect/check_importfiles.lua index caa61e4c7c..5395413a78 100644 --- a/xmake/modules/lib/detect/check_importfiles.lua +++ b/xmake/modules/lib/detect/check_importfiles.lua @@ -21,6 +21,7 @@ -- 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 -- @@ -28,6 +29,10 @@ import("lib.detect.pkgconfig") -- @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("::") @@ -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