For each of the recently added warning flags check to see if the

compiler supports the flag before adding it.
This commit is contained in:
Glenn Rice 2013-01-29 21:28:55 -06:00
parent 0e04e0c305
commit 7676c4d43b

View File

@ -109,32 +109,37 @@ endif()
# Various compile flags # Various compile flags
add_definitions(-msse2) add_definitions(-msse2)
include(CheckCXXCompilerFlag)
macro(check_and_add_flag var flag)
CHECK_CXX_COMPILER_FLAG(${flag} FLAG_${var})
if(FLAG_${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()
# Enabling all warnings in MSVC spams too much # Enabling all warnings in MSVC spams too much
if(NOT MSVC) if(NOT MSVC)
add_definitions(-Wall add_definitions(-Wall)
# TODO: would like these but they produce overwhelming amounts of warnings
# -Wextra # TODO: would like these but they produce overwhelming amounts of warnings
# -Wmissing-field-initializers #check_and_add_flag(EXTRA -Wextra)
# -Wswitch-default #check_and_add_flag(MISSING_FIELD_INITIALIZERS -Wmissing-field-initializers)
# -Wfloat-equal #check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
# -Wconversion #check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
# -Wzero-as-null-pointer-constant #check_and_add_flag(CONVERSION -Wconversion)
-Wtype-limits #check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
-Wsign-compare check_and_add_flag(TYPE_LIMITS -Wtype-limits)
-Wignored-qualifiers check_and_add_flag(SIGN_COMPARE -Wsign-compare)
-Wuninitialized check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
-Wshadow check_and_add_flag(UNINITIALIZED -Wuninitialized)
-Winit-self) check_and_add_flag(LOGICAL_OP -Wlogical-op)
if (NOT (${CMAKE_C_COMPILER} MATCHES "clang")) check_and_add_flag(SHADOW -Wshadow)
add_definitions(-Wlogical-op) check_and_add_flag(INIT_SELF -Winit-self)
endif()
endif(NOT MSVC) endif(NOT MSVC)
# gcc uses some optimizations which might break stuff without this flag # gcc uses some optimizations which might break stuff without this flag
add_definitions(-fno-strict-aliasing -fno-exceptions -Wno-psabi) add_definitions(-fno-strict-aliasing -fno-exceptions -Wno-psabi)
include(CheckCXXCompilerFlag)
# We call fread numerous times without checking return values. Hide the # We call fread numerous times without checking return values. Hide the
# corresponding compiler warnings if the compiler supports doing so. # corresponding compiler warnings if the compiler supports doing so.
CHECK_CXX_COMPILER_FLAG(-Wunused-result NO_UNUSED_RESULT) CHECK_CXX_COMPILER_FLAG(-Wunused-result NO_UNUSED_RESULT)
@ -142,16 +147,10 @@ if(NO_UNUSED_RESULT)
add_definitions(-Wno-unused-result) add_definitions(-Wno-unused-result)
endif(NO_UNUSED_RESULT) endif(NO_UNUSED_RESULT)
CHECK_CXX_COMPILER_FLAG(-fvisibility-inlines-hidden VISIBILITY_INLINES_HIDDEN) check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
if(VISIBILITY_INLINES_HIDDEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
endif(VISIBILITY_INLINES_HIDDEN)
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden VISIBILITY_HIDDEN) check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)
if(VISIBILITY_HIDDEN)
add_definitions(-fvisibility=hidden)
endif(VISIBILITY_HIDDEN)
endif() endif()
if(APPLE) if(APPLE)