Add -Wshadow compil option, if exists to warn about shadowed variables.

Swig auto generated .cxx file has a lot of shadowed variables, so this option cannot be used to compil all files.
This commit is contained in:
jean-pierre charras 2017-02-23 11:40:40 +01:00
parent a9d6af8001
commit 11dcb76fc9
12 changed files with 70 additions and 1 deletions

View File

@ -194,6 +194,21 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
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()
#================================================
# Set flags for GCC, or treat llvm as GCC
#================================================

View File

@ -1,3 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
include_directories( BEFORE ${INC_BEFORE} )
include_directories(

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
include_directories( BEFORE ${INC_BEFORE} )
include_directories(
./dialogs

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_definitions( -DCVPCB )
include_directories( BEFORE ${INC_BEFORE} )

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_definitions( -DEESCHEMA )
if( KICAD_SPICE )

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_definitions(-DGERBVIEW)
include_directories( BEFORE ${INC_BEFORE} )

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_definitions( -DKICAD )
include_directories( BEFORE ${INC_BEFORE} )

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_definitions(-DPL_EDITOR)
include_directories(BEFORE ${INC_BEFORE})

View File

@ -341,6 +341,13 @@ set( PCBNEW_SCRIPTING_PYTHON_HELPERS
swig/pcbnew_action_plugins.cpp
)
# .cpp files are compiled with extra ${WSHADOW_FLAGS}, but not .cxx files
set_source_files_properties(
${PCBNEW_SRCS} ${PCBNEW_COMMON_SRCS} ${PCBNEW_SCRIPTING_DIALOGS} ${PCBNEW_SCRIPTING_PYTHON_HELPERS}
PROPERTIES COMPILE_FLAGS ${WSHADOW_FLAGS}
)
if( KICAD_SCRIPTING )
set( PCBNEW_SCRIPTING_SRCS
${PCBNEW_SCRIPTING_DIALOGS}
@ -356,7 +363,6 @@ if( KICAD_SCRIPTING )
PROPERTIES COMPILE_FLAGS -Wno-suggest-override
)
endif()
endif()

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
include_directories(
${GLM_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/include

View File

@ -1,3 +1,7 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
include_directories(BEFORE ${INC_BEFORE})
include_directories(

View File

@ -1,3 +1,8 @@
# .cpp files are compiled with extra ${WSHADOW_FLAGS}
if( COMPILER_SUPPORTS_WSHADOW )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WSHADOW_FLAGS}")
endif()
add_subdirectory( idftools )
if( KICAD_USE_OCE )