diff options
| author | ruki <[email protected]> | 2023-02-16 18:24:45 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-16 18:24:45 +0800 |
| commit | 6800854f448ab11095f354c59bbdc7ab7f935c55 (patch) | |
| tree | a58bc365362e94a9060b0adc89163162d19a1aee | |
| parent | 6015ba5e5b254ebab40a8222e2d857a9af4df1c2 (diff) | |
| parent | 559ecc3c028a176bdacb4b2e937ab6da9c9f5c4d (diff) | |
Merge pull request #3370 from xq114/dev
improve meson for flexible build
| -rw-r--r-- | xmake/modules/detect/tools/find_meson.lua | 54 | ||||
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 35 |
2 files changed, 82 insertions, 7 deletions
diff --git a/xmake/modules/detect/tools/find_meson.lua b/xmake/modules/detect/tools/find_meson.lua new file mode 100644 index 000000000..e85f537d5 --- /dev/null +++ b/xmake/modules/detect/tools/find_meson.lua @@ -0,0 +1,54 @@ +--!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 xq114 +-- @file find_meson.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find meson +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local meson = find_meson() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "meson", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end + diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 95f777fde..f99e20c77 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -24,7 +24,6 @@ import("core.project.config") import("core.tool.toolchain") import("core.tool.linker") import("core.tool.compiler") -import("package.tools.ninja") import("lib.detect.find_tool") -- get build directory @@ -55,6 +54,9 @@ function _is_cross_compilation(package) if package:is_plat("macosx") and not package:is_arch(os.subarch()) then return true end + if package:is_plat("windows") and package:is_arch("arm64") then + return true + end return false end @@ -374,7 +376,8 @@ function generate(package, configs, opt) opt = opt or {} -- pass configurations - local argv = {} + -- TODO: support more backends https://mesonbuild.com/Commands.html#setup + local argv = {"setup"} for name, value in pairs(_get_configs(package, configs, opt)) do value = tostring(value):trim() if value ~= "" then @@ -387,7 +390,8 @@ function generate(package, configs, opt) end -- do configure - os.vrunv("meson", argv, {envs = opt.envs or buildenvs(package, opt)}) + local meson = assert(find_tool("meson"), "meson not found!") + os.vrunv(meson, argv, {envs = opt.envs or buildenvs(package, opt)}) end -- build package @@ -397,9 +401,19 @@ function build(package, configs, opt) opt = opt or {} generate(package, configs, opt) - -- do build + -- configurate build local buildir = _get_buildir(package, opt) - ninja.build(package, {}, {buildir = buildir, envs = opt.envs or buildenvs(package, opt)}) + local njob = opt.jobs or option.get("jobs") or tostring(os.default_njob()) + local argv = {"compile", "-C", buildir} + if option.get("diagnosis") then + table.insert(argv, "-v") + end + table.insert(argv, "-j") + table.insert(argv, njob) + + -- do build + local meson = assert(find_tool("meson"), "meson not found!") + os.vrunv(meson, argv, {envs = opt.envs or buildenvs(package, opt)}) end -- install package @@ -409,9 +423,16 @@ function install(package, configs, opt) opt = opt or {} generate(package, configs, opt) - -- do build and install + -- configure install local buildir = _get_buildir(package, opt) - ninja.install(package, {}, {buildir = buildir, envs = opt.envs or buildenvs(package, opt)}) + local argv = {"install", "-C", buildir} + if option.get("verbose") then + table.insert(argv, "-v") + end + + -- do build and install + local meson = assert(find_tool("meson"), "meson not found!") + os.vrunv(meson, {"install", "-C", buildir}, {envs = opt.envs or buildenvs(package, opt)}) -- fix static libname on windows if package:is_plat("windows") and not package:config("shared") then |
