Make qt_internal_set_warnings_are_errors_flags genex-ed

Fixes: QTBUG-132705
Pick-to: 6.8
Change-Id: I57987f1ae1c6d6adc4a2d0151f365c24605b940e
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit e3af89f7b4e8daa9cbfcc0d2c7cec7b7478f9406)
This commit is contained in:
Cristian Le 2025-01-24 17:27:25 +01:00
parent 8b59467d20
commit 0bdad95d0c
2 changed files with 123 additions and 76 deletions

View File

@ -39,9 +39,15 @@ if(TARGET @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal)
if(NOT _qt_platform_internal_common_target) if(NOT _qt_platform_internal_common_target)
set(_qt_platform_internal_common_target @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal) set(_qt_platform_internal_common_target @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal)
endif() endif()
set(_qt_internal_clang_msvc_frontend FALSE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
set(_qt_internal_clang_msvc_frontend TRUE)
endif()
set_target_properties(${_qt_platform_internal_common_target} set_target_properties(${_qt_platform_internal_common_target}
PROPERTIES PROPERTIES
_qt_internal_cmake_generator "${CMAKE_GENERATOR}" _qt_internal_cmake_generator "${CMAKE_GENERATOR}"
_qt_internal_clang_msvc_frontend "${_qt_internal_clang_msvc_frontend}"
) )
unset(_qt_platform_internal_common_target) unset(_qt_platform_internal_common_target)
endif() endif()

View File

@ -3,85 +3,116 @@
function(qt_internal_set_warnings_are_errors_flags target target_scope) function(qt_internal_set_warnings_are_errors_flags target target_scope)
set(flags "") # Gate everything by the target property
if (CLANG AND NOT MSVC) set(common_conditions "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_SKIP_WARNINGS_ARE_ERRORS>>>")
list(APPEND flags -Werror -Wno-error=\#warnings -Wno-error=deprecated-declarations) # Apparently qmake only adds -Werror to CXX and OBJCXX files, not C files. We have to do the
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") # as in: not AppleClang # same otherwise MinGW builds break when building 3rdparty\md4c\md4c.c (and probably on other
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0") # platforms too).
set(language_args LANGUAGES CXX OBJCXX)
# This property is set to True only if we are using Clang and frontend is MSVC
# Currently we do not set any error flags
set(clang_msvc_frontend_args
"$<NOT:$<BOOL:$<TARGET_PROPERTY:Qt6::PlatformCommonInternal,_qt_internal_clang_msvc_frontend>>>"
)
if(GCC OR CLANG OR WIN32)
# Note: the if check is included to mimic the previous selective gating. These need to
# balance reducing unnecessary compile flags that are evaluated by the genex, and making
# sure the developer has appropriate Werror flags enabled when building a module with
# different environment
qt_internal_add_compiler_dependent_flags("${target}" ${target_scope}
COMPILERS CLANG AppleClang
OPTIONS
-Werror -Wno-error=\#warnings -Wno-error=deprecated-declarations
COMPILERS CLANG
CONDITIONS VERSION_GREATER_EQUAL 10
OPTIONS
# We do mixed enum arithmetic all over the place: # We do mixed enum arithmetic all over the place:
list(APPEND flags -Wno-error=deprecated-enum-enum-conversion) -Wno-error=deprecated-enum-enum-conversion
endif() CONDITIONS VERSION_GREATER_EQUAL 14
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0.0") OPTIONS
# Clang 14 introduced these two but we are not clean for it. # Clang 14 introduced these two but we are not clean for it.
list(APPEND flags -Wno-error=deprecated-copy-with-user-provided-copy) -Wno-error=deprecated-copy-with-user-provided-copy
list(APPEND flags -Wno-error=unused-but-set-variable) -Wno-error=unused-but-set-variable
endif() COMMON_CONDITIONS
endif() ${common_conditions}
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") ${clang_msvc_frontend_args}
# using GCC ${language_args}
list(APPEND flags -Werror -Wno-error=cpp -Wno-error=deprecated-declarations) )
qt_internal_add_compiler_dependent_flags("${target}" ${target_scope}
COMPILERS GNU
OPTIONS
-Werror -Wno-error=cpp -Wno-error=deprecated-declarations
# GCC prints this bogus warning, after it has inlined a lot of code # 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 # error: assuming signed overflow does not occur when assuming that (X + c) < X
list(APPEND flags -Wno-error=strict-overflow) # is always false
-Wno-error=strict-overflow
# GCC 7 includes -Wimplicit-fallthrough in -Wextra, but Qt is not yet free of implicit fallthroughs. CONDITIONS VERSION_GREATER_EQUAL 7
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0") OPTIONS
list(APPEND flags -Wno-error=implicit-fallthrough) # GCC 7 includes -Wimplicit-fallthrough in -Wextra, but Qt is not yet free of
endif() # implicit fallthroughs.
-Wno-error=implicit-fallthrough
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.0.0") CONDITIONS VERSION_GREATER_EQUAL 9
OPTIONS
# GCC 9 introduced these but we are not clean for it. # GCC 9 introduced these but we are not clean for it.
list(APPEND flags -Wno-error=deprecated-copy -Wno-error=redundant-move -Wno-error=init-list-lifetime) -Wno-error=deprecated-copy
-Wno-error=redundant-move
-Wno-error=init-list-lifetime
# GCC 9 introduced -Wformat-overflow in -Wall, but it is buggy: # GCC 9 introduced -Wformat-overflow in -Wall, but it is buggy:
list(APPEND flags -Wno-error=format-overflow) -Wno-error=format-overflow
endif() CONDITIONS VERSION_GREATER_EQUAL 10
OPTIONS
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "10.0.0")
# GCC 10 has a number of bugs in -Wstringop-overflow. Do not make them an error. # GCC 10 has a number of bugs in -Wstringop-overflow. Do not make them an error.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92955
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94335
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101134 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101134
list(APPEND flags -Wno-error=stringop-overflow) -Wno-error=stringop-overflow
endif() CONDITIONS VERSION_GREATER_EQUAL 11
OPTIONS
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0.0")
# Ditto # Ditto
list(APPEND flags -Wno-error=stringop-overread) -Wno-error=stringop-overread
# We do mixed enum arithmetic all over the place: # We do mixed enum arithmetic all over the place:
list(APPEND flags -Wno-error=deprecated-enum-enum-conversion -Wno-error=deprecated-enum-float-conversion) -Wno-error=deprecated-enum-enum-conversion
endif() -Wno-error=deprecated-enum-float-conversion
CONDITIONS VERSION_GREATER_EQUAL 11.0 AND VERSION_LESS 11.2
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0.0" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.2.0") OPTIONS
# GCC 11.1 has a regression in the integrated preprocessor, so disable it as a workaround (QTBUG-93360) # GCC 11.1 has a regression in the integrated preprocessor, so disable it as a
# workaround (QTBUG-93360)
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100796 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100796
# This in turn triggers a fallthrough warning in cborparser.c, so we disable this warning. # This in turn triggers a fallthrough warning in cborparser.c, so we disable
list(APPEND flags -no-integrated-cpp -Wno-implicit-fallthrough) # this warning.
-no-integrated-cpp -Wno-implicit-fallthrough
COMMON_CONDITIONS
${common_conditions}
${language_args}
)
endif() endif()
# Other options are gated at compile time that are not likely to change between different build
# environments of other modules.
if(ANDROID)
qt_internal_add_compiler_dependent_flags("${target}" ${target_scope}
COMPILERS GNU
CONDITIONS $<PLATFORM_ID:ANDROID>
OPTIONS
# Work-around for bug https://code.google.com/p/android/issues/detail?id=58135 # Work-around for bug https://code.google.com/p/android/issues/detail?id=58135
if (ANDROID) -Wno-error=literal-suffix
list(APPEND flags -Wno-error=literal-suffix) COMMON_CONDITIONS
${common_conditions}
${language_args}
)
endif() endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") if(WIN32)
qt_internal_add_compiler_dependent_flags("${target}" ${target_scope}
COMPILERS MSVC
# Only enable for versions of MSVC that are known to work # Only enable for versions of MSVC that are known to work
# 1941 is Visual Studio 2022 version 17.11 # 1941 is Visual Studio 2022 version 17.11
if(MSVC_VERSION LESS_EQUAL 1941) CONDITIONS VERSION_LESS_EQUAL 17.11
list(APPEND flags /WX) OPTIONS
/WX
COMMON_CONDITIONS
${common_conditions}
${language_args}
)
endif() endif()
endif()
set(warnings_are_errors_enabled_genex
"$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_SKIP_WARNINGS_ARE_ERRORS>>>")
# Apparently qmake only adds -Werror to CXX and OBJCXX files, not C files. We have to do the
# same otherwise MinGW builds break when building 3rdparty\md4c\md4c.c (and probably on other
# platforms too).
set(cxx_only_genex "$<COMPILE_LANGUAGE:CXX,OBJCXX>")
set(final_condition_genex "$<AND:${warnings_are_errors_enabled_genex},${cxx_only_genex}>")
set(flags_generator_expression "$<${final_condition_genex}:${flags}>")
target_compile_options("${target}" ${target_scope} "${flags_generator_expression}")
endfunction() endfunction()
# The function adds a global 'definition' to the platform internal targets and the target # The function adds a global 'definition' to the platform internal targets and the target
@ -310,6 +341,16 @@ if (MSVC AND NOT CLANG)
) )
endif() endif()
set(_qt_internal_clang_msvc_frontend False)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
set(_qt_internal_clang_msvc_frontend True)
endif()
set_target_properties(PlatformCommonInternal
PROPERTIES
_qt_internal_clang_msvc_frontend "${_qt_internal_clang_msvc_frontend}"
)
if(MINGW) if(MINGW)
target_compile_options(PlatformCommonInternal INTERFACE -Wa,-mbig-obj) target_compile_options(PlatformCommonInternal INTERFACE -Wa,-mbig-obj)
endif() endif()