Skip to content

Commit ebc885c

Browse files
authored
Merge pull request #6055 from xmake-io/pkgconfig
check pkgconfig/cmake importfiles for package
2 parents e470863 + aca0146 commit ebc885c

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

xmake/core/package/package.lua

+24
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,30 @@ function _instance:check_fcsnippets(snippets, opt)
27122712
return sandbox_module.import("lib.detect.check_fcsnippets", {anonymous = true})(snippets, opt)
27132713
end
27142714

2715+
-- check the given importfiles?
2716+
--
2717+
-- @param names the import filenames (without .pc/.cmake extension), e.g. pkgconfig::libxml-2.0, cmake::CURL
2718+
-- @param opt the argument options
2719+
--
2720+
-- @return true or false, errors
2721+
--
2722+
function _instance:check_importfiles(names, opt)
2723+
opt = opt or {}
2724+
if opt.PKG_CONFIG_PATH == nil then
2725+
local PKG_CONFIG_PATH = {}
2726+
local linkdirs = table.wrap(self:get("linkdirs") or "lib")
2727+
local installdir = self:installdir()
2728+
for _, linkdir in ipairs(linkdirs) do
2729+
table.insert(PKG_CONFIG_PATH, path.join(installdir, linkdir, "pkgconfig"))
2730+
end
2731+
opt.PKG_CONFIG_PATH = PKG_CONFIG_PATH
2732+
end
2733+
if opt.CMAKE_PREFIX_PATH == nil then
2734+
opt.CMAKE_PREFIX_PATH = self:installdir()
2735+
end
2736+
return sandbox_module.import("lib.detect.check_importfiles", {anonymous = true})(names or ("pkgconfig::" .. self:name()), opt)
2737+
end
2738+
27152739
-- the current mode is belong to the given modes?
27162740
function package._api_is_mode(interp, ...)
27172741
return config.is_mode(...)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author ruki
18+
-- @file check_importfiles.lua
19+
--
20+
21+
-- imports
22+
import("core.base.option")
23+
import("lib.detect.pkgconfig")
24+
import("package.manager.cmake.find_package", {alias = "cmake_find_package"})
25+
26+
-- check the given importfiles for pkgconfig/cmake
27+
--
28+
-- @param names the import filenames (without .pc/.cmake suffix), e.g. pkgconfig::libxml-2.0, cmake::CURL
29+
-- @param opt the argument options, e.g. { verbose = true, configdirs = {"lib"}}
30+
--
31+
function main(names, opt)
32+
local verbose
33+
if opt.verbose or option.get("verbose") or option.get("diagnosis") then
34+
verbose = true
35+
end
36+
for _, name in ipairs(names) do
37+
local kind
38+
local parts = name:split("::")
39+
if #parts == 2 then
40+
kind = parts[1]
41+
name = parts[2]
42+
end
43+
if kind == nil then
44+
kind = "pkgconfig"
45+
end
46+
if verbose then
47+
cprint("${dim}> checking for %s/%s", kind, name)
48+
end
49+
if kind == "pkgconfig" then
50+
opt.configdirs = opt.PKG_CONFIG_PATH
51+
local result = pkgconfig.libinfo(name, opt)
52+
if verbose and result then
53+
print(result)
54+
end
55+
if not result then
56+
return false, string.format("pkgconfig/%s.pc not found!", name)
57+
end
58+
elseif kind == "cmake" then
59+
if opt.CMAKE_PREFIX_PATH then
60+
opt.configs = opt.configs or {}
61+
opt.configs.envs = opt.configs.envs or {}
62+
opt.configs.envs.CMAKE_PREFIX_PATH = path.joinenv(table.wrap(opt.CMAKE_PREFIX_PATH))
63+
end
64+
local result = cmake_find_package(name, opt)
65+
if verbose and result then
66+
print(result)
67+
end
68+
if not result then
69+
return false, string.format("cmake/%s.cmake not found!", name)
70+
end
71+
end
72+
end
73+
return true
74+
end
75+

0 commit comments

Comments
 (0)