From 623add4344bf5e5d29b116356de7d398c2ddec2f Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 17 Jul 2019 18:21:48 +0800 Subject: add auto detect vs version --- xmake/plugins/project/main.lua | 21 ++++++++++++++++++++- xmake/plugins/project/vstudio/impl/vsinfo.lua | 2 +- xmake/plugins/project/vsxmake/vsxmake.lua | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/project/main.lua b/xmake/plugins/project/main.lua index d2ce39a10..ede6989fb 100755 --- a/xmake/plugins/project/main.lua +++ b/xmake/plugins/project/main.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.task") +import("core.project.config") import("core.platform.environment") import("make.makefile") import("cmake.cmakelists") @@ -30,6 +31,22 @@ import("vsxmake.vsxmake") import("clang.compile_flags") import("clang.compile_commands") +function _vs(outputdir) + local vsver = assert(tonumber(config.get("vs")), "invalid vs version, run `xmake f --vs=2015`") + vprint("using project kind vs%d", vsver) + if vsver < 2010 then + return vs.make(vsver)(outputdir) + else + return vsx.make(vsver)(outputdir) + end +end + +function _vsxmake(outputdir) + local vsver = assert(tonumber(config.get("vs")), "invalid vs version, run `xmake f --vs=2015`") + vprint("using project kind vsxmake%d", vsver) + return vsxmake.make(vsver)(outputdir) +end + -- make project function _make(kind) @@ -48,17 +65,19 @@ function _make(kind) , vs2015 = vsx.make(2015) , vs2017 = vsx.make(2017) , vs2019 = vsx.make(2019) + , vs = _vs , vsxmake2010 = vsxmake.make(2010) , vsxmake2012 = vsxmake.make(2012) , vsxmake2013 = vsxmake.make(2013) , vsxmake2015 = vsxmake.make(2015) , vsxmake2017 = vsxmake.make(2017) , vsxmake2019 = vsxmake.make(2019) + , vsxmake = _vsxmake , compile_flags = compile_flags.make , compile_commands = compile_commands.make } assert(maps[kind], "the project kind(%s) is not supported!", kind) - + -- make it maps[kind](option.get("outputdir")) end diff --git a/xmake/plugins/project/vstudio/impl/vsinfo.lua b/xmake/plugins/project/vstudio/impl/vsinfo.lua index 3da30d398..bd512a775 100644 --- a/xmake/plugins/project/vstudio/impl/vsinfo.lua +++ b/xmake/plugins/project/vstudio/impl/vsinfo.lua @@ -89,5 +89,5 @@ local vsinfo = function main(version) assert(version) - return assert(vsinfo[version]); + return assert(vsinfo[version], "unsupported vs version (%d)", version); end \ No newline at end of file diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 424d30256..3443563a9 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -129,6 +129,11 @@ end -- make function make(version) + -- check + if version < 2010 then + raise("vsxmake does not support vs version lower than 2010") + end + return function(outputdir) local info = getinfo(outputdir, vsinfo(version)) local paramsprovidersln = _buildparams(info) -- cgit v1.3.1