2023-10-11 15:05:18 +03:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
|
|
|
|
macro (checkCFlag FLAG)
|
|
|
|
CHECK_C_COMPILER_FLAG("${FLAG}" CFLAG${FLAG})
|
|
|
|
if(CFLAG${FLAG})
|
|
|
|
string(APPEND CMAKE_C_FLAGS " ${FLAG}")
|
|
|
|
else()
|
|
|
|
message(WARNING "compiler does not support ${FLAG}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" ON)
|
|
|
|
option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF)
|
|
|
|
|
|
|
|
if (ENABLE_WARNING_VERBOSE)
|
|
|
|
if (MSVC)
|
2023-10-16 15:05:48 +03:00
|
|
|
# Remove previous warning definitions,
|
|
|
|
# NMake is otherwise complaining.
|
|
|
|
foreach (flags_var_to_scrub
|
|
|
|
CMAKE_C_FLAGS
|
|
|
|
CMAKE_C_FLAGS_DEBUG
|
|
|
|
CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL)
|
|
|
|
string (REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " "
|
|
|
|
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
|
|
|
|
endforeach()
|
|
|
|
|
2023-10-11 15:05:18 +03:00
|
|
|
set(C_WARNING_FLAGS
|
2023-11-14 15:26:05 +03:00
|
|
|
/W4
|
|
|
|
/wo4324
|
2023-10-11 15:05:18 +03:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(C_WARNING_FLAGS
|
|
|
|
-Weverything
|
|
|
|
-Wall
|
|
|
|
-Wpedantic
|
|
|
|
-Wno-padded
|
2024-09-09 16:10:33 +03:00
|
|
|
-Wno-switch-enum
|
2023-10-11 15:05:18 +03:00
|
|
|
-Wno-cast-align
|
|
|
|
-Wno-declaration-after-statement
|
|
|
|
-Wno-unsafe-buffer-usage
|
|
|
|
-Wno-reserved-identifier
|
|
|
|
-Wno-covered-switch-default
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(FLAG ${C_WARNING_FLAGS})
|
|
|
|
CheckCFlag(${FLAG})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
if (ENABLE_WARNING_ERROR)
|
|
|
|
CheckCFlag(-Werror)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "default CFLAGS")
|
|
|
|
message("Using CFLAGS ${CMAKE_C_FLAGS}")
|