cmake: simplify exceptions handling code

A little code simplification. And we can enable exception handling
explicitly for GCC/Clang by adding "-fexceptions", it was missing
in the old code, add it as well.

[ChangeLog] [Build System] Qt explicitly pass -fexceptions now on
 non-MSVC toolchains, if exception handling is not disabled in CMake
 configure.

Change-Id: Id9d61d3ee8b7d490f4a743e34e8be321af080be0
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Yuhang Zhao 2023-10-07 14:17:30 +08:00
parent c52ada54c5
commit a20a6ae7ea

View File

@ -256,21 +256,17 @@ function(qt_internal_set_exceptions_flags target exceptions_on)
# this hack since some unknown MSVC version.
set(_flag ${_flag} "/d2FH4")
endif()
else()
set(_flag "-fexceptions")
endif()
else()
set(_defs "QT_NO_EXCEPTIONS")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
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 "/EHs-c-" "/wd4530" "/wd4577")
else()
set(_flag "-fno-exceptions")
endif()
endif()
endif()
target_compile_definitions("${target}" PRIVATE ${_defs})
target_compile_options("${target}" PRIVATE ${_flag})