Skip to content

Commit

Permalink
fix CMakeToolchain GENERATOR_TOOLSET for updates (#15789)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Mar 1, 2024
1 parent 1c43157 commit 32a6cbd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
5 changes: 2 additions & 3 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,10 @@ def get_toolset(generator, conanfile):
if toolset is None:
compiler_version = str(settings.compiler.version)
compiler_update = str(settings.compiler.update)
toolset = msvc_version_to_toolset_version(compiler_version)
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)
else:
toolset = msvc_version_to_toolset_version(compiler_version)
toolset += ",version=14.{}{}".format(compiler_version[-1], compiler_update)
elif compiler == "clang":
if generator and "Visual" in generator:
if "Visual Studio 16" in generator or "Visual Studio 17" in generator:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ def test_cmake_toolchain_win_toolset(compiler, version, update, runtime):
client.save({"conanfile.py": conanfile})
client.run("install . {}".format(settings))
toolchain = client.load("conan_toolchain.cmake")
value = "v14{}".format(version[-1])
if update is not None: # Fullversion
value = "version=14.{}{}".format(version[-1], update)
else:
value = "v14{}".format(version[-1])
value += f",version=14.{version[-1]}{update}"
assert 'set(CMAKE_GENERATOR_TOOLSET "{}" CACHE STRING "" FORCE)'.format(value) in toolchain


Expand Down Expand Up @@ -76,8 +75,7 @@ def test_cmake_toolchain_custom_toolchain():
reason="Single config test, Linux CI still without 3.23")
@pytest.mark.tool("cmake", "3.23")
@pytest.mark.parametrize("existing_user_presets", [None, "user_provided", "conan_generated"])
@pytest.mark.parametrize("schema2", [True, False])
def test_cmake_user_presets_load(existing_user_presets, schema2):
def test_cmake_user_presets_load(existing_user_presets):
"""
Test if the CMakeUserPresets.cmake is generated and use CMake to use it to verify the right
syntax of generated CMakeUserPresets.cmake and CMakePresets.cmake. If the user already provided
Expand Down
26 changes: 26 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ def test_older_msvc_toolset():
assert 'CMAKE_CXX_STANDARD 98' in content


def test_older_msvc_toolset_update():
# https://github.com/conan-io/conan/issues/15787
c = ConanFile(None)
c.settings = Settings({"os": ["Windows"],
"compiler": {"msvc": {"version": ["192"], "update": [8, 9],
"cppstd": ["14"]}},
"build_type": ["Release"],
"arch": ["x86_64"]})
c.settings.build_type = "Release"
c.settings.arch = "x86_64"
c.settings.compiler = "msvc"
c.settings.compiler.version = "192"
c.settings.compiler.update = 9
c.settings.compiler.cppstd = "14"
c.settings.os = "Windows"
c.settings_build = c.settings
c.conf = Conf()
c.folders.set_base_generators(".")
c._conan_node = Mock()
c._conan_node.dependencies = []
c._conan_node.transitive_deps = {}
toolchain = CMakeToolchain(c)
content = toolchain.content
assert 'CMAKE_GENERATOR_TOOLSET "v142,version=14.29"' in content


def test_msvc_xp_toolsets():
c = ConanFile(None)
c.settings = Settings({"os": ["Windows"],
Expand Down

0 comments on commit 32a6cbd

Please sign in to comment.