From 5a4e4aea6734560b0e1b4206f1475c49faa00c49 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 25 Apr 2020 00:46:29 +0100 Subject: [PATCH] Enable new warnings --- CMakeLists.txt | 35 +---------------- CMakeModules/Warnings.cmake | 76 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 CMakeModules/Warnings.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c81bd8b625..a288395aac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,39 +240,8 @@ if( CMAKE_VERSION VERSION_LESS 3.1 AND ( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_C endif() -# Warn about missing override specifiers, if supported -if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) - include(CheckCXXCompilerFlag) - - CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" COMPILER_SUPPORTS_WSUGGEST_OVERRIDE) - - if(COMPILER_SUPPORTS_WSUGGEST_OVERRIDE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override") - endif() - - CHECK_CXX_COMPILER_FLAG("-Wvla" COMPILER_SUPPORTS_WVLA) - - if(COMPILER_SUPPORTS_WVLA) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=vla") - endif() - -endif() - - -# Warn about shadowed variables (-Wshadow option), if supported -# Unfortunately, the swig autogenerated files have a lot of shadowed variables -# and -Wno-shadow does not exist. -# Adding -Wshadow can be made only for .cpp files -# and will be added later in CMakeLists.txt -if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) - include(CheckCXXCompilerFlag) - - CHECK_CXX_COMPILER_FLAG("-Wshadow" COMPILER_SUPPORTS_WSHADOW) - - if( COMPILER_SUPPORTS_WSHADOW ) - set(WSHADOW_FLAGS "-Wshadow") - endif() -endif() +# Setup the compiler warnings +include( ${CMAKE_MODULE_PATH}/Warnings.cmake ) if( WIN32 ) # define UNICODE and_UNICODE definition on Windows. KiCad uses unicode. diff --git a/CMakeModules/Warnings.cmake b/CMakeModules/Warnings.cmake new file mode 100644 index 0000000000..8586872686 --- /dev/null +++ b/CMakeModules/Warnings.cmake @@ -0,0 +1,76 @@ +# +# This program source code file is part of KICAD, a free EDA CAD application. +# +# Copyright (C) 2007-2020 Kicad Developers, see AUTHORS.txt for contributors. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, you may find one here: +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# or you may search the http://www.gnu.org website for the version 2 license, +# or you may write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +# + +# Only configure warnings for Clang and GCC +if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) + include( CheckCXXCompilerFlag ) + + + # Warn about missing override specifiers + CHECK_CXX_COMPILER_FLAG( "-Wsuggest-override" COMPILER_SUPPORTS_WSUGGEST_OVERRIDE ) + + if( COMPILER_SUPPORTS_WSUGGEST_OVERRIDE ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override" ) + message( STATUS "Enabling warning -Wsugest-override" ) + endif() + + + CHECK_CXX_COMPILER_FLAG( "-Wvla" COMPILER_SUPPORTS_WVLA ) + + if( COMPILER_SUPPORTS_WVLA ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=vla" ) + message( STATUS "Enabling error for -Wvla" ) + endif() + + + # Warn on implicit switch fallthrough + CHECK_CXX_COMPILER_FLAG( "-Wimplicit-fallthrough" COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH ) + + if( COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough" ) + message( STATUS "Enabling warning -Wimplicit-fallthrough" ) + endif() + + + # Error if there is a problem with function returns + CHECK_CXX_COMPILER_FLAG( "-Wreturn-type" COMPILER_SUPPORTS_WRETURN_TYPE ) + + if( COMPILER_SUPPORTS_WRETURN_TYPE ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type" ) + message( STATUS "Enabling error for -Wreturn-type" ) + endif() + + + # Warn about shadowed variables (-Wshadow option), if supported + # Unfortunately, the swig autogenerated files have a lot of shadowed variables + # and -Wno-shadow does not exist. + # Adding -Wshadow can be made only for .cpp files + # and will be added later in CMakeLists.txt + CHECK_CXX_COMPILER_FLAG( "-Wshadow" COMPILER_SUPPORTS_WSHADOW ) + + if( COMPILER_SUPPORTS_WSHADOW ) + set( WSHADOW_FLAGS "-Wshadow" ) + message( STATUS "Enabling warning -Wshadow" ) + endif() + +endif()