diff options
author | Albert Astals Cid <albert.astals.cid@kdab.com> | 2019-06-04 15:55:41 +0200 |
---|---|---|
committer | Albert Astals Cid <albert.astals.cid@kdab.com> | 2019-06-05 09:10:51 +0000 |
commit | bfa209dfa557e7c30d654add09f5c8f97cfc2492 (patch) | |
tree | e3bdc19f60d742ee810eabffbab5b90a4a5de2e1 | |
parent | fecd9d90daa22b33c40a709da21cef62bfa44a15 (diff) |
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>
-rw-r--r-- | cmake/QtBuild.cmake | 37 | ||||
-rw-r--r-- | src/concurrent/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/corelib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/testlib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/corelib/global/qglobalstatic/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/exceptionthrow/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/verifyexceptionthrown/CMakeLists.txt | 1 | ||||
-rwxr-xr-x | util/cmake/pro2cmake.py | 3 |
8 files changed, 42 insertions, 4 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 85ee030822..6fabf8098a 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -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}" diff --git a/src/concurrent/CMakeLists.txt b/src/concurrent/CMakeLists.txt index 9094cf13db..b0d90e40ba 100644 --- a/src/concurrent/CMakeLists.txt +++ b/src/concurrent/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### add_qt_module(Concurrent + EXCEPTIONS SOURCES qtconcurrent_global.h qtconcurrentcompilertest.h diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 5d45d2b316..a032a9117e 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -17,6 +17,7 @@ endif() ##################################################################### add_qt_module(Core + EXCEPTIONS QMAKE_MODULE_CONFIG moc resources SOURCES # special case: remove ../3rdparty/harfbuzz diff --git a/src/testlib/CMakeLists.txt b/src/testlib/CMakeLists.txt index 9acbe76e0f..eba682bdc2 100644 --- a/src/testlib/CMakeLists.txt +++ b/src/testlib/CMakeLists.txt @@ -6,6 +6,7 @@ add_qt_module(Test CONFIG_MODULE_NAME testlib # special case + EXCEPTIONS SOURCES qabstracttestlogger.cpp qabstracttestlogger_p.h qasciikey.cpp diff --git a/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt b/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt index 3aa4511d6f..fc31f1ea99 100644 --- a/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt +++ b/tests/auto/corelib/global/qglobalstatic/CMakeLists.txt @@ -1,4 +1,5 @@ add_qt_test(tst_qglobalstatic + EXCEPTIONS SOURCES tst_qglobalstatic.cpp DEFINES diff --git a/tests/auto/testlib/selftests/exceptionthrow/CMakeLists.txt b/tests/auto/testlib/selftests/exceptionthrow/CMakeLists.txt index 1e67b630bd..71d3aa1e74 100644 --- a/tests/auto/testlib/selftests/exceptionthrow/CMakeLists.txt +++ b/tests/auto/testlib/selftests/exceptionthrow/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### add_qt_executable(exceptionthrow + EXCEPTIONS NO_INSTALL # special case OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case GUI diff --git a/tests/auto/testlib/selftests/verifyexceptionthrown/CMakeLists.txt b/tests/auto/testlib/selftests/verifyexceptionthrown/CMakeLists.txt index 817eddaee8..24dd224107 100644 --- a/tests/auto/testlib/selftests/verifyexceptionthrown/CMakeLists.txt +++ b/tests/auto/testlib/selftests/verifyexceptionthrown/CMakeLists.txt @@ -5,6 +5,7 @@ ##################################################################### add_qt_executable(verifyexceptionthrown + EXCEPTIONS NO_INSTALL # special case OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} # special case GUI diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index fcf9b1060c..bd26e5782a 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -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) |