From c4ab2f6b9eaa65a266ad7b9339eb1fc57983476b Mon Sep 17 00:00:00 2001 From: lizzie Date: Sun, 9 Aug 2026 02:56:28 +0200 Subject: [PATCH] [cmake] Add ENABLE_WERROR option (#4080) Should warnings be errors? that's a philosophical debate which I can only answer with "no, but if you think otherwise here is an option for you" Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4080 Reviewed-by: crueter Reviewed-by: MaranBr --- CMakeLists.txt | 14 ++++++++++++++ docs/Options.md | 2 ++ src/CMakeLists.txt | 28 ++++++++++++++++++++-------- src/audio_core/CMakeLists.txt | 2 +- src/common/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 2 +- src/hid_core/CMakeLists.txt | 2 +- src/input_common/CMakeLists.txt | 2 +- src/shader_recompiler/CMakeLists.txt | 2 +- src/video_core/CMakeLists.txt | 2 +- 10 files changed, 43 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1039ddfed4..8085604de2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ set(YUZU_QT_MIRROR "" CACHE STRING "What mirror to use for downloading the bundl cmake_dependent_option(YUZU_USE_BUNDLED_QT "Download bundled Qt binaries" "${MSVC}" "ENABLE_QT" OFF) option(ENABLE_DEBUG_TOOLS "Enable debugging tools (maxwell disassembler, SPIRV translator, etc)" OFF) +option(ENABLE_WERROR "Enable -Werror diagnostics" ON) # non-linux bundled qt are static if (YUZU_USE_BUNDLED_QT AND (APPLE OR NOT UNIX)) @@ -157,6 +158,19 @@ if (CXX_CLANG_CL) $<$:-Wno-reserved-identifier> $<$:-Wno-deprecated-declarations> $<$:-Wno-cast-function-type-mismatch> + $<$:-Wno-c99-extensions> + $<$:-Wno-c++17-compat> + $<$:-Wno-c++11-compat-reserved-user-defined-literal> + $<$:-Wno-c++11-compat-deprecated-writable-strings> + $<$:-Wno-c++11-compat-pedantic> + $<$:-Wno-c++11-compat> + $<$:-Wno-c++0x-compat> + $<$:-Wno-c++98-c++11-compat-binary-literal> + $<$:-Wno-c++98-compat-pedantic> + $<$:-Wno-c++98-compat> + $<$:-Wno-c99-compat> + $<$:-Wno-c98-compat> + $<$:-Wno-c99-extensions> $<$:/EHsc>) # REQUIRED CPU features IN Windows-amd64 if (ARCHITECTURE_x86_64) diff --git a/docs/Options.md b/docs/Options.md index bd353b16ca..a8552f2f0f 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -46,6 +46,8 @@ These options control dependencies. - `YUZU_INSTALL_UDEV_RULES` (OFF) Install udev rules to enable hidraw access - Needed for gyroscopes - Only available on Linux +- `ENABLE_DEBUG_TOOLS` (OFF) Enables debugging and development tools, see [tools](../tools/README.md). +- `ENABLE_WERROR` (ON) Enables warnings as errors (-Werror). ### Flavors diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6d526c5eb..882aff70f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -155,12 +155,24 @@ else() $<$:-fno-rtti>) endif() + if (ENABLE_WERROR) + add_compile_options( + $<$:-Werror=all> + $<$:-Werror=extra> + $<$:-Werror=missing-declarations> + $<$:-Werror=shadow> + $<$:-Werror=unused>) + else() + add_compile_options( + $<$:-Wall> + $<$:-Wextra> + $<$:-Wmissing-declarations> + $<$:-Wshadow> + $<$:-Wunused> + # Some compilers could particularly misbehave :) + $<$:-Wno-error-all>) + endif() add_compile_options( - $<$:-Werror=all> - $<$:-Werror=extra> - $<$:-Werror=missing-declarations> - $<$:-Werror=shadow> - $<$:-Werror=unused> $<$:-Wno-attributes> $<$:-Wno-invalid-offsetof> $<$:-Wno-unused-parameter> @@ -169,9 +181,9 @@ else() if (CXX_CLANG OR CXX_ICC OR CXX_APPLE) # Clang, AppleClang, or Intel C++ if (NOT MSVC) add_compile_options( - $<$:-Werror=shadow-uncaptured-local> - $<$:-Werror=implicit-fallthrough> - $<$:-Werror=type-limits>) + $<$:-Wshadow-uncaptured-local> + $<$:-Wimplicit-fallthrough> + $<$:-Wtype-limits>) endif() add_compile_options( $<$:-Wno-braced-scalar-init> diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt index 4d0b130afc..b186edaab4 100644 --- a/src/audio_core/CMakeLists.txt +++ b/src/audio_core/CMakeLists.txt @@ -222,7 +222,7 @@ if (MSVC) ) else() target_compile_options(audio_core PRIVATE - $<$:-Werror=conversion> + $<$:-Wconversion> $<$:-Wno-sign-conversion>) endif() diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 923d001442..10e8cd0cc7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -220,7 +220,7 @@ endif() if(CXX_CLANG) target_compile_options(common PRIVATE $<$:-fsized-deallocation> - $<$:-Werror=unreachable-code-aggressive>) + $<$:-Wunreachable-code-aggressive>) target_compile_definitions( common PRIVATE diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 16806ff0c0..8e01a67c20 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1199,7 +1199,7 @@ if (MSVC) ) else() target_compile_options(core PRIVATE - $<$:-Werror=conversion> + $<$:-Wconversion> $<$:-Wno-sign-conversion> $<$:-Wno-cast-function-type> $<$:-fsized-deallocation>) diff --git a/src/hid_core/CMakeLists.txt b/src/hid_core/CMakeLists.txt index c740cdbe7f..e617160834 100644 --- a/src/hid_core/CMakeLists.txt +++ b/src/hid_core/CMakeLists.txt @@ -151,7 +151,7 @@ if (MSVC) ) else() target_compile_options(hid_core PRIVATE - $<$:-Werror=conversion> + $<$:-Wconversion> $<$:-Wno-sign-conversion> $<$:-Wno-cast-function-type> $<$:-fsized-deallocation>) diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 91dd8558ab..840602f4ce 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -44,7 +44,7 @@ if (MSVC) /we4800 # Implicit conversion from 'type' to bool. Possible information loss ) else() - target_compile_options(input_common PRIVATE $<$:-Werror=conversion>) + target_compile_options(input_common PRIVATE $<$:-Wconversion>) endif() if (ANDROID) diff --git a/src/shader_recompiler/CMakeLists.txt b/src/shader_recompiler/CMakeLists.txt index d02ee268f0..1e6a4d173a 100644 --- a/src/shader_recompiler/CMakeLists.txt +++ b/src/shader_recompiler/CMakeLists.txt @@ -253,7 +253,7 @@ if (MSVC) ) else() target_compile_options(shader_recompiler PRIVATE - $<$:-Werror=conversion> + $<$:-Wconversion> # Bracket depth determines maximum size of a fold expression in Clang since 9c9974c3ccb6. # And this in turns limits the size of a std::array. $<$:-fbracket-depth=1024> diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index aba602c3b3..6720195c0e 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -373,7 +373,7 @@ else() $<$:-Wno-shadow> $<$:-Wno-unused-local-typedef>) else() - target_compile_options(video_core PRIVATE $<$:-Werror=conversion>) + target_compile_options(video_core PRIVATE $<$:-Wconversion>) endif() target_compile_options(video_core PRIVATE $<$:-Wno-sign-conversion>)