blob: 9f21e077c4bd9db217424191ac6677b783f3949d [file] [log] [blame]
if(warnings_included)
return()
endif()
set(warnings_included true)
macro(add_compiler_flags)
foreach(flag ${ARGV})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endforeach()
endmacro()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
#add_compiler_flags(-Werror)
add_compiler_flags(-std=c++98)
add_compiler_flags(-pedantic)
add_compiler_flags(-pedantic-errors)
add_compiler_flags(-fvisibility=hidden)
add_compiler_flags(-fstrict-aliasing)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
#add_compiler_flags(-fstack-protector-all)
#add_compiler_flags(-funsafe-loop-optimizations)
add_compiler_flags(-ansi)
add_compiler_flags(-Wall)
add_compiler_flags(-Wextra)
add_compiler_flags(-Wconversion)
add_compiler_flags(-Wno-missing-field-initializers)
add_compiler_flags(-Wold-style-cast)
add_compiler_flags(-Wfloat-equal)
add_compiler_flags(-Wlogical-op)
add_compiler_flags(-Wundef)
add_compiler_flags(-Wredundant-decls)
add_compiler_flags(-Wshadow)
add_compiler_flags(-Wstrict-overflow=5)
add_compiler_flags(-Wwrite-strings)
add_compiler_flags(-Wpointer-arith)
add_compiler_flags(-Wcast-qual)
add_compiler_flags(-Wformat=2)
add_compiler_flags(-Wswitch-default)
add_compiler_flags(-Wmissing-include-dirs)
add_compiler_flags(-Wcast-align)
add_compiler_flags(-Wformat-nonliteral)
add_compiler_flags(-Wparentheses)
add_compiler_flags(-Winit-self)
add_compiler_flags(-Wuninitialized)
add_compiler_flags(-Wswitch-enum)
add_compiler_flags(-Wno-endif-labels)
add_compiler_flags(-Wunused-function)
add_compiler_flags(-Wnon-virtual-dtor)
add_compiler_flags(-Wno-pmf-conversions)
add_compiler_flags(-Wctor-dtor-privacy)
add_compiler_flags(-Wsign-promo)
add_compiler_flags(-Wdisabled-optimization)
add_compiler_flags(-Waggregate-return)
add_compiler_flags(-Weffc++)
add_compiler_flags(-Winline)
add_compiler_flags(-Winvalid-pch)
add_compiler_flags(-Wstack-protector)
add_compiler_flags(-Wunsafe-loop-optimizations)
add_compiler_flags(-Wmissing-declarations)
add_compiler_flags(-Woverloaded-virtual)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
add_compiler_flags(-Wdouble-promotion)
add_compiler_flags(-Wtrampolines)
add_compiler_flags(-Wzero-as-null-pointer-constant)
add_compiler_flags(-Wuseless-cast)
add_compiler_flags(-Wvector-operation-performance)
add_compiler_flags(-Wsized-deallocation)
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.3)
add_compiler_flags(-Wshift-overflow=2)
add_compiler_flags(-Wnull-dereference)
add_compiler_flags(-Wduplicated-cond)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compiler_flags(-Weverything)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
#add_compiler_flags(/WX)
add_compiler_flags(/W4) # /Wall is too aggressive - even the standard C headers give thousands of errors...
endif()