From 5a9f324a46451f660f9bcc1da455a33c60c0ea29 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 14 Oct 2024 16:12:31 +0200 Subject: [PATCH] CMake: Guard some MSVC flags not understood by clang-cl frontend Due to various reasons, Qt WebEngine needs to be built with clang-cl, while qtbase and other dependencies with MSVC. clang-cl does not understand all MSVC-style options, which are recorded and propagated through the PlatformCommonInternal target which is configured in qtbase using MSVC. Guard the flags that are not understood by clang-cl with a genex condition that checks that the compiler is not clang (which implies clang-cl, because afaik it's not possible to use gcc frontend of clang against an MSVC-built qtbase). Change-Id: Ibf2c96399a8322ce13814c9c6afa5b57fd8885be Reviewed-by: Alexey Edelev Reviewed-by: Zhao Yuhang <2546789017@qq.com> Reviewed-by: Oliver Wolff Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 515ad07a12c4bf190545ae38eff588f7b979d68e) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtInternalTargets.cmake | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index b95257cc69e..89d0f893e9b 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -262,6 +262,13 @@ endif() # Taken from mkspecs/common/msvc-version.conf and mkspecs/common/msvc-desktop.conf if (MSVC AND NOT CLANG) if (MSVC_VERSION GREATER_EQUAL 1799) + set_target_properties(PlatformCommonInternal PROPERTIES _qt_cpp_compiler_frontend_variant + "${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}") + + # Protect against adding these flags when building qtbase with MSVC, and qtwebengine using + # clang-cl. + set(is_not_clang_cl_start "$<$,Clang>>:") + set(is_not_clang_cl_end ">") target_compile_options(PlatformCommonInternal INTERFACE -FS -Zc:rvalueCast @@ -271,18 +278,18 @@ if (MSVC AND NOT CLANG) if (MSVC_VERSION GREATER_EQUAL 1899) target_compile_options(PlatformCommonInternal INTERFACE -Zc:strictStrings - -Zc:throwingNew + "${is_not_clang_cl_start}-Zc:throwingNew${is_not_clang_cl_end}" ) endif() if (MSVC_VERSION GREATER_EQUAL 1909) # MSVC 2017 target_compile_options(PlatformCommonInternal INTERFACE - -Zc:referenceBinding + "${is_not_clang_cl_start}-Zc:referenceBinding${is_not_clang_cl_end}" -Zc:ternary ) endif() if (MSVC_VERSION GREATER_EQUAL 1919) # MSVC 2019 target_compile_options(PlatformCommonInternal INTERFACE - -Zc:externConstexpr + "${is_not_clang_cl_start}-Zc:externConstexpr${is_not_clang_cl_end}" #-Zc:lambda # Buggy. TODO: Enable again when stable enough. #-Zc:preprocessor # breaks build due to bug in default Windows SDK 10.0.19041 )