diff options
| author | ruki <[email protected]> | 2019-01-19 18:16:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-19 18:16:07 +0800 |
| commit | e3d5b1f0d7c8670ce88cee55b240309262798ac8 (patch) | |
| tree | 0e642970c30316747d8ad3565abf8d7a27024dc9 | |
| parent | 1d6190aa0a4697d11b9890a6f158ab4e91cd9bc2 (diff) | |
add builtin find_packages
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 24 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/find_packages.lua | 50 |
3 files changed, 72 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cc0e2641..891b00646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Remove some deprecated interfaces of xmake 1.x, e.g. `add_option_xxx` * [#327](https://github.com/tboox/xmake/issues/327): Support conan package manager for `lib.detect.find_package` * [#319](https://github.com/tboox/xmake/issues/319): Add `add_headerfiles` and `add_headerdirs` to improve to set header files and directories +* Improve `lib.detect.find_package` and add builtin `find_packages("zlib 1.x", "openssl", {xxx = ...})` api ### Bugs fixed @@ -564,6 +565,7 @@ * 移除xmake 1.x的一些废弃接口, 例如:`add_option_xxx` * [#327](https://github.com/tboox/xmake/issues/327): 改进`lib.detect.find_package`增加对conan包管理器的支持 * [#319](https://github.com/tboox/xmake/issues/319): 添加`add_headerfiles`和`add_headerdirs`接口去改进头文件的设置 +* 改进`lib.detect.find_package`并且添加内建的`find_packages("zlib 1.x", "openssl", {xxx = ...})`接口 ### Bugs修复 diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index ad12d1e63..4ede165e7 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -279,9 +279,17 @@ function target:set(name_or_info, ...) end end - -- set a dictionary values + -- set array, e.g. set({{links = ..}, {links = ..}}) + elseif table.is_array(name_or_info) then + for _, dict in pairs(name_or_info) do + for name, info in pairs(dict) do + self:set(name, info) + end + end + + -- set dictionary, e.g. set({links = ..}) elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do + for name, info in pairs(name_or_info) do self:set(name, info) end end @@ -316,9 +324,17 @@ function target:add(name_or_info, ...) end end - -- add a dictionary values + -- add array, e.g. add({{links = ..}, {links = ..}}) + elseif table.is_array(name_or_info) then + for _, dict in pairs(name_or_info) do + for name, info in pairs(dict) do + self:add(name, info) + end + end + + -- add dictionary, e.g. add({links = ..}) elseif table.is_dictionary(name_or_info) then - for name, info in pairs(table.join(name_or_info, ...)) do + for name, info in pairs(name_or_info) do self:add(name, info) end end diff --git a/xmake/core/sandbox/modules/find_packages.lua b/xmake/core/sandbox/modules/find_packages.lua new file mode 100644 index 000000000..d3116330b --- /dev/null +++ b/xmake/core/sandbox/modules/find_packages.lua @@ -0,0 +1,50 @@ +--!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 find_package.lua +-- + +-- return module +return function (...) + + -- get find_package + local find_package = require("sandbox/modules/import/lib/detect/find_package").main + + -- get packages and options + local pkgs = {...} + local opts = pkgs[#pkgs] + if type(opts) == "table" then + pkgs = table.slice(pkgs, 1, #pkgs - 1) + else + opts = {} + end + + -- find all packages + local packages = {} + for _, pkgname in ipairs(pkgs) do + local pkg = find_package(pkgname, opts) + if pkg then + table.insert(packages, pkg) + end + end + return packages +end + |
