Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for msvc toolset version overflow #15588

Merged
3 changes: 2 additions & 1 deletion conan/tools/cmake/toolchain/blocks.py
Expand Up @@ -697,7 +697,8 @@ def get_toolset(generator, conanfile):
compiler_update = str(settings.compiler.update)
if compiler_update != "None": # It is full one(19.28), not generic 19.2X
# The equivalent of compiler 19.26 is toolset 14.26
toolset = "version=14.{}{}".format(compiler_version[-1], compiler_update)
compiler_ver = int(compiler_version[-1]) * 10 + int(compiler_update)
toolset = "version=14.{}".format(compiler_ver)
else:
toolset = msvc_version_to_toolset_version(compiler_version)
elif compiler == "clang":
Expand Down
15 changes: 14 additions & 1 deletion conans/test/unittests/tools/cmake/test_cmaketoolchain.py
Expand Up @@ -198,7 +198,7 @@ def conanfile_msvc():
c = ConanFile(None)
c.settings = Settings({"os": ["Windows"],
"compiler": {"msvc": {"version": ["193"], "cppstd": ["20"],
"update": [None]}},
"update": ["ANY"]}},
"build_type": ["Release"],
"arch": ["x86"]})
c.settings.build_type = "Release"
Expand All @@ -223,6 +223,19 @@ def test_toolset(conanfile_msvc):
assert 'CMAKE_CXX_STANDARD 20' in toolchain.content


def test_toolset_update_version(conanfile_msvc):
conanfile_msvc.settings.compiler.update = "8"
toolchain = CMakeToolchain(conanfile_msvc)
assert 'set(CMAKE_GENERATOR_TOOLSET "version=14.38" CACHE STRING "" FORCE)' in toolchain.content


def test_toolset_update_version_overflow(conanfile_msvc):
# https://github.com/conan-io/conan/issues/15583
conanfile_msvc.settings.compiler.update = "10"
memsharded marked this conversation as resolved.
Show resolved Hide resolved
toolchain = CMakeToolchain(conanfile_msvc)
assert 'set(CMAKE_GENERATOR_TOOLSET "version=14.40" CACHE STRING "" FORCE)' in toolchain.content


def test_toolset_x64(conanfile_msvc):
# https://github.com/conan-io/conan/issues/11144
conanfile_msvc.conf.define("tools.cmake.cmaketoolchain:toolset_arch", "x64")
Expand Down