1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 14:08:35 +08:00

FASTBuild: fix CMake build with clang-cl

Fixes: #27175
This commit is contained in:
Eduard Voronkin
2025-09-02 21:45:33 -07:00
parent 1dfe9898e6
commit 888e9e1081
3 changed files with 20 additions and 8 deletions

View File

@@ -158,9 +158,15 @@ macro(__enable_llvm_rc_preprocessing clang_option_prefix extra_pp_flags)
endif()
if(DEFINED CMAKE_RC_PREPROCESSOR)
set(CMAKE_DEPFILE_FLAGS_RC "${clang_option_prefix}-MD ${clang_option_prefix}-MF ${clang_option_prefix}<DEP_FILE>")
# llvm-rc runs preprocessor starting from LLVM-13, so we can run it directly instead of using "cmake_llvm_rc".
# See https://reviews.llvm.org/D100755 for more details.
if (CMAKE_GENERATOR MATCHES "FASTBuild")
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> <FLAGS> /fo<OBJECT> <SOURCE>")
else()
# The <FLAGS> are passed to the preprocess and the resource compiler to pick
# up the eventual -D / -C options passed through the CMAKE_RC_FLAGS.
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_COMMAND> -E cmake_llvm_rc <SOURCE> <OBJECT>.pp <${CMAKE_RC_PREPROCESSOR}> <DEFINES> -DRC_INVOKED <INCLUDES> <FLAGS> ${extra_pp_flags} -E -- <SOURCE> ++ <CMAKE_RC_COMPILER> <DEFINES> -I <SOURCE_DIR> <INCLUDES> <FLAGS> /fo <OBJECT> <OBJECT>.pp")
endif()
if(CMAKE_GENERATOR MATCHES "Ninja")
set(CMAKE_NINJA_CMCLDEPS_RC 0)
set(CMAKE_NINJA_DEP_TYPE_RC gcc)

View File

@@ -434,10 +434,11 @@ macro(__windows_compiler_msvc lang)
# macOS paths usually start with /Users/*. Unfortunately, clang-cl interprets
# paths starting with /U as macro undefines, so we need to put a -- before the
# input file path to force it to be treated as a path.
if(NOT CMAKE_GENERATOR MATCHES "FASTBuild")
string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_COMPILE_OBJECT "${CMAKE_${lang}_COMPILE_OBJECT}")
string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "${CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE}")
string(REPLACE "-c <SOURCE>" "-c -- <SOURCE>" CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "${CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE}")
endif()
elseif(MSVC_VERSION GREATER_EQUAL 1913)
# At least MSVC toolet 14.13 from VS 2017 15.6
set(CMAKE_PCH_PROLOGUE "#pragma system_header")

View File

@@ -890,7 +890,7 @@ void cmGlobalFastbuildGenerator::WriteCompilers()
std::map<std::string, std::string> compilerIdToFastbuildFamily = {
{ "MSVC", "msvc" }, { "Clang", "clang" },
{ "AppleClang", "clang" }, { "GNU", "gcc" },
{ "NVIDIA", "cuda-nvcc" },
{ "NVIDIA", "cuda-nvcc" }, { "Clang-cl", "clang-cl" },
};
auto ft = compilerIdToFastbuildFamily.find(compilerDef.CmakeCompilerID);
if (ft != compilerIdToFastbuildFamily.end()) {
@@ -969,6 +969,11 @@ void cmGlobalFastbuildGenerator::AddCompiler(std::string const& language,
compilerDef.Executable = compilerLocation;
compilerDef.CmakeCompilerID =
mf->GetSafeDefinition("CMAKE_" + language + "_COMPILER_ID");
if (compilerDef.CmakeCompilerID == "Clang" &&
mf->GetSafeDefinition("CMAKE_" + language +
"_COMPILER_FRONTEND_VARIANT") == "MSVC") {
compilerDef.CmakeCompilerID = "Clang-cl";
}
compilerDef.CmakeCompilerVersion =
mf->GetSafeDefinition("CMAKE_" + language + "_COMPILER_VERSION");