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 | |
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>
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | cmake/QtBuild.cmake | 63 | ||||
-rw-r--r-- | qmake/generators/mac/pbuilder_pbx.cpp | 2 | ||||
-rw-r--r-- | qmake/generators/makefile.cpp | 1 | ||||
-rw-r--r-- | qmake/generators/projectgenerator.h | 2 | ||||
-rw-r--r-- | qmake/generators/win32/winmakefile.cpp | 2 | ||||
-rw-r--r-- | src/gui/CMakeLists.txt | 7 |
7 files changed, 76 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8344d22c0d..6be7a6edcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,9 @@ include(QtBaseGlobalTargets) option(BUILD_SHARED_LIBS "Build Qt statically or dynamically" ON) set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +## Should this Qt be built with Werror? +option(WARNINGS_ARE_ERRORS "Build Qt with warnings as errors" ${FEATURE_developer_build}) + ## Decide whether tools will be built. qt_check_if_tools_will_be_built() 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. diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp index b3c6ba4869..59a4008a3b 100644 --- a/qmake/generators/mac/pbuilder_pbx.cpp +++ b/qmake/generators/mac/pbuilder_pbx.cpp @@ -513,7 +513,6 @@ bool ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) { ProStringList tmp; - bool did_preprocess = false; //HEADER const int pbVersion = pbuilderVersion(); @@ -731,7 +730,6 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t) QFile mkf(mkfile); if(mkf.open(QIODevice::WriteOnly | QIODevice::Text)) { writingUnixMakefileGenerator = true; - did_preprocess = true; debug_msg(1, "pbuilder: Creating file: %s", mkfile.toLatin1().constData()); QTextStream mkt(&mkf); writeHeader(mkt); diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index f3ca192ab2..411bb37437 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -895,6 +895,7 @@ bool MakefileGenerator::processPrlFileBase(QString &origFile, const QStringRef &origName, const QStringRef &fixedBase, int slashOff) { + Q_UNUSED(slashOff) return processPrlFileCore(origFile, origName, fixedBase + Option::prl_ext); } diff --git a/qmake/generators/projectgenerator.h b/qmake/generators/projectgenerator.h index e9b050cc74..ef6a76f0d0 100644 --- a/qmake/generators/projectgenerator.h +++ b/qmake/generators/projectgenerator.h @@ -43,7 +43,7 @@ protected: void init() override; bool writeMakefile(QTextStream &) override; - QString escapeFilePath(const QString &path) const override { Q_ASSERT(false); return QString(); } + QString escapeFilePath(const QString &path) const override { Q_UNUSED(path); Q_ASSERT(false); return QString(); } public: bool supportsMetaBuild() override { return false; } diff --git a/qmake/generators/win32/winmakefile.cpp b/qmake/generators/win32/winmakefile.cpp index 8e0c62e13f..b79fd8f250 100644 --- a/qmake/generators/win32/winmakefile.cpp +++ b/qmake/generators/win32/winmakefile.cpp @@ -645,7 +645,7 @@ void Win32MakefileGenerator::writeObjectsPart(QTextStream &t) t << "OBJECTS = " << valList(escapeDependencyPaths(project->values("OBJECTS"))) << Qt::endl; } -void Win32MakefileGenerator::writeImplicitRulesPart(QTextStream &t) +void Win32MakefileGenerator::writeImplicitRulesPart(QTextStream &) { } diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b662f8e092..fe37e4daa5 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -36,6 +36,13 @@ if (QT_FEATURE_gui) set(QT_QPA_DEFAULT_PLATFORM "${_default_platform}" CACHE STRING "QPA default platform") endif() + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set_source_files_properties(../3rdparty/md4c/md4c.c PROPERTIES COMPILE_FLAGS "-Wno-error=unused-parameter -Wno-error=sign-compare -Wno-error=missing-field-initializers") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(../3rdparty/md4c/md4c.c PROPERTIES COMPILE_FLAGS "-Wno-error=unused-parameter -Wno-error=sign-compare -Wno-error=missing-field-initializers -Wno-error=missing-braces") +endif() + # special case end add_qt_module(Gui |