From 1f34ccd505a67d3e71803d07e8d7bc7f1b9be4fd Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 Jan 2025 00:57:49 +0800 Subject: improve to check pkgconfig/importfiles --- xmake/modules/lib/detect/check_importfiles.lua | 29 +++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'xmake/modules/lib') diff --git a/xmake/modules/lib/detect/check_importfiles.lua b/xmake/modules/lib/detect/check_importfiles.lua index caa61e4c7..5395413a7 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 -- cgit v1.3.1