diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 8f9a2c85236..ca8a85e383b 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -879,6 +879,12 @@ def context(self): # To set CMAKE__COMPILER if comp in compilers_by_conf: compilers[lang] = compilers_by_conf[comp] + compiler = self._conanfile.settings.get_safe("compiler") + if compiler == "msvc" and "Ninja" in str(self._toolchain.generator): + # None of them defined, if one is defined by user, user should define the other too + if "c" not in compilers_by_conf and "cpp" not in compilers_by_conf: + compilers["C"] = "cl" + compilers["CXX"] = "cl" return {"compilers": compilers} diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index e5fed44cb05..a251caa70d0 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -231,6 +231,12 @@ def environment(self): # https://github.com/conan-io/conan/issues/13780 compiler = unix_path(self._conanfile, compiler) env.define(env_var, compiler) + compiler_setting = self._conanfile.settings.get_safe("compiler") + if compiler_setting == "msvc": + # None of them defined, if one is defined by user, user should define the other too + if "c" not in compilers_by_conf and "cpp" not in compilers_by_conf: + env.define("CC", "cl") + env.define("CXX", "cl") env.append("CPPFLAGS", ["-D{}".format(d) for d in self.defines]) env.append("CXXFLAGS", self.cxxflags) diff --git a/test/functional/toolchains/cmake/test_cmake_toolchain.py b/test/functional/toolchains/cmake/test_cmake_toolchain.py index f8592601199..de31d29aa1f 100644 --- a/test/functional/toolchains/cmake/test_cmake_toolchain.py +++ b/test/functional/toolchains/cmake/test_cmake_toolchain.py @@ -230,6 +230,8 @@ def test_cmake_toolchain_cmake_vs_debugger_environment(): f"$<$:{release_bindir}>" \ f"$<$:{minsizerel_bindir}>;%PATH%" assert debugger_environment in toolchain + + @pytest.mark.tool("cmake") def test_cmake_toolchain_cmake_vs_debugger_environment_not_needed(): client = TestClient() @@ -243,7 +245,6 @@ def test_cmake_toolchain_cmake_vs_debugger_environment_not_needed(): assert "CMAKE_VS_DEBUGGER_ENVIRONMENT" not in toolchain - @pytest.mark.tool("cmake") def test_cmake_toolchain_multiple_user_toolchain(): """ A consumer consuming two packages that declare: diff --git a/test/functional/toolchains/gnu/autotools/test_win_bash.py b/test/functional/toolchains/gnu/autotools/test_win_bash.py index d26647fced2..6a04132c3be 100644 --- a/test/functional/toolchains/gnu/autotools/test_win_bash.py +++ b/test/functional/toolchains/gnu/autotools/test_win_bash.py @@ -21,7 +21,6 @@ def test_autotools_bash_complete(): [conf] tools.microsoft.bash:subsystem=msys2 tools.microsoft.bash:path=bash - tools.build:compiler_executables={{"c": "cl", "cpp": "cl"}} """) main = gen_function_cpp(name="main") diff --git a/test/functional/toolchains/gnu/test_v2_autotools_template.py b/test/functional/toolchains/gnu/test_v2_autotools_template.py index d4ee48731f3..afd56049d6b 100644 --- a/test/functional/toolchains/gnu/test_v2_autotools_template.py +++ b/test/functional/toolchains/gnu/test_v2_autotools_template.py @@ -352,7 +352,6 @@ def test_msys2_autotools_windows(self): [conf] tools.microsoft.bash:subsystem=msys2 tools.microsoft.bash:path=bash - tools.build:compiler_executables={"c": "cl", "cpp": "cl"} """) c.save({"msys2": msys2}) # FIXME: Need to deactivate test_package because AutotoolsDeps doesn't work in Win @@ -369,7 +368,6 @@ def test_msys2_autotools_exe_windows(self): [conf] tools.microsoft.bash:subsystem=msys2 tools.microsoft.bash:path=bash - tools.build:compiler_executables={"c": "cl", "cpp": "cl"} """) c.save({"msys2": msys2}) c.run("create . -pr=msys2")