diff --git a/CMakeLists.txt b/CMakeLists.txt index f9ce5610a..71ee06921 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,6 +199,11 @@ if(MILKYWAY_IPHONE_APP) add_definitions("-DMILKYWAY_IPHONE_APP") endif() +option (DISABLE_SAFE_LCC_WARNINGS "Disable some of excess Elbrus compiler warnings" ON) +mark_as_advanced(DISABLE_SAFE_LCC_WARNINGS) + +option (DISABLE_EXTRA_LCC_WARNINGS "Disable more Elbrus compiler warnings that may be unsafe" OFF) +mark_as_advanced(DISABLE_EXTRA_LCC_WARNINGS) ################################################################################ @@ -247,6 +252,31 @@ add_flag_if_supported("-xc99") # #-Xanalyzer -analyzer-display-progress # -Xanalyzer -analyzer-no-purge-dead) +if(DISABLE_SAFE_LCC_WARNINGS) + # These warnings are about completely safe situations + suppress_warning_if_supported("-Wno-alignment-reduction-ignored") + suppress_warning_if_supported("-Wno-unused-variable") + suppress_warning_if_supported("-Wno-unused-function") + suppress_warning_if_supported("-Wno-unused-parameter") + suppress_warning_if_supported("-Wno-comment") + suppress_warning_if_supported("-Wno-static-reference-in-c99-inline-function") + suppress_warning_if_supported("-Wno-reduced-alignment") + suppress_warning_if_supported("-Wno-inline") + + if(DISABLE_EXTRA_LCC_WARNINGS) + # These warnings may probably lead to some unsafe situations, + # so we won't turn them off unless specifically noted + suppress_warning_if_supported("-Wno-maybe-uninitialized") + suppress_warning_if_supported("-Wno-invalid-pragma-parameter") + suppress_warning_if_supported("-Wno-bad-initializer-type") + suppress_warning_if_supported("-Wno-sign-compare") + suppress_warning_if_supported("-Wno-array-bounds") + suppress_warning_if_supported("-Wno-bad-return-value-type") + suppress_warning_if_supported("-Wno-implicit-function-declaration") + suppress_warning_if_supported("-Wno-invalid-builtin-arg") + endif() +endif() + CHECK_C_COMPILER_FLAG("-funswitch-loops" SUPPORTS_UNSWITCH_LOOPS) if(SUPPORTS_UNSWITCH_LOOPS) set(gcc_extra_flags "-fno-common -funswitch-loops ") @@ -278,7 +308,7 @@ if(NOT DOUBLEPREC) endif() if(CMAKE_COMPILER_IS_GNUCC OR C_COMPILER_IS_CLANG) - foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags}) + foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags} ${suppress_warning_flags}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}") endforeach() endif() @@ -290,7 +320,7 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT C_COMPILER_IS_CLANG) endif() if(CMAKE_COMPILER_IS_GNUCC OR CXX_COMPILER_IS_CLANG) - foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags}) + foreach(flag ${gcc_extra_flags} ${gcc_warnings} ${extra_gcc_math_flags} ${suppress_warning_flags}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") endforeach() endif() diff --git a/cmake_modules/CheckCFlag.cmake b/cmake_modules/CheckCFlag.cmake index d5a0cab7a..eafb6aaea 100644 --- a/cmake_modules/CheckCFlag.cmake +++ b/cmake_modules/CheckCFlag.cmake @@ -29,6 +29,15 @@ function(add_flag_if_supported flagname) endif() endfunction() +# The ${suppress_warning_flags} variable is to be added after all other flags. +function(suppress_warning_if_supported flagname) + check_c_compiler_flag("${flagname}" HAVE_FLAG_${flagname}) + + if(${HAVE_FLAG_${flagname}}) + set(suppress_warning_flags "${suppress_warning_flags} ${flagname}" PARENT_SCOPE) + endif() +endfunction() + function(append_supported_flags flags) foreach(flag ${flags}) add_flag_if_supported(${flag})