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>
This commit is contained in:
Albert Astals Cid 2019-06-04 15:14:42 +02:00
parent e5d6640692
commit 5fea9f8f52
7 changed files with 76 additions and 4 deletions

View File

@ -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()

View File

@ -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.

View File

@ -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);

View File

@ -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);
}

View File

@ -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; }

View File

@ -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 &)
{
}

View File

@ -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