refactor(build): graduate -Wvla, -fno-common and -Og "features"

These are in gcc 4.9+ which we require anyway.
-Og is safe on clang as well (reserved for a future debug-optimize mode,
and currently does the same as -O1 which is reasonable)
This commit is contained in:
bfredl 2023-02-27 20:14:10 +01:00 committed by Björn Linse
parent 848dac0aaa
commit 2cffd04833
2 changed files with 6 additions and 23 deletions

View File

@ -120,17 +120,11 @@ if(CMAKE_C_FLAGS_RELEASE MATCHES "-O3")
string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "-O3" "-O2" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
endif() endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
check_c_compiler_flag(-Og HAS_OG_FLAG)
else()
set(HAS_OG_FLAG 0)
endif()
#
# Build-type: RelWithDebInfo # Build-type: RelWithDebInfo
#
if(HAS_OG_FLAG) # /Og means something different in MSVC
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Og -g") if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Og -g")
endif() endif()
# We _want_ assertions in RelWithDebInfo build-type. # We _want_ assertions in RelWithDebInfo build-type.
if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG) if(CMAKE_C_FLAGS_RELWITHDEBINFO MATCHES DNDEBUG)

View File

@ -87,14 +87,14 @@ if(MSVC)
target_sources(main_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/os/nvim.manifest) target_sources(main_lib INTERFACE ${CMAKE_CURRENT_LIST_DIR}/os/nvim.manifest)
else() else()
target_compile_options(main_lib INTERFACE -Wall -Wextra -pedantic -Wno-unused-parameter target_compile_options(main_lib INTERFACE -Wall -Wextra -pedantic -Wno-unused-parameter
-Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla
-Wdouble-promotion -Wdouble-promotion
-Wmissing-noreturn -Wmissing-noreturn
-Wmissing-format-attribute -Wmissing-format-attribute
-Wmissing-prototypes) -Wmissing-prototypes)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU") if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(main_lib INTERFACE target_compile_options(main_lib INTERFACE -fno-common
$<$<CONFIG:Release>:-Wno-unused-result> $<$<CONFIG:Release>:-Wno-unused-result>
$<$<CONFIG:RelWithDebInfo>:-Wno-unused-result> $<$<CONFIG:RelWithDebInfo>:-Wno-unused-result>
$<$<CONFIG:MinSizeRel>:-Wno-unused-result>) $<$<CONFIG:MinSizeRel>:-Wno-unused-result>)
@ -144,17 +144,6 @@ if(WIN32)
target_compile_definitions(main_lib INTERFACE _WIN32_WINNT=0x0602 MSWIN) target_compile_definitions(main_lib INTERFACE _WIN32_WINNT=0x0602 MSWIN)
endif() endif()
# OpenBSD's GCC (4.2.1) doesn't have -Wvla
check_c_compiler_flag(-Wvla HAS_WVLA_FLAG)
if(HAS_WVLA_FLAG)
target_compile_options(main_lib INTERFACE -Wvla)
endif()
check_c_compiler_flag(-fno-common HAVE_FNO_COMMON)
if (HAVE_FNO_COMMON)
target_compile_options(main_lib INTERFACE -fno-common)
endif()
check_c_compiler_flag(-fdiagnostics-color=auto HAS_DIAG_COLOR_FLAG) check_c_compiler_flag(-fdiagnostics-color=auto HAS_DIAG_COLOR_FLAG)
if(HAS_DIAG_COLOR_FLAG) if(HAS_DIAG_COLOR_FLAG)
if(CMAKE_GENERATOR MATCHES "Ninja") if(CMAKE_GENERATOR MATCHES "Ninja")