From 45a13570f1ad7178a232230510e4dcbafa9d71d8 Mon Sep 17 00:00:00 2001 From: Parker Philip Gibson Date: Fri, 3 Jan 2020 03:56:57 -0600 Subject: [PATCH 1/3] missing-prototypes Contributor @strager had recommended enabling missing-prototypes, which proved us eful for identifying unused code. In addition to missing-prototypes, this will en able -Wall and -Werror for C code. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e3b3498..0b9fffc93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID} if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-Wno-multichar -Wno-sign-compare) endif () +elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + add_compile_options(-Wall -Werror -Wmissing-prototypes) else () message(WARNING "Compiler not supported to enable warnings.") endif () From a78cdea8d076bbdf4d1234bd26c336dc806cc0c6 Mon Sep 17 00:00:00 2001 From: Parker Philip Gibson Date: Thu, 9 Jan 2020 00:23:22 -0600 Subject: [PATCH 2/3] Revert "missing-prototypes" add_compile_options() will need CMake generator expressions to distinguish between invocations of C and C++ compilers. This commit did not solve the issue and may cause build errors if the missing-prototypes option is passed to C++ compilers. This reverts commit 45a13570f1ad7178a232230510e4dcbafa9d71d8. --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b9fffc93..35e3b3498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID} if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-Wno-multichar -Wno-sign-compare) endif () -elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") - add_compile_options(-Wall -Werror -Wmissing-prototypes) else () message(WARNING "Compiler not supported to enable warnings.") endif () From 32e37e9047c51deb25572ffd53331fab9bc83085 Mon Sep 17 00:00:00 2001 From: Parker Philip Gibson Date: Thu, 9 Jan 2020 00:26:41 -0600 Subject: [PATCH 3/3] missing-prototypes & missing-declarations Contributor @strager had recommended enabling missing-prototypes, which proved useful for identifying unused code. I have added warning options -Wmissing-declarations and for the C compiler -Wmissing-prototypes. Until these warnings are taken care of, I've disabled errors for these warnings. --- CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35e3b3498..5127ce456 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,8 +61,19 @@ endif () # Enable all warnings. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") add_compile_options(/D_CRT_SECURE_NO_WARNINGS) # TODO: /Wall /WX -elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - add_compile_options(-Wall -Werror) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR + "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR + "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + add_compile_options(-Wall -Werror -Wmissing-declarations + $<$:-Wmissing-prototypes> + #Until we add explicit prototypes/declarations for definitions which + #themselves provide a prototype, treating these warnings as errors will + #break builds. + #Once prototypes and declarations are added please remove the following + # -Wno-error options. + -Wno-error=missing-declarations + $<$:-Wno-error=missing-prototypes>) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-Wno-multichar -Wno-sign-compare) endif ()