diff options
author | Albert Astals Cid <albert.astals.cid@kdab.com> | 2019-06-04 15:14:42 +0200 |
---|---|---|
committer | Albert Astals Cid <albert.astals.cid@kdab.com> | 2019-06-05 13:10:16 +0000 |
commit | 5fea9f8f52810dc50e45f7462a5df9d8ab0a1f37 (patch) | |
tree | da4dd731e41cd3381815cb925aedd5dc47797325 /cmake/QtBuild.cmake | |
parent | e5d66406928c9baa190cd2e57783849d8ad67fd5 (diff) |
cmake: Add warnings_are_errors option
for modules, plugins and tools only (i.e. no tests nor examples)
this mimics the qmake behavior
default value is developer_build
Comes with some fixes in qmake since it seems in the qmake built it was
not having Werror, now does because we built it with add_qt_tool
Change-Id: I6f3237f25a6fedefa958644929e90f13837a12df
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtBuild.cmake')
-rw-r--r-- | cmake/QtBuild.cmake | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index acc36276bb..08b04e42ea 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -1002,6 +1002,60 @@ function(qt_internal_set_no_exceptions_flags target) endif() endfunction() +function(qt_internal_set_warnings_are_errors_flags target) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # Regular clang 3.0+ + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "3.0.0") + target_compile_options("${target}" PRIVATE -Werror -Wno-error=\#warnings -Wno-error=deprecated-declarations) + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + # using AppleClang + # Apple clang 4.0+ + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "4.0.0") + target_compile_options("${target}" PRIVATE -Werror -Wno-error=\#warnings -Wno-error=deprecated-declarations) + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # using GCC + target_compile_options("${target}" PRIVATE -Werror -Wno-error=cpp -Wno-error=deprecated-declarations) + + # GCC prints this bogus warning, after it has inlined a lot of code + # error: assuming signed overflow does not occur when assuming that (X + c) < X is always false + target_compile_options("${target}" PRIVATE -Wno-error=strict-overflow) + + # GCC 7 includes -Wimplicit-fallthrough in -Wextra, but Qt is not yet free of implicit fallthroughs. + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0") + target_compile_options("${target}" PRIVATE -Wno-error=implicit-fallthrough) + endif() + + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0.0") + # GCC 9 introduced these but we are not clean for it. + target_compile_options("${target}" PRIVATE -Wno-error=deprecated-copy -Wno-error=redundant-move -Wno-error=init-list-lifetime) + endif() + + # Work-around for bug https://code.google.com/p/android/issues/detail?id=58135 + if (ANDROID) + target_compile_options("${target}" PRIVATE -Wno-error=literal-suffix) + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + # Intel CC 13.0 +, on Linux only + if (LINUX) + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0.0") + # 177: function "entity" was declared but never referenced + # (too aggressive; ICC reports even for functions created due to template instantiation) + # 1224: #warning directive + # 1478: function "entity" (declared at line N) was declared deprecated + # 1786: function "entity" (declared at line N of "file") was declared deprecated ("message") + # 1881: argument must be a constant null pointer value + # (NULL in C++ is usually a literal 0) + target_compile_options("${target}" PRIVATE -Werror -ww177,1224,1478,1786,1881) + endif() + endif() + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # using Visual Studio C++ + target_compile_options("${target}" PRIVATE /WX) + 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 # features. @@ -1146,6 +1200,9 @@ function(add_qt_module target) if(NOT ${arg_EXCEPTIONS}) qt_internal_set_no_exceptions_flags("${target}") endif() + if(WARNINGS_ARE_ERRORS) + qt_internal_set_warnings_are_errors_flags("${target}") + endif() set(configureFile "${CMAKE_CURRENT_SOURCE_DIR}/configure.cmake") if(EXISTS "${configureFile}") @@ -1478,6 +1535,9 @@ function(add_qt_plugin target) if(NOT ${arg_EXCEPTIONS}) qt_internal_set_no_exceptions_flags("${target}") endif() + if(WARNINGS_ARE_ERRORS) + qt_internal_set_warnings_are_errors_flags("${target}") + endif() set(qt_libs_private "") @@ -1777,6 +1837,9 @@ function(add_qt_tool name) DISABLE_AUTOGEN_TOOLS ${disable_autogen_tools} ) qt_internal_add_target_aliases("${name}") + if(WARNINGS_ARE_ERRORS) + qt_internal_set_warnings_are_errors_flags("${name}") + endif() if(NOT arg_NO_INSTALL AND arg_TOOLS_TARGET) # Assign a tool to an export set, and mark the module to which the tool belongs. |