From 4bd329ef8184659bfbd221bf80efc5d7ee30e63f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 Jan 2025 00:48:01 +0800 Subject: check pkgconfig --- xmake/core/package/package.lua | 21 +++++++++++++++ xmake/modules/lib/detect/check_pkgconfig.lua | 40 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 xmake/modules/lib/detect/check_pkgconfig.lua diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 741ca318c..a5d6283db 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2712,6 +2712,27 @@ function _instance:check_fcsnippets(snippets, opt) return sandbox_module.import("lib.detect.check_fcsnippets", {anonymous = true})(snippets, opt) end +-- check the given pkgconfig file? +-- +-- @param name the .pc filename (without .pc extension) +-- @param opt the argument options +-- +-- @return true or false, errors +-- +function _instance:check_pkgconfig(name, opt) + opt = opt or {} + if opt.configdirs == nil then + local configdirs = {} + 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)) + end + opt.configdirs = configdirs + end + return sandbox_module.import("lib.detect.check_pkgconfig", {anonymous = true})(name or self:name(), opt) +end + -- the current mode is belong to the given modes? function package._api_is_mode(interp, ...) return config.is_mode(...) diff --git a/xmake/modules/lib/detect/check_pkgconfig.lua b/xmake/modules/lib/detect/check_pkgconfig.lua new file mode 100644 index 000000000..97fdabe55 --- /dev/null +++ b/xmake/modules/lib/detect/check_pkgconfig.lua @@ -0,0 +1,40 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_pkgconfig.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.pkgconfig") + +-- check the given pkgconfig file +-- +-- @param name the .pc file name +-- @param opt the argument options, e.g. { verbose = true, configdirs = {"lib"}} +-- +function main(name, opt) + 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 + end + return result +end + -- cgit v1.3.1 From 4810c79dcd1759389791148496d2b62bfdc90191 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 Jan 2025 00:54:27 +0800 Subject: rename to check importfiles --- xmake/core/package/package.lua | 8 ++-- xmake/modules/lib/detect/check_importfiles.lua | 56 ++++++++++++++++++++++++++ xmake/modules/lib/detect/check_pkgconfig.lua | 40 ------------------ 3 files changed, 60 insertions(+), 44 deletions(-) create mode 100644 xmake/modules/lib/detect/check_importfiles.lua delete mode 100644 xmake/modules/lib/detect/check_pkgconfig.lua diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index a5d6283db..f81bf2a0a 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2712,14 +2712,14 @@ function _instance:check_fcsnippets(snippets, opt) return sandbox_module.import("lib.detect.check_fcsnippets", {anonymous = true})(snippets, opt) end --- check the given pkgconfig file? +-- check the given importfiles? -- --- @param name the .pc filename (without .pc extension) +-- @param names the import filenames (without .pc/.cmake extension), e.g. pkgconfig::libxml-2.0, cmake::CURL -- @param opt the argument options -- -- @return true or false, errors -- -function _instance:check_pkgconfig(name, opt) +function _instance:check_importfiles(names, opt) opt = opt or {} if opt.configdirs == nil then local configdirs = {} @@ -2730,7 +2730,7 @@ function _instance:check_pkgconfig(name, opt) end opt.configdirs = configdirs end - return sandbox_module.import("lib.detect.check_pkgconfig", {anonymous = true})(name or self:name(), opt) + return sandbox_module.import("lib.detect.check_importfiles", {anonymous = true})(names or ("pkgconfig::" .. self:name()), opt) end -- the current mode is belong to the given modes? diff --git a/xmake/modules/lib/detect/check_importfiles.lua b/xmake/modules/lib/detect/check_importfiles.lua new file mode 100644 index 000000000..caa61e4c7 --- /dev/null +++ b/xmake/modules/lib/detect/check_importfiles.lua @@ -0,0 +1,56 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check_importfiles.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.pkgconfig") + +-- 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) + for _, name in ipairs(names) do + local kind + local parts = name:split("::") + if #parts == 2 then + kind = parts[1] + name = parts[2] + end + if kind == nil then + kind = "pkgconfig" + end + if kind == "pkgconfig" then + 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 + end + if not result then + return false, string.format("pkgconfig/%s.pc not found!", name) + end + end + end + return true +end + diff --git a/xmake/modules/lib/detect/check_pkgconfig.lua b/xmake/modules/lib/detect/check_pkgconfig.lua deleted file mode 100644 index 97fdabe55..000000000 --- a/xmake/modules/lib/detect/check_pkgconfig.lua +++ /dev/null @@ -1,40 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file check_pkgconfig.lua --- - --- imports -import("core.base.option") -import("lib.detect.pkgconfig") - --- check the given pkgconfig file --- --- @param name the .pc file name --- @param opt the argument options, e.g. { verbose = true, configdirs = {"lib"}} --- -function main(name, opt) - 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 - end - return result -end - -- cgit v1.3.1 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/core/package/package.lua | 11 ++++++---- xmake/modules/lib/detect/check_importfiles.lua | 29 +++++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index f81bf2a0a..ea33e24fa 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 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 From aca01466c20ab4ab339df31ba507c241606bab25 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 Jan 2025 00:58:41 +0800 Subject: fix cmake check importfiles --- xmake/modules/lib/detect/check_importfiles.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/lib/detect/check_importfiles.lua b/xmake/modules/lib/detect/check_importfiles.lua index 5395413a7..f364c36f5 100644 --- a/xmake/modules/lib/detect/check_importfiles.lua +++ b/xmake/modules/lib/detect/check_importfiles.lua @@ -59,7 +59,7 @@ function main(names, opt) 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) + opt.configs.envs.CMAKE_PREFIX_PATH = path.joinenv(table.wrap(opt.CMAKE_PREFIX_PATH)) end local result = cmake_find_package(name, opt) if verbose and result then -- cgit v1.3.1