From 6fb838ec1f244829183529319b6240ea09e5f495 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sat, 4 Mar 2023 11:03:08 +0000 Subject: [PATCH 1/2] Add a CMake option to turn warnings into errors The option is disabled by default as it can get in the way of people merely building PortAudio (as opposed to doing development work). This is provided as a CMake option so that it can easily be switched on by people doing local development. The option will eventually be turned on in CI. In this mode pre-existing warnings are suppressed, in other words they are "grandfathered" in for the sake of preventing build breakage. The idea is to enable enforcement first to prevent backsliding, and then we can take care of existing warnings later. --- CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d8106288..873e0d0e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,43 @@ else() set(LIBRARY_BUILD_TYPE STATIC) endif() +option(PA_WARNINGS_ARE_ERRORS "Turn compiler warnings into errors" OFF) +if(PA_WARNINGS_ARE_ERRORS) + if(MSVC) + add_compile_options(/WX + # "Grandfathered" warnings that existed before we started enforcement. + # Do *NOT* add warnings to this list. Instead, fix your code so that it doesn't produce the warning. + # TODO: fix the offending code so that we don't have to exclude specific warnings anymore. + /wd4018 # W3 signed/unsigned mismatch + /wd4024 # W1 different types for formal and actual parameter + /wd4047 # W1 differs in levels of indirection + /wd4101 # W3 unreferenced local variable + /wd4133 # W3 incompatible types + /wd4146 # W2 unary minus operator applied to unsigned type, result still unsigned + /wd4244 # W2 conversion possible loss of data + /wd4267 # W3 conversion possible loss of data + /wd4305 # W1 truncation + /wd4477 # W1 format string requires an argument of type, but variadic argument number has type + /wd4996 # W3 unsafe/deprecated + ) + else() + add_compile_options(-Werror + # "Grandfathered" warnings that existed before we started enforcement. + # Do *NOT* add warnings to this list. Instead, fix your code so that it doesn't produce the warning. + # TODO: fix the offending code so that we don't have to exclude specific warnings anymore. + -Wno-error=deprecated-declarations # https://github.com/PortAudio/portaudio/issues/213 https://github.com/PortAudio/portaudio/issues/641 + -Wno-error=incompatible-pointer-types + -Wno-error=int-conversion + -Wno-error=stringop-overflow + ) + if (CMAKE_C_COMPILER_ID MATCHES "Clang") + # Don't fail on older clang versions that don't recognize the latest warnings in the list above. + # Note that unrecognized warning options are not a fatal error on GCC, and in fact, GCC will choke on this option. Hence the conditional. + add_compile_options(-Wno-error=unknown-warning-option) + endif() + endif() +endif() + add_library(PortAudio ${LIBRARY_BUILD_TYPE} src/common/pa_allocation.c From ec04223154d437f57b60386e4d934e2585f2899a Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sat, 4 Mar 2023 11:45:40 +0000 Subject: [PATCH 2/2] Enforce no warnings through the CMake CI This will prevent backsliding by failing CI on any code that produces new types of warnings. --- .github/workflows/cmake.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 52f23cead..a25eaabf7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -114,6 +114,7 @@ jobs: -DPA_USE_SKELETON=ON -DPA_BUILD_TESTS=ON -DPA_BUILD_EXAMPLES=ON + -DPA_WARNINGS_ARE_ERRORS=ON -S . -B build - name: build