cmake: defeat bogus missing-field-initializers warning on g++ 4.8

g++ 4.8 emits a bogus warning on code like foo{}. Add a compiler flag
-Wno-missing-field-initializers if that warning is detected, because it
is annoying.
This commit is contained in:
ridiculousfish 2022-09-20 12:41:41 -07:00
parent e7de342259
commit 379ad245e4

View file

@ -5,6 +5,7 @@
# This is the case for at least Cygwin and Newlib.
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE=1)
include(CheckCXXCompilerFlag)
include(CMakePushCheckState)
if(APPLE)
check_cxx_compiler_flag("-Werror=unguarded-availability" REQUIRES_UNGUARDED_AVAILABILITY)
@ -31,6 +32,25 @@ if (HAS_REDUNDANT_MOVE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wredundant-move")
endif()
# Defeat bogus warnings about missing field initializers for `var{}` initialization.
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_FLAGS "-W")
check_cxx_source_compiles("
struct sr_t { int x; };
int main(void) {
sr_t sr{};
return sr.x;
}"
EMPTY_VALUE_INIT_ACCEPTED
FAIL_REGEX "-Wmissing-field-initializers"
)
if (NOT EMPTY_VALUE_INIT_ACCEPTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
endif()
cmake_pop_check_state()
endif()
# Disable static destructors if we can.
check_cxx_compiler_flag("-fno-c++-static-destructors" DISABLE_STATIC_DESTRUCTORS)
if (DISABLE_STATIC_DESTRUCTORS)
@ -79,7 +99,6 @@ include(CheckIncludeFiles)
include(CheckStructHasMember)
include(CheckCXXSourceCompiles)
include(CheckTypeSize)
include(CMakePushCheckState)
check_cxx_symbol_exists(backtrace_symbols execinfo.h HAVE_BACKTRACE_SYMBOLS)
# workaround for lousy mtime precision on a Linux kernel