build: enable -Werror with a documented exception list (#15660)

This commit is contained in:
Kris Austin
2026-09-12 13:52:05 -05:00
committed by GitHub
parent fe0d47c7a3
commit bb8c2ae5ce

View File

@@ -557,59 +557,101 @@ if ((NOT MSVC OR IS_CLANG_CL) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
elseif (NOT MINGW) elseif (NOT MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
endif () endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder" )
# On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error. # Every warning is an error unless it appears in one of the two lists below.
add_compile_options(-Werror=return-type) # disabled - never wanted. Off everywhere, so it never warns or errors.
# demoted - wanted, not cleared yet. Still warns, does not error.
# Since some portions of code are just commented out or put under conditional compilation, there are # Disabled.
# a bunch of warning related to unused functions and variables. Suppress those warnings to not pollute set(warnings_disabled
# compilers diagnostics output with warnings we not going to look at reorder # members initialised in an order we chose
add_compile_options(-Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-label -Wno-unused-local-typedefs) sign-compare # signed/unsigned comparisons throughout
misleading-indentation # false positives on mixed tabs and spaces
switch # unhandled enum value in a switch
unused-function # commented-out or conditionally compiled code
unused-variable # commented-out or conditionally compiled code
unused-but-set-variable # commented-out or conditionally compiled code
unused-label # commented-out or conditionally compiled code
unused-local-typedefs # commented-out or conditionally compiled code
)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND warnings_disabled deprecated-declarations) # legacy OpenGL calls
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
list(APPEND warnings_disabled ignored-attributes) # from Eigen headers marked SYSTEM
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND warnings_disabled unknown-pragmas) # igl pragmas, GCC bug 66943
endif ()
foreach (w IN LISTS warnings_disabled)
add_compile_options(-Wno-${w})
endforeach ()
# Ignore signed/unsigned comparison warnings # Turn everything else into an error. Dependency headers are exempt because the SYSTEM
add_compile_options(-Wno-sign-compare) # include flag (-imsvc on clang-cl, -isystem elsewhere) keeps their diagnostics out,
# apart from GCC's maybe-uninitialized, demoted below.
add_compile_options(-Werror)
# The mismatch of tabs and spaces throughout the project can sometimes # Demoted. Remove a name once its category is cleared on every compiler.
# cause this warning to appear even though the indentation is fine. set(warnings_demoted)
# Some includes also cause the warning if (APPLE)
add_compile_options(-Wno-misleading-indentation) list(APPEND warnings_demoted
# MacDarkMode.mm makes two calls to AppKit's private titlebarViewController
# and one to a wxWidgets category on NSTableColumn whose header is not
# imported. Clearing it means declaring the private selectors ourselves, which
# needs a macOS build to verify.
objc-method-access
)
endif ()
if (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
list(APPEND warnings_demoted
# About two dozen GetProcAddress casts, most in the vendored dark_mode.hpp,
# retype FARPROC to a real signature. The __stdcall typedefs are identical to
# FARPROC on x64, so only arm64 reports them. Clearing them is a separate
# sweep.
cast-function-type-mismatch
)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
list(APPEND warnings_demoted
# maybe-uninitialized runs after inlining and reports inside boost/variant,
# boost/tuple and the bundled clipper header even with -isystem.
maybe-uninitialized
# Disable warning if enum value does not have a corresponding case in switch statement # array-bounds is reported once, where ConfigOptionVector::set_at inlines
add_compile_options(-Wno-switch) # into OrcaSlicer.cpp on a branch the preceding type test rules out.
array-bounds
# removes LOTS of extraneous Eigen warnings (GCC only supports it since 6.1) # template-id-cdtor is a GCC 14+ warning in the bundled Clipper2 headers.
# https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1221 template-id-cdtor
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0) )
add_compile_options(-Wno-ignored-attributes) # Tamas: Eigen include dirs are marked as SYSTEM endif ()
endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND warnings_demoted
# enum-constexpr-conversion is a Clang warning that defaults to an error,
# present through clang 20 and gone in clang 21.
enum-constexpr-conversion
)
endif ()
# Clang reports legacy OpenGL calls as deprecated. Turn off the warning for now # The list mixes names not every compiler has, so add each exception only where the
# to reduce the clutter, we know about this one. It should be reenabled after # compiler knows the warning. Probe with the positive -W<name>, which an unknown
# we finally get rid of the deprecated code. # warning fails on both compilers (GCC errors, Clang reports unknown-warning-option).
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") # An option that takes a =N argument rejects the bare -W<name>, so fall back to
add_compile_options(-Wno-deprecated-declarations) # -W<name>=1 and demote with the trailing =.
endif() include(CheckCXXCompilerFlag)
foreach (category IN LISTS warnings_demoted)
if((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang") AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER 15) string(MAKE_C_IDENTIFIER "ORCA_HAS_W_${category}" _orca_has_w)
include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-W${category}" ${_orca_has_w})
check_cxx_compiler_flag(-Wno-error=enum-constexpr-conversion HAS_WNO_ERROR_ENUM_CONSTEXPR_CONV) if (${_orca_has_w})
if(HAS_WNO_ERROR_ENUM_CONSTEXPR_CONV) add_compile_options(-Wno-error=${category})
add_compile_options(-Wno-error=enum-constexpr-conversion) else ()
endif() check_cxx_compiler_flag("-W${category}=1" ${_orca_has_w}_arg)
endif() if (${${_orca_has_w}_arg})
add_compile_options(-Wno-error=${category}=)
#GCC generates loads of -Wunknown-pragmas when compiling igl. The fix is not easy due to a bug in gcc, see endif ()
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or endif ()
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431 endforeach ()
# We will turn the warning of for GCC for now:
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# GCC generates loads of -Wunknown-pragmas when compiling igl. The fix is not easy due to a bug in gcc, see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
# We will turn the warning of for GCC for now:
add_compile_options(-Wno-unknown-pragmas)
endif()
# Compress the debug info with zstd to save space in Flatpak CI builds # Compress the debug info with zstd to save space in Flatpak CI builds
if(FLATPAK) if(FLATPAK)
@@ -619,10 +661,6 @@ if ((NOT MSVC OR IS_CLANG_CL) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
endif() endif()
endif() endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=template-id-cdtor" )
endif()
endif() endif()
if (SLIC3R_ASAN) if (SLIC3R_ASAN)
@@ -1212,8 +1250,9 @@ endif ()
if (NOT SLIC3R_WARNINGS) if (NOT SLIC3R_WARNINGS)
add_compile_options(-w) add_compile_options(-w)
elseif (MSVC AND NOT IS_CLANG_CL) elseif (MSVC AND NOT IS_CLANG_CL)
# /we4715 is C4715, no return from a non-void function, matching the # /we4715 is C4715, no return from a non-void function, an error on the GNU/Clang
# -Werror=return-type the GNU/Clang builds apply. # builds under -Werror. MSVC is not in that model, so this stays a single promoted
# warning.
add_compile_options(/W3 /we4715) add_compile_options(/W3 /we4715)
endif () endif ()