diff options
| author | xq114 <[email protected]> | 2023-02-16 13:53:47 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2023-02-16 13:53:47 +0800 |
| commit | 08eac51e8874519707627a0d79809ac8cd60a9f5 (patch) | |
| tree | c3a5524d2f58539db81938020cac5ff8a08035e4 | |
| parent | 7fd2cec12bf091a8695fa50009e7399447f4622d (diff) | |
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 | 38 |
2 files changed, 84 insertions, 8 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..ec38dd99d 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,21 +401,39 @@ 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 function install(package, configs, opt) - -- generate build files + -- generate build files and build opt = opt or {} generate(package, configs, opt) + build(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 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 |
