From 106d115c3e338fe3d4a5bdc3c946380b69bd9253 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 5 Nov 2022 02:56:50 -0500 Subject: [PATCH] cmake: Port warning configuration from make Adds SRB2_CONFIG_ERRORMODE to replace ERRORMODE too. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 134 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 082093140..16eb5f9e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ cmake_dependent_option( ) option(SRB2_CONFIG_HWRENDER "Enable hardware render (OpenGL) support" ON) option(SRB2_CONFIG_STATIC_OPENGL "Enable static linking GL (do not do this)" OFF) +option(SRB2_CONFIG_ERRORMODE "Compile C code with warnings treated as errors. (C++ warnings are always treated as errors)" OFF) set(SRB2_CONFIG_ASSET_DIRECTORY "" CACHE PATH "Path to directory that contains all asset files for the installer. If set, assets will be part of installation and cpack.") # Enable CCache diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c98019e8..97d484421 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -128,13 +128,141 @@ endif() # We should really fix our code to not need this if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) - target_compile_options(SRB2SDL2 PRIVATE -Wno-trigraphs) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - target_compile_options(SRB2SDL2 PRIVATE -Wno-absolute-value) +# Compiler warnings configuration +target_compile_options(SRB2SDL2 PRIVATE + # Using generator expressions to handle per-language compile options + + # C, GNU + # This is a direct translation from versions.mk + $<$,$>: + -Wall + -Wno-trigraphs + -W # Was controlled by RELAXWARNINGS + -Wfloat-equal + -Wundef + -Wpointer-arith + -Wbad-function-cast + -Wcast-qual + -Wcast-align # Was controlled by NOCASTALIGNWARN + -Wwrite-strings + -Wsign-compare + -Waggregate-return + -Wmissing-prototypes + -Wmissing-declarations + -Wmissing-noreturn + -Wnested-externs + -Winline + -Wformat-y2k + -Wformat-security + + $<$,2.9.5>: + -Wno-div-by-zero + -Wendif-labels + -Wdisabled-optimization + > + + $<$,4.0.0>: + -Wold-style-definition + -Wmissing-field-initializers + > + + $<$,4.1.0>: + -Wshadow + > + + $<$,4.3.0>: + -funit-at-a-time + -Wlogical-op + > + + $<$,4.5.0>: + -Wlogical-op + -Wno-error=array-bounds + > + + $<$,4.6.0>: + -Wno-suggest-attribute=noreturn + -Wno-error=suggest-attribute=noreturn + > + + $<$,5.4.0>: + -Wno-logical-op + -Wno-error=logical-op + > + + $<$,6.1.0>: + -Wno-tautological-compare + -Wno-error=tautological-compare + > + + $<$,7.1.0>: + -Wno-error=format-overflow=2 + -Wimplicit-fallthrough=4 + > + + $<$,8.1.0>: + -Wno-error=format-overflow + -Wno-error=stringop-truncation + -Wno-error=stringop-overflow + -Wno-format-overflow + -Wno-stringop-truncation + -Wno-stringop-overflow + -Wno-error=multistatement-macros + > + + $<$,9.1.0>: + -Wno-error=address-of-packed-member + > + > + + # C, Clang and Apple Clang + $<$,$,$>>: + -Wall + -Wno-absolute-value + -Wno-trigraphs + -Wno-error=non-literal-null-conversion + -Wno-error=constant-conversion + -Wno-error=unused-but-set-variable + > + + # C, MSVC + $<$,$>: + # All warnings at and before Visual Studio 2019 RTM + # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170 + /Wv:19.20.27004.0 + > + + # C++, GNU, Clang and Apple Clang + $<$,$,$,$>>: + -Wall + > + + # C++, MSVC + $<$,$>: + /Wv:19.20.27004.0 + > +) +if(SRB2_CONFIG_ERRORMODE) + target_compile_options(SRB2SDL2 PRIVATE + $<$,$,$>: + -Werror + > + + $<$: + /WX + > + ) endif() +# Link warnings configuration +target_link_options(SRB2SDL2 PRIVATE + $<$: + # -Wl,--as-needed - Was controlled by NOLDWARNING + > +) + if(${SRB2_CONFIG_DEV_BUILD}) target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP) endif()