diff options
| author | xq114 <[email protected]> | 2021-05-25 15:06:04 +0800 |
|---|---|---|
| committer | xq114 <[email protected]> | 2021-05-25 15:06:04 +0800 |
| commit | ccd1de7efef16a5a63033c6e75ed0ff522326ecd (patch) | |
| tree | 3fc64ef156ebb93e5ccbeb8f991f6dd63d91b2ed | |
| parent | b54871bfdd16eb87546fea49c1413068636c3ae4 (diff) | |
improve package.tools.meson on windows
| -rw-r--r-- | xmake/modules/package/tools/meson.lua | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/xmake/modules/package/tools/meson.lua b/xmake/modules/package/tools/meson.lua index 2f64e1554..ebfdce69a 100644 --- a/xmake/modules/package/tools/meson.lua +++ b/xmake/modules/package/tools/meson.lua @@ -41,6 +41,19 @@ function _get_configs(package, configs, opt) local configs = configs or {} table.insert(configs, "--prefix=" .. package:installdir()) + -- set build type + table.insert(configs, "--buildtype=" .. (package:debug() and "debug" or "release")) + + -- add -fpic + if package:is_plat("linux") and package:config("pic") then + table.insert(configs, "-Db_staticpic=true") + end + + -- add vs_runtime flags + if package:is_plat("windows") then + table.insert(configs, "-Db_vscrt=" .. (package:config("vs_runtime"):startswith("MT") and "mt" or "md")) + end + -- add build directory table.insert(configs, _get_buildir(opt)) return configs @@ -58,6 +71,13 @@ function _get_msvc_runenvs(package) return _get_msvc(package):runenvs() end +-- fix libname on windows +function _fix_libname_on_windows(package) + for _, lib in ipairs(os.files(path.join(package:installdir("lib"), "lib*.a"))) do + os.mv(lib, lib:gsub("(.+)lib(.-)%.a", "%1%2.lib")) + end +end + -- get the build environments function buildenvs(package) local envs = {} @@ -68,7 +88,13 @@ function buildenvs(package) envs.CXXFLAGS = table.concat(cxxflags, ' ') envs.ASFLAGS = table.concat(table.wrap(package:config("asflags")), ' ') if package:is_plat("windows") then - table.join2(envs, _get_msvc_runenvs(package)) + for name, values in pairs(_get_msvc_runenvs(package)) do + local oldvalues = os.getenv(name) + if oldvalues then + values = values .. path.envsep() .. oldvalues + end + envs[name] = values + end end else local cflags = table.join(table.wrap(package:build_getenv("cxflags")), package:build_getenv("cflags")) @@ -153,4 +179,9 @@ function install(package, configs, opt) -- do build and install local buildir = _get_buildir(opt) ninja.install(package, {}, {buildir = buildir, envs = opt.envs or buildenvs(package, opt)}) + + -- fix static libname on windows + if package:is_plat("windows") and not package:config("shared") then + _fix_libname_on_windows(package) + end end |
