diff options
| author | ruki <[email protected]> | 2020-06-21 16:32:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-21 16:32:17 +0800 |
| commit | bf2a6694133db7b795b71e06e5a7162b21b5e26f (patch) | |
| tree | 84f53941faf34b7da4cc710322f40d4b4ea7ceea /xmake/modules | |
| parent | b983c94fcda0e069e906f4dd46d1d19726780843 (diff) | |
improve to call msbuild
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/detect/tools/find_msbuild.lua | 55 | ||||
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/cmake.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/msbuild.lua | 11 |
4 files changed, 78 insertions, 7 deletions
diff --git a/xmake/modules/detect/tools/find_msbuild.lua b/xmake/modules/detect/tools/find_msbuild.lua new file mode 100644 index 000000000..38d83c5ab --- /dev/null +++ b/xmake/modules/detect/tools/find_msbuild.lua @@ -0,0 +1,55 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_msbuild.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find msbuild +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local msbuild = find_msbuild() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.check = "/version" + + -- find program + local program = find_program(opt.program or "msbuild.exe", 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/cmake.lua b/xmake/modules/package/tools/cmake.lua index 7299f20b4..f35b489b4 100644 --- a/xmake/modules/package/tools/cmake.lua +++ b/xmake/modules/package/tools/cmake.lua @@ -20,7 +20,9 @@ -- imports import("core.base.option") +import("core.tool.toolchain") import("lib.detect.find_file") +import("lib.detect.find_tool") -- get configs function _get_configs(package, configs) @@ -118,10 +120,12 @@ function install(package, configs, opt) -- do build and install if package:is_plat("windows") then local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.vrun("msbuild \"%s\" -nologo -t:Rebuild -p:Configuration=%s -p:Platform=%s", slnfile, package:debug() and "Debug" or "Release", package:is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc", {plat = package:plat(), arch = package:arch()}):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vrunv(msbuild.program, {slnfile, "-nologo", "-t:Rebuild", "-p:Configuration=" .. (package:debug() and "Debug" or "Release"), "-p:Platform=" .. (package:is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" if os.isfile(projfile) then - os.vrun("msbuild \"%s\" /property:configuration=%s", projfile, package:debug() and "Debug" or "Release") + os.vrunv(msbuild.program, {projfile, "/property:configuration=" .. (package:debug() and "Debug" or "Release")}, {envs = runenvs}) os.trycp("install/lib", package:installdir()) -- perhaps only headers library os.cp("install/include", package:installdir()) else diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index d5e0cbce2..684941c39 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -22,6 +22,7 @@ import("core.base.cli") import("core.base.option") import("core.project.config") +import("core.tool.toolchain") import("lib.detect.find_file") import("lib.detect.find_tool") @@ -76,7 +77,9 @@ function clean() if configfile then local oldir = os.cd(buildir) if is_plat("windows") then - os.vexec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=%s -p:Platform=%s", configfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Clean", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) else os.vexec("make clean") end @@ -107,11 +110,13 @@ function build() -- do build if is_plat("windows") then + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") - os.vexec("msbuild \"%s\" -nologo -t:Build -p:Configuration=%s -p:Platform=%s", slnfile, is_mode("debug") and "Debug" or "Release", is_arch("x64") and "x64" or "Win32") + os.vexecv(msbuild.program, {slnfile, "-nologo", "-t:Build", "-p:Configuration=" .. (is_mode("debug") and "Debug" or "Release"), "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) local projfile = os.isfile("INSTALL.vcxproj") and "INSTALL.vcxproj" or "INSTALL.vcproj" if os.isfile(projfile) then - os.vexec("msbuild \"%s\" /property:configuration=%s", projfile, is_mode("debug") and "Debug" or "Release") + os.vexecv(msbuild.program, {projfile, "/property:configuration=" .. (is_mode("debug") and "Debug" or "Release")}, {envs = runenvs}) end else local argv = {"-j" .. option.get("jobs")} diff --git a/xmake/modules/private/action/trybuild/msbuild.lua b/xmake/modules/private/action/trybuild/msbuild.lua index 0cd00fef9..e86830900 100644 --- a/xmake/modules/private/action/trybuild/msbuild.lua +++ b/xmake/modules/private/action/trybuild/msbuild.lua @@ -21,7 +21,9 @@ -- imports import("core.base.option") import("core.project.config") +import("core.tool.toolchain") import("lib.detect.find_file") +import("lib.detect.find_tool") -- detect build-system and configuration file function detect() @@ -32,7 +34,9 @@ end -- do clean function clean() - os.vexec("msbuild \"%s\" -nologo -t:Clean -p:Configuration=Release -p:Platform=%s", configfile, is_arch("x64") and "x64" or "Win32") + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Clean", "-p:Configuration=Release", "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) end -- do build @@ -42,6 +46,9 @@ function build() assert(is_subhost(config.plat()), "msbuild: %s not supported!", config.plat()) -- do build - os.vexec("msbuild \"%s\" -nologo -t:Build -p:Configuration=Release -p:Platform=%s", configfile, is_arch("x64") and "x64" or "Win32") + local configfile = find_file("*.sln", os.curdir()) + local runenvs = toolchain.load("msvc"):runenvs() + local msbuild = find_tool("msbuild", {envs = runenvs}) + os.vexecv(msbuild.program, {configfile, "-nologo", "-t:Build", "-p:Configuration=Release", "-p:Platform=" .. (is_arch("x64") and "x64" or "Win32")}, {envs = runenvs}) cprint("${color.success}build ok!") end |
