From 20b3eb0fd8b5f82cf432f2c06e7c5d3f533df0a5 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Thu, 3 Jun 2021 12:42:07 +0200 Subject: [PATCH] CMake: Add support for building with clang-cl qmake had support for building with clang-cl as the win32-clang-msvc mkspec. Task-number: QTBUG-89642 Task-number: QTBUG-88081 Change-Id: I0709c289f90fedb121620d1e67ef841602219816 Reviewed-by: Alexandru Croitor --- cmake/QtBuild.cmake | 4 +++- cmake/QtFlagHandlingHelpers.cmake | 2 +- src/corelib/CMakeLists.txt | 20 ++++++++++++++++++ src/corelib/global/qt_pch.h | 35 ++++++++++++++++++------------- src/gui/CMakeLists.txt | 9 ++++++++ 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index bb8b14658a9..792276e38ff 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -285,7 +285,9 @@ if(WIN32) list(APPEND QT_DEFAULT_PLATFORM_DEFINITIONS WIN64 _WIN64) endif() if(MSVC) - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + if (CLANG) + set(QT_DEFAULT_MKSPEC win32-clang-msvc) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64") set(QT_DEFAULT_MKSPEC win32-arm64-msvc) else() set(QT_DEFAULT_MKSPEC win32-msvc) diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 0c57d9e0e1e..0eeccce4dd5 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -235,7 +235,7 @@ endfunction() function(qt_set_msvc_cplusplus_options target visibility) # For MSVC we need to explicitly pass -Zc:__cplusplus to get correct __cplusplus. # Check qt_config_compile_test for more info. - if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1913) + if(MSVC AND MSVC_VERSION GREATER_EQUAL 1913) target_compile_options("${target}" ${visibility} "-Zc:__cplusplus" "-permissive-") endif() endfunction() diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 2c991f76e0b..9f0c95e9d62 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -271,6 +271,26 @@ qt_internal_add_module(Core # special case end ) +if (MSVC AND CLANG) + foreach(subarch sse4_1 rdrnd rdseed) + if (TEST_subarch_${subarch}) + qt_internal_add_simd_part(Core SIMD ${subarch} + SOURCES + global/qsimd.cpp + ) + endif() + endforeach() + + foreach(subarch sse4_1 aesni) + if (TEST_subarch_${subarch}) + qt_internal_add_simd_part(Core SIMD ${subarch} + SOURCES + tools/qhash.cpp + ) + endif() + endforeach() +endif() + qt_update_ignore_pch_source(Core kernel/qmetatype.cpp ) # special case begin diff --git a/src/corelib/global/qt_pch.h b/src/corelib/global/qt_pch.h index 58697517b59..6108b075f0e 100644 --- a/src/corelib/global/qt_pch.h +++ b/src/corelib/global/qt_pch.h @@ -62,19 +62,24 @@ # define _POSIX_ # include # undef _POSIX_ -#endif -#include -#include -#include -#include -#include /* All moc genereated code has this include */ -#include -#if QT_CONFIG(regularexpression) -# include -#endif -#include -#include -#include -#include -#include +# if defined(Q_CC_CLANG) && defined(Q_CC_MSVC) +// See https://bugs.llvm.org/show_bug.cgi?id=41226 +# include +__declspec(selectany) auto *__wmemchr_symbol_loader_value = wmemchr(L"", L'0', 0); +# endif +# endif +# include +# include +# include +# include +# include /* All moc genereated code has this include */ +# include +# if QT_CONFIG(regularexpression) +# include +# endif +# include +# include +# include +# include +# include #endif diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 5fe4d59d107..04f58dd9bc6 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -577,6 +577,15 @@ if(NOT ANDROID) ) endif() + if (MSVC AND CLANG AND TEST_subarch_sse4_1) + qt_internal_add_simd_part(Gui SIMD sse4_1 + SOURCES + painting/qdrawhelper.cpp + painting/qdrawhelper_sse2.cpp + painting/qdrawhelper_ssse3.cpp + ) + endif() + qt_internal_add_simd_part(Gui SIMD ssse3 SOURCES image/qimage_ssse3.cpp