diff options
| author | ruki <[email protected]> | 2019-01-12 22:44:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-12 22:44:41 +0800 |
| commit | 80629131183b4fe1c3587f11fa80707979b18538 (patch) | |
| tree | 2eac5e5626ad05e384070610171e6ee744b30460 /xmake/modules/lib | |
| parent | a1afc21b797df768331f7aff6f4b82f0f896700b (diff) | |
support conan for lib.detect.find_package
Diffstat (limited to 'xmake/modules/lib')
| -rw-r--r-- | xmake/modules/lib/detect/conan.lua | 151 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/vcpkg.lua | 5 |
2 files changed, 154 insertions, 2 deletions
diff --git a/xmake/modules/lib/detect/conan.lua b/xmake/modules/lib/detect/conan.lua new file mode 100644 index 000000000..4660e0670 --- /dev/null +++ b/xmake/modules/lib/detect/conan.lua @@ -0,0 +1,151 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file conan.lua +-- + +-- imports +import("lib.detect.find_file") +import("lib.detect.find_library") +import("detect.sdks.find_conandir") +import("core.project.config") +import("core.project.target") + +-- get package info +-- +-- @param name the package name +-- @param opt the argument options, {version = true, arch = "", plat = "", mode = "", conandir = ""} +-- +-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {""}, includedirs = {""}, version = ""} +-- +-- @code +-- +-- local pkginfo = conan.info("openssl") +-- +-- @endcode +-- +function info(name, opt) + + -- init options + opt = opt or {} + + -- attempt to find the conan root directory + local conandir = find_conandir(opt.conandir) + if not conandir then + return + end + + -- init cache + _g._INFO = _g._INFO or {} + + -- get it from cache first + local key = name + local result = _g._INFO[key] + if result ~= nil then + return result and result or nil + end + + -- find the package conanmanifest file, .e.g ~/.conan/data/pcre2/10.31/bincrafters/stable/package/519f362e9832d00859a5da6d5f76da34ecf8e237/conanmanifest.txt + local manifestfile = find_file("conanmanifest.txt", path.join(conandir, "data", name, "*", "*", "*", "package", "*")) + + -- save includedirs, linkdirs and links + local info = manifestfile and io.readfile(manifestfile) or nil + if info then + local installdir = path.directory(manifestfile) + result = {includedirs = path.join(installdir, "include"), linkdirs = path.join(installdir, "lib")} + for _, line in ipairs(info:split('\n')) do + line = line:split(':')[1]:trim() + if line:startswith("lib") and (line:endswith(".lib") or line:endswith(".a")) then + result.links = result.links or {} + table.insert(result.links, target.linkname(path.filename(line))) + end + end + end + + -- save version + if result and manifestfile then + result.version = manifestfile:match(path.join(name, "(%d+%.?%d*%.?%d*.-)")) + if not result.version then + result.version = manifestfile:match(path.join(name, "(%d+%.?%d*%.-)")) + end + end + + -- save result to cache + _g._INFO[key] = result and result or false + + -- ok? + return result +end + +-- find package +-- +-- @param name the package name +-- @param opt the argument options, {version = "1.0.1", links = {...}, conandir = ""} +-- +-- @return {links = {"ssl", "crypto", "z"}, linkdirs = {""}, includedirs = {""}} +-- +-- @code +-- +-- local pkginfo = conan.find("openssl") +-- +-- @endcode +-- +function find(name, opt) + + -- get package info + local pkginfo = info(name, opt) + if not pkginfo then + return + end + + -- match version? + opt = opt or {} + if opt.version and pkginfo.version ~= opt.version then + return + end + + -- get links + local links = pkginfo.links + if not links or #links == 0 then + links = opt.links + end + + -- find library + local result = nil + for _, link in ipairs(table.wrap(links)) do + local libinfo = find_library(link, pkginfo.linkdirs) + if libinfo then + result = result or {} + result.links = table.join(result.links or {}, libinfo.link) + result.linkdirs = table.join(result.linkdirs or {}, libinfo.linkdir) + end + end + + -- found? + if result and result.links then + result.linkdirs = table.unique(result.linkdirs) + result.includedirs = table.join(result.includedirs or {}, pkginfo.includedirs) + end + + -- ok? + return result +end + diff --git a/xmake/modules/lib/detect/vcpkg.lua b/xmake/modules/lib/detect/vcpkg.lua index 56763d9c0..573830fef 100644 --- a/xmake/modules/lib/detect/vcpkg.lua +++ b/xmake/modules/lib/detect/vcpkg.lua @@ -27,6 +27,7 @@ import("lib.detect.find_file") import("lib.detect.find_library") import("detect.sdks.find_vcpkgdir") import("core.project.config") +import("core.project.target") -- get package info -- @@ -96,14 +97,14 @@ function info(name, opt) result.links = result.links or {} result.linkdirs = result.linkdirs or {} table.insert(result.linkdirs, path.join(installdir, path.directory(line))) - table.insert(result.links, path.basename(line)) + table.insert(result.links, target.linkname(path.filename(line))) end end end end -- save version - if opt.version then + if result then local infoname = path.basename(infofile) result.version = infoname:match(name .. "_(%d+%.?%d*%.?%d*.-)_" .. arch) if not result.version then |
