summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-10 23:45:37 +0800
committerruki <[email protected]>2025-09-10 23:45:37 +0800
commit47d5aff2085590620041c00091484e4edda9f9f3 (patch)
treee8090de390b770f1f5ce3ec4c47d383473b89d4e
parent3844210dfaee545890a72e190d8c3585c512c2d8 (diff)
improve vs version
-rw-r--r--xmake/modules/package/manager/conan/v1/install_package.lua12
-rw-r--r--xmake/modules/package/tools/cmake.lua13
-rw-r--r--xmake/modules/private/action/trybuild/cmake.lua13
-rw-r--r--xmake/modules/private/utils/toolchain.lua15
4 files changed, 19 insertions, 34 deletions
diff --git a/xmake/modules/package/manager/conan/v1/install_package.lua b/xmake/modules/package/manager/conan/v1/install_package.lua
index 22bdb0bfd..d96727eb7 100644
--- a/xmake/modules/package/manager/conan/v1/install_package.lua
+++ b/xmake/modules/package/manager/conan/v1/install_package.lua
@@ -27,6 +27,7 @@ import("core.platform.platform")
import("lib.detect.find_tool")
import("devel.git")
import("net.fasturl")
+import("private.utils.toolchain", {alias = "toolchain_utils"})
-- get build env
function _conan_get_build_env(name, plat)
@@ -197,20 +198,11 @@ function main(conan, name, opt)
-- set compiler settings
if opt.plat == "windows" then
- local vsvers = {["2022"] = "17",
- ["2019"] = "16",
- ["2017"] = "15",
- ["2015"] = "14",
- ["2013"] = "12",
- ["2012"] = "11",
- ["2010"] = "10",
- ["2008"] = "9",
- ["2005"] = "8"}
local vs = assert(config.get("vs"), "vs not found!")
table.insert(argv, "-s")
table.insert(argv, "compiler=Visual Studio")
table.insert(argv, "-s")
- table.insert(argv, "compiler.version=" .. assert(vsvers[vs], "unknown msvc version!"))
+ table.insert(argv, "compiler.version=" .. toolchain_utils.get_vsver(vs))
if configs.runtimes then
table.insert(argv, "-s")
table.insert(argv, "compiler.runtime=" .. configs.runtimes)
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index 21eed5392..cbf9bcb37 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -764,20 +764,9 @@ end
-- get cmake generator for msvc
function _get_cmake_generator_for_msvc(package)
- local vsvers =
- {
- ["2022"] = "17",
- ["2019"] = "16",
- ["2017"] = "15",
- ["2015"] = "14",
- ["2013"] = "12",
- ["2012"] = "11",
- ["2010"] = "10",
- ["2008"] = "9"
- }
local vs = _get_msvc(package):config("vs") or config.get("vs")
assert(vsvers[vs], "Unknown Visual Studio version: '" .. tostring(vs) .. "' set in project.")
- return "Visual Studio " .. vsvers[vs] .. " " .. vs
+ return "Visual Studio " .. toolchain_utils.get_vsver(vs) .. " " .. vs
end
-- get configs for cmake generator
diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua
index 2957231ad..377c9c66e 100644
--- a/xmake/modules/private/action/trybuild/cmake.lua
+++ b/xmake/modules/private/action/trybuild/cmake.lua
@@ -395,20 +395,9 @@ end
-- get cmake generator for msvc
function _get_cmake_generator_for_msvc()
- local vsvers =
- {
- ["2022"] = "17",
- ["2019"] = "16",
- ["2017"] = "15",
- ["2015"] = "14",
- ["2013"] = "12",
- ["2012"] = "11",
- ["2010"] = "10",
- ["2008"] = "9"
- }
local vs = _get_msvc():config("vs") or config.get("vs")
assert(vsvers[vs], "Unknown Visual Studio version: '" .. tostring(vs) .. "' set in project.")
- return "Visual Studio " .. vsvers[vs] .. " " .. vs
+ return "Visual Studio " .. toolchain_utils.get_vsver(vs) .. " " .. vs
end
-- get configs for cmake generator
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua
index 8fbd5c111..da2e9febf 100644
--- a/xmake/modules/private/utils/toolchain.lua
+++ b/xmake/modules/private/utils/toolchain.lua
@@ -35,6 +35,21 @@ function is_compatible_with_host(name)
end
end
+-- get vs version
+function get_vsver(vs)
+ local vsvers = {["2026"] = "18",
+ ["2022"] = "17",
+ ["2019"] = "16",
+ ["2017"] = "15",
+ ["2015"] = "14",
+ ["2013"] = "12",
+ ["2012"] = "11",
+ ["2010"] = "10",
+ ["2008"] = "9",
+ ["2005"] = "8"}
+ return assert(vsvers[vs], "unknown msvc version!")
+end
+
-- get vs toolset version, e.g. v143, v144, ..
function get_vs_toolset_ver(vs_toolset)
local toolset_ver