Overhaul compiler warnings infrastructure

* Track our warnings separate from normal flags
* Remove all warnings from the SWIG code
* Add more GCC warnings
This commit is contained in:
Ian McInerney 2020-05-06 01:47:20 +01:00
parent 2148c593d6
commit e4b6487fca
13 changed files with 95 additions and 64 deletions

View File

@ -302,11 +302,6 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set( CMAKE_CXX_FLAGS "-ffloat-store ${CMAKE_CXX_FLAGS}" ) set( CMAKE_CXX_FLAGS "-ffloat-store ${CMAKE_CXX_FLAGS}" )
endif() endif()
# Establish -Wall early, so specialized relaxations of this may come
# subsequently on the command line, such as in pcbnew/github/CMakeLists.txt
set( CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}" )
set( CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}" )
# Link flags in Debug: -g1 and -ggdb1 or -g1 and -ggdb3 can be used. # Link flags in Debug: -g1 and -ggdb1 or -g1 and -ggdb3 can be used.
# Level 1 produces minimal information, enough for making basic backtraces. # Level 1 produces minimal information, enough for making basic backtraces.
# This includes descriptions of functions and external variables, and line number tables, # This includes descriptions of functions and external variables, and line number tables,

View File

@ -26,11 +26,23 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
include( CheckCXXCompilerFlag ) include( CheckCXXCompilerFlag )
# The SWIG-generated files tend to throw a lot of warnings, so
# we do not add the warnings directly to the flags here but instead
# keep track of them and add them to the flags later in a controlled manner
# (that way we can not put any warnings on the SWIG-generated files)
set( COMPILER_SUPPORTS_WARNINGS TRUE )
# Establish -Wall early, so specialized relaxations of this may come
# subsequently on the command line, such as in pcbnew/github/CMakeLists.txt
set( WARN_FLAGS_C "-Wall" )
set( WARN_FLAGS_CXX "-Wall" )
# Warn about missing override specifiers # Warn about missing override specifiers
CHECK_CXX_COMPILER_FLAG( "-Wsuggest-override" COMPILER_SUPPORTS_WSUGGEST_OVERRIDE ) CHECK_CXX_COMPILER_FLAG( "-Wsuggest-override" COMPILER_SUPPORTS_WSUGGEST_OVERRIDE )
if( COMPILER_SUPPORTS_WSUGGEST_OVERRIDE ) if( COMPILER_SUPPORTS_WSUGGEST_OVERRIDE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override" ) set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wsuggest-override" )
message( STATUS "Enabling warning -Wsuggest-override" ) message( STATUS "Enabling warning -Wsuggest-override" )
endif() endif()
@ -39,15 +51,34 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
CHECK_CXX_COMPILER_FLAG( "-Winconsistent-missing-override" COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE ) CHECK_CXX_COMPILER_FLAG( "-Winconsistent-missing-override" COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE )
if( COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE ) if( COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winconsistent-missing-override" ) set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Winconsistent-missing-override" )
message( STATUS "Enabling warning -Winconsistent-missing-override" ) message( STATUS "Enabling warning -Winconsistent-missing-override" )
endif() endif()
# Warn on duplicated branches
CHECK_CXX_COMPILER_FLAG( "-Wduplicated-branches" COMPILER_SUPPORTS_WDUPLICATED_BRANCHES )
if( COMPILER_SUPPORTS_WDUPLICATED_BRANCHES )
set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wduplicated-branches" )
message( STATUS "Enabling warning -Wduplicated-branches" )
endif()
# Warn on duplicated conditions
CHECK_CXX_COMPILER_FLAG( "-Wduplicated-cond" COMPILER_SUPPORTS_WDUPLICATED_COND )
if( COMPILER_SUPPORTS_WDUPLICATED_COND )
set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wduplicated-cond" )
message( STATUS "Enabling warning -Wduplicated-cond" )
endif()
CHECK_CXX_COMPILER_FLAG( "-Wvla" COMPILER_SUPPORTS_WVLA ) CHECK_CXX_COMPILER_FLAG( "-Wvla" COMPILER_SUPPORTS_WVLA )
if( COMPILER_SUPPORTS_WVLA ) if( COMPILER_SUPPORTS_WVLA )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=vla" ) set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Werror=vla" )
message( STATUS "Enabling error for -Wvla" ) message( STATUS "Enabling error for -Wvla" )
endif() endif()
@ -56,7 +87,13 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
CHECK_CXX_COMPILER_FLAG( "-Wimplicit-fallthrough" COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH ) CHECK_CXX_COMPILER_FLAG( "-Wimplicit-fallthrough" COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH )
if( COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH ) if( COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough" ) if( CMAKE_COMPILER_IS_GNUCXX )
# GCC level 5 does not allow comments - mirrors the Clang warning
set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wimplicit-fallthrough=5" )
else()
set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wimplicit-fallthrough" )
endif()
message( STATUS "Enabling warning -Wimplicit-fallthrough" ) message( STATUS "Enabling warning -Wimplicit-fallthrough" )
endif() endif()
@ -65,20 +102,16 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
CHECK_CXX_COMPILER_FLAG( "-Wreturn-type" COMPILER_SUPPORTS_WRETURN_TYPE ) CHECK_CXX_COMPILER_FLAG( "-Wreturn-type" COMPILER_SUPPORTS_WRETURN_TYPE )
if( COMPILER_SUPPORTS_WRETURN_TYPE ) if( COMPILER_SUPPORTS_WRETURN_TYPE )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type" ) set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Werror=return-type" )
message( STATUS "Enabling error for -Wreturn-type" ) message( STATUS "Enabling error for -Wreturn-type" )
endif() endif()
# Warn about shadowed variables (-Wshadow option), if supported # Warn about shadowed variables
# 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 ) CHECK_CXX_COMPILER_FLAG( "-Wshadow" COMPILER_SUPPORTS_WSHADOW )
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WSHADOW )
set( WSHADOW_FLAGS "-Wshadow" ) set( WARN_FLAGS_CXX "${WARN_FLAGS_CXX} -Wshadow" )
message( STATUS "Enabling warning -Wshadow" ) message( STATUS "Enabling warning -Wshadow" )
endif() endif()

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions( -DBITMAP_2_CMP ) add_definitions( -DBITMAP_2_CMP )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_subdirectory( libeval ) add_subdirectory( libeval )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions( -DCVPCB ) add_definitions( -DCVPCB )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions( -DEESCHEMA ) add_definitions( -DEESCHEMA )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions(-DGERBVIEW) add_definitions(-DGERBVIEW)

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions( -DKICAD ) add_definitions( -DKICAD )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_definitions(-DPL_EDITOR) add_definitions(-DPL_EDITOR)

View File

@ -359,36 +359,29 @@ set( PCBNEW_SCRIPTING_PYTHON_HELPERS
swig/python_scripting.cpp swig/python_scripting.cpp
) )
if( COMPILER_SUPPORTS_WSHADOW )
# .cpp files are compiled with extra ${WSHADOW_FLAGS}, but not .cxx files if( COMPILER_SUPPORTS_WARNINGS )
# Only compile our source files with the warnings, since the SWIG generated
# files contain a lot of warnings, we just ignore it.
set_source_files_properties( set_source_files_properties(
${PCBNEW_SRCS} ${PCBNEW_COMMON_SRCS} ${PCBNEW_SCRIPTING_DIALOGS} ${PCBNEW_SCRIPTING_PYTHON_HELPERS} ${PCBNEW_SRCS} ${PCBNEW_COMMON_SRCS} ${PCBNEW_SCRIPTING_DIALOGS} ${PCBNEW_SCRIPTING_PYTHON_HELPERS}
PROPERTIES COMPILE_FLAGS ${WSHADOW_FLAGS} PROPERTIES COMPILE_FLAGS ${WARN_FLAGS_CXX}
)
# There is a lot of 'local variable shadowed' warnings,
# but we have no control over the generated code
set_source_files_properties( pcbnew_wrap.cxx pcbnewPYTHON_wrap.cxx
PROPERTIES COMPILE_FLAGS -Wno-shadow
) )
endif() endif()
if( KICAD_SCRIPTING ) if( KICAD_SCRIPTING )
# Disable all warnings for the SWIG file
if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set_source_files_properties( pcbnew_wrap.cxx PROPERTIES COMPILE_FLAGS "-Wno-everything" )
endif()
set( PCBNEW_SCRIPTING_SRCS set( PCBNEW_SCRIPTING_SRCS
${PCBNEW_SCRIPTING_DIALOGS} ${PCBNEW_SCRIPTING_DIALOGS}
pcbnew_wrap.cxx pcbnew_wrap.cxx
${PCBNEW_SCRIPTING_PYTHON_HELPERS} ${PCBNEW_SCRIPTING_PYTHON_HELPERS}
) )
# Swig generated files do not use the override specifier, therefore
# disable suggest-override warnings
if( COMPILER_SUPPORTS_WSUGGEST_OVERRIDE )
set_source_files_properties( pcbnew_wrap.cxx pcbnewPYTHON_wrap.cxx
PROPERTIES COMPILE_FLAGS -Wno-suggest-override
)
endif()
endif() endif()

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
include_directories( include_directories(

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
include_directories( BEFORE ${INC_BEFORE} ${INC_AFTER} ) include_directories( BEFORE ${INC_BEFORE} ${INC_AFTER} )

View File

@ -1,6 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS} # Add all the warnings to the files
if( COMPILER_SUPPORTS_WSHADOW ) if( COMPILER_SUPPORTS_WARNINGS )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARN_FLAGS_CXX}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS_C}")
endif() endif()
add_subdirectory( idftools ) add_subdirectory( idftools )