From a25a4abc0169fdb613d38d5328641325d6964704 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Tue, 4 Feb 2025 11:30:03 +0300 Subject: [PATCH] llvm-rc: Fix regression on .rc sources with LLVM/Clang tooling Refactoring in commit 2b2344b412 (MSVC: Add abstraction for runtime checks, 2025-01-22) switched to using local compiler id variables to recognize compilers that target the MSVC ABI. However, those variables may be modified modified in a special case for `lang == "RC"` that does not apply to the ABI check. Check the target ABI before applying the special case. Fixes: #26663 --- Source/cmLocalGenerator.cxx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index f58078a18b..4d967cab08 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2125,12 +2125,17 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, } } - std::string compiler = this->Makefile->GetSafeDefinition( + std::string compilerId = this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_", lang, "_COMPILER_ID")); std::string compilerSimulateId = this->Makefile->GetSafeDefinition( cmStrCat("CMAKE_", lang, "_SIMULATE_ID")); + bool const compilerTargetsMsvcABI = + (compilerId == "MSVC" || compilerSimulateId == "MSVC"); + bool const compilerTargetsWatcomABI = + (compilerId == "OpenWatcom" || compilerSimulateId == "OpenWatcom"); + if (lang == "Swift") { if (cmValue v = target->GetProperty("Swift_LANGUAGE_VERSION")) { if (cmSystemTools::VersionCompare( @@ -2148,12 +2153,12 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, } else if (lang == "RC" && this->Makefile->GetSafeDefinition("CMAKE_RC_COMPILER") .find("llvm-rc") != std::string::npos) { - compiler = this->Makefile->GetSafeDefinition("CMAKE_C_COMPILER_ID"); - if (!compiler.empty()) { + compilerId = this->Makefile->GetSafeDefinition("CMAKE_C_COMPILER_ID"); + if (!compilerId.empty()) { compilerSimulateId = this->Makefile->GetSafeDefinition("CMAKE_C_SIMULATE_ID"); } else { - compiler = this->Makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"); + compilerId = this->Makefile->GetSafeDefinition("CMAKE_CXX_COMPILER_ID"); compilerSimulateId = this->Makefile->GetSafeDefinition("CMAKE_CXX_SIMULATE_ID"); } @@ -2162,7 +2167,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, } // Add VFS Overlay for Clang compilers - if (compiler == "Clang") { + if (compilerId == "Clang") { if (cmValue vfsOverlay = this->Makefile->GetDefinition("CMAKE_CLANG_VFS_OVERLAY")) { if (compilerSimulateId == "MSVC") { @@ -2193,7 +2198,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, "CMAKE_" + lang + "_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_" + msvcRuntimeLibrary)) { this->AppendCompileOptions(flags, *msvcRuntimeLibraryOptions); - } else if ((compiler == "MSVC" || compilerSimulateId == "MSVC") && + } else if (compilerTargetsMsvcABI && !cmSystemTools::GetErrorOccurredFlag()) { // The compiler uses the MSVC ABI so it needs a known runtime library. this->IssueMessage(MessageType::FATAL_ERROR, @@ -2221,8 +2226,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, "CMAKE_" + lang + "_COMPILE_OPTIONS_WATCOM_RUNTIME_LIBRARY_" + watcomRuntimeLibrary)) { this->AppendCompileOptions(flags, *watcomRuntimeLibraryOptions); - } else if ((compiler == "OpenWatcom" || - compilerSimulateId == "OpenWatcom") && + } else if (compilerTargetsWatcomABI && !cmSystemTools::GetErrorOccurredFlag()) { // The compiler uses the Watcom ABI so it needs a known runtime // library. @@ -2266,7 +2270,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, "CMAKE_", lang, "_COMPILE_OPTIONS_MSVC_RUNTIME_CHECKS_" + msvcRuntimeChecks))) { this->AppendCompileOptions(flags, *msvcRuntimeChecksOptions); - } else if ((compiler == "MSVC" || compilerSimulateId == "MSVC") && + } else if (compilerTargetsMsvcABI && !cmSystemTools::GetErrorOccurredFlag()) { // The compiler uses the MSVC ABI so it needs a known runtime checks. this->IssueMessage(MessageType::FATAL_ERROR, @@ -2287,7 +2291,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags, "_COMPILE_OPTIONS_MSVC_DEBUG_INFORMATION_FORMAT_", *msvcDebugInformationFormat))) { this->AppendCompileOptions(flags, *msvcDebugInformationFormatOptions); - } else if ((compiler == "MSVC" || compilerSimulateId == "MSVC") && + } else if (compilerTargetsMsvcABI && !cmSystemTools::GetErrorOccurredFlag()) { // The compiler uses the MSVC ABI so it needs a known runtime library. this->IssueMessage(MessageType::FATAL_ERROR,