diff --git a/conan/tools/microsoft/toolchain.py b/conan/tools/microsoft/toolchain.py index 5e33d51030c..f7fb6214ca1 100644 --- a/conan/tools/microsoft/toolchain.py +++ b/conan/tools/microsoft/toolchain.py @@ -7,7 +7,7 @@ from conan.internal import check_duplicated_generator from conan.tools.build import build_jobs from conan.tools.intel.intel_cc import IntelCC -from conan.tools.microsoft.visual import VCVars, msvs_toolset +from conan.tools.microsoft.visual import VCVars, msvs_toolset, msvc_runtime_flag from conan.errors import ConanException from conans.util.files import save, load @@ -67,7 +67,7 @@ def __init__(self, conanfile): #: The build type. By default, the ``conanfile.settings.build_type`` value self.configuration = conanfile.settings.build_type #: The runtime flag. By default, it'll be based on the `compiler.runtime` setting. - self.runtime_library = self._runtime_library(conanfile.settings) + self.runtime_library = self._runtime_library() #: cppstd value. By default, ``compiler.cppstd`` one. self.cppstd = conanfile.settings.get_safe("compiler.cppstd") self.cstd = conanfile.settings.get_safe("compiler.cstd") @@ -107,24 +107,13 @@ def generate(self): else: VCVars(self._conanfile).generate() - @staticmethod - def _runtime_library(settings): - compiler = settings.compiler - runtime = settings.get_safe("compiler.runtime") - if compiler == "msvc" or compiler == "intel-cc": - build_type = settings.get_safe("build_type") - if build_type != "Debug": - runtime_library = {"static": "MultiThreaded", - "dynamic": "MultiThreadedDLL"}.get(runtime, "") - else: - runtime_library = {"static": "MultiThreadedDebug", - "dynamic": "MultiThreadedDebugDLL"}.get(runtime, "") - else: - runtime_library = {"MT": "MultiThreaded", - "MTd": "MultiThreadedDebug", - "MD": "MultiThreadedDLL", - "MDd": "MultiThreadedDebugDLL"}.get(runtime, "") - return runtime_library + def _runtime_library(self): + return { + "MT": "MultiThreaded", + "MTd": "MultiThreadedDebug", + "MD": "MultiThreadedDLL", + "MDd": "MultiThreadedDebugDLL", + }.get(msvc_runtime_flag(self._conanfile), "") @property def context_config_toolchain(self): diff --git a/test/integration/toolchains/microsoft/test_msbuild_toolchain.py b/test/integration/toolchains/microsoft/test_msbuild_toolchain.py index 05574dfc0a8..4c3366415e1 100644 --- a/test/integration/toolchains/microsoft/test_msbuild_toolchain.py +++ b/test/integration/toolchains/microsoft/test_msbuild_toolchain.py @@ -2,22 +2,30 @@ import textwrap import pytest -from parameterized import parameterized from conan.test.utils.tools import TestClient -@parameterized.expand([("msvc", "190", "dynamic"), - ("msvc", "191", "static")] - ) -@pytest.mark.tool("visual_studio") @pytest.mark.skipif(platform.system() != "Windows", reason="Only for windows") -def test_toolchain_win(compiler, version, runtime): +@pytest.mark.tool("visual_studio") +@pytest.mark.tool("clang", "16") +@pytest.mark.parametrize( + "compiler, version", + [ + ("msvc", "190"), + ("msvc", "191"), + ("clang", "16") + ], +) +@pytest.mark.parametrize("runtime", ["dynamic", "static"]) +@pytest.mark.parametrize("runtime_type", ["Release", "Debug"]) +def test_toolchain_win(compiler, version, runtime, runtime_type): client = TestClient(path_with_spaces=False) settings = {"compiler": compiler, "compiler.version": version, "compiler.cppstd": "14", "compiler.runtime": runtime, + "compiler.runtime_type": runtime_type, "build_type": "Release", "arch": "x86_64"} @@ -39,11 +47,20 @@ def generate(self): props = client.load("conantoolchain_release_x64.props") assert "true" in props assert "stdcpp14" in props - if version == "190": - assert "v140" in props - else: - assert "v141" in props + if compiler == "msvc": + if version == "190": + assert "v140" in props + elif version == "191": + assert "v141" in props + elif compiler == "clang": + assert "ClangCl" in props if runtime == "dynamic": - assert "MultiThreadedDLL" in props + if runtime_type == "Release": + assert "MultiThreadedDLL" in props + else: + assert "MultiThreadedDebugDLL" in props else: - assert "MultiThreaded" in props + if runtime_type == "Release": + assert "MultiThreaded" in props + else: + assert "MultiThreadedDebug" in props