cmake: build with exceptions disabled by default

Only re-enable exceptions for the modules that do
CONFIG+=exceptions
in qmake

Change-Id: I9f19078adbdc1b8fa3d4102fb51a099e7e35522e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Albert Astals Cid 2019-06-04 15:55:41 +02:00
parent fecd9d90da
commit bfa209dfa5
8 changed files with 42 additions and 4 deletions

View File

@ -982,6 +982,21 @@ function(qt_internal_add_target_aliases target)
endif()
endfunction()
# Sets the exceptions flags for the given target
function(qt_internal_set_no_exceptions_flags target)
target_compile_definitions("${target}" PRIVATE "QT_NO_EXCEPTIONS")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options("${target}" PRIVATE "/wd4530 /wd4577")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options("${target}" PRIVATE "-fno-exceptions")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
target_compile_options("${target}" PRIVATE "-fno-exceptions")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options("${target}" PRIVATE "-fno-exceptions")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
target_compile_options("${target}" PRIVATE "-fno-exceptions")
endif()
endfunction()
# This is the main entry function for creating a Qt module, that typically
# consists of a library, public header files, private header files and configurable
@ -998,7 +1013,7 @@ function(add_qt_module target)
# Process arguments:
qt_parse_all_arguments(arg "add_qt_module"
"NO_MODULE_HEADERS;STATIC;DISABLE_TOOLS_EXPORT"
"NO_MODULE_HEADERS;STATIC;DISABLE_TOOLS_EXPORT;EXCEPTIONS"
"CONFIG_MODULE_NAME"
"${__default_private_args};${__default_public_args};QMAKE_MODULE_CONFIG" ${ARGN})
@ -1118,6 +1133,9 @@ function(add_qt_module target)
if(FEATURE_largefile)
target_compile_definitions("${target}" PRIVATE "_LARGEFILE64_SOURCE;_LARGEFILE_SOURCE")
endif()
if(NOT ${arg_EXCEPTIONS})
qt_internal_set_no_exceptions_flags("${target}")
endif()
set(configureFile "${CMAKE_CURRENT_SOURCE_DIR}/configure.cmake")
if(EXISTS "${configureFile}")
@ -1355,7 +1373,7 @@ function(add_qt_plugin target)
qt_internal_set_qt_known_plugins("${QT_KNOWN_PLUGINS}" "${target}")
qt_parse_all_arguments(arg "add_qt_plugin" "STATIC"
qt_parse_all_arguments(arg "add_qt_plugin" "STATIC;EXCEPTIONS"
"TYPE;CLASS_NAME;OUTPUT_DIRECTORY;INSTALL_DIRECTORY;ARCHIVE_INSTALL_DIRECTORY"
"${__default_private_args};${__default_public_args}" ${ARGN})
@ -1447,6 +1465,9 @@ function(add_qt_plugin target)
if(FEATURE_largefile)
target_compile_definitions("${target}" PRIVATE "_LARGEFILE64_SOURCE;_LARGEFILE_SOURCE")
endif()
if(NOT ${arg_EXCEPTIONS})
qt_internal_set_no_exceptions_flags("${target}")
endif()
set(qt_libs_private "")
@ -1512,7 +1533,7 @@ endfunction()
# Please consider to use a more specific version target like the one created
# by add_qt_test or add_qt_tool below.
function(add_qt_executable name)
qt_parse_all_arguments(arg "add_qt_executable" "GUI;BOOTSTRAP;NO_QT;NO_INSTALL" "OUTPUT_DIRECTORY;INSTALL_DIRECTORY" "EXE_FLAGS;${__default_private_args}" ${ARGN})
qt_parse_all_arguments(arg "add_qt_executable" "GUI;BOOTSTRAP;NO_QT;NO_INSTALL;EXCEPTIONS" "OUTPUT_DIRECTORY;INSTALL_DIRECTORY" "EXE_FLAGS;${__default_private_args}" ${ARGN})
if ("x${arg_OUTPUT_DIRECTORY}" STREQUAL "x")
set(arg_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${INSTALL_BINDIR}")
@ -1561,6 +1582,9 @@ function(add_qt_executable name)
if(FEATURE_largefile)
target_compile_definitions("${name}" PRIVATE "_LARGEFILE64_SOURCE;_LARGEFILE_SOURCE")
endif()
if(NOT ${arg_EXCEPTIONS})
qt_internal_set_no_exceptions_flags("${name}")
endif()
if(WIN32)
@ -1579,10 +1603,15 @@ endfunction()
# This function creates a CMake test target with the specified name for use with CTest.
function(add_qt_test name)
qt_parse_all_arguments(arg "add_qt_test" "RUN_SERIAL" "" "${__default_private_args}" ${ARGN})
qt_parse_all_arguments(arg "add_qt_test" "RUN_SERIAL;EXCEPTIONS" "" "${__default_private_args}" ${ARGN})
set(path "${CMAKE_CURRENT_BINARY_DIR}")
if (${arg_EXCEPTIONS})
set(EXCEPTIONS_TEXT "EXCEPTIONS")
endif()
add_qt_executable("${name}"
${EXCEPTIONS_TEXT}
NO_INSTALL
OUTPUT_DIRECTORY "${path}"
SOURCES "${arg_SOURCES}"

View File

@ -5,6 +5,7 @@
#####################################################################
add_qt_module(Concurrent
EXCEPTIONS
SOURCES
qtconcurrent_global.h
qtconcurrentcompilertest.h

View File

@ -17,6 +17,7 @@ endif()
#####################################################################
add_qt_module(Core
EXCEPTIONS
QMAKE_MODULE_CONFIG moc resources
SOURCES
# special case: remove ../3rdparty/harfbuzz

View File

@ -6,6 +6,7 @@
add_qt_module(Test
CONFIG_MODULE_NAME testlib # special case
EXCEPTIONS
SOURCES
qabstracttestlogger.cpp qabstracttestlogger_p.h
qasciikey.cpp

View File

@ -1,4 +1,5 @@
add_qt_test(tst_qglobalstatic
EXCEPTIONS
SOURCES
tst_qglobalstatic.cpp
DEFINES

View File

@ -5,6 +5,7 @@
#####################################################################
add_qt_executable(exceptionthrow
EXCEPTIONS
NO_INSTALL # special case
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case
GUI

View File

@ -5,6 +5,7 @@
#####################################################################
add_qt_executable(verifyexceptionthrown
EXCEPTIONS
NO_INSTALL # special case
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case
GUI

View File

@ -1545,6 +1545,9 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str,
# Evaluate total condition of all scopes:
recursive_evaluate_scope(scope)
if 'exceptions' in scope.get('CONFIG'):
extra_lines.append('EXCEPTIONS')
# Get a flat list of all scopes but the main one:
scopes = flatten_scopes(scope)
total_scopes = len(scopes)