From 5074344c9c1fb9a510f333d470d83e8da94072f9 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Thu, 2 Dec 2021 17:14:00 +0800 Subject: MSVC: Use dubbed FH4 to make C++ exception handling smaller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Visual Studio 2019 introduced the dubbed FH4 feature which can make C++ exception handling smaller on x64. According to the article [1], it's enabled by default for UWP applications, and Microsoft also use it in their own widely-known commercial products such as Office to reduce the binary size. So make use of this feature for Qt when possible, to get smaller binary. As a drive-by, add "/EHs-c-" explicitly to the flags when we want to disable C++ exception handling. [1] Official article that introduces dubbed FH4: https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/ Change-Id: I2e3330de477f78372cf7903d0ef7a732b09552a9 Reviewed-by: Thiago Macieira Reviewed-by: André de la Rocha Reviewed-by: Qt CI Bot Reviewed-by: Oliver Wolff --- cmake/QtFlagHandlingHelpers.cmake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cmake/QtFlagHandlingHelpers.cmake') diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 3558dd46ac..9c5aee5d90 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -148,16 +148,19 @@ function(qt_internal_set_exceptions_flags target exceptions_on) if(exceptions_on) if(MSVC) set(_flag "/EHsc") + if(MSVC_VERSION GREATER_EQUAL 1929) + set(_flag ${_flag} "/d2FH4") + endif() endif() else() set(_defs "QT_NO_EXCEPTIONS") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - set(_flag "/wd4530" "/wd4577") + set(_flag "/EHs-c-" "/wd4530" "/wd4577") elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|AppleClang|InteLLLVM") set(_flag "-fno-exceptions") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") if (MSVC) - set(_flag "/wd4530" "/wd4577") + set(_flag "/EHs-c-" "/wd4530" "/wd4577") else() set(_flag "-fno-exceptions") endif() -- cgit v1.2.3