|
| 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