2024-09-18 11:11:45 +03:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
|
|
|
macro (checkCXXFlag FLAG)
|
|
|
|
check_cxx_compiler_flag("${FLAG}" CXXFLAG${FLAG})
|
|
|
|
if(CXXFLAG${FLAG})
|
|
|
|
string(APPEND CMAKE_CXX_FLAGS " ${FLAG}")
|
|
|
|
else()
|
|
|
|
message(WARNING "compiler does not support ${FLAG}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2024-09-25 11:28:49 +03:00
|
|
|
option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF)
|
2024-09-18 11:11:45 +03:00
|
|
|
option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF)
|
|
|
|
|
|
|
|
if (ENABLE_WARNING_VERBOSE)
|
|
|
|
if (MSVC)
|
|
|
|
# Remove previous warning definitions,
|
|
|
|
# NMake is otherwise complaining.
|
|
|
|
foreach (flags_var_to_scrub
|
|
|
|
CMAKE_CXX_FLAGS
|
|
|
|
CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL)
|
|
|
|
string (REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " "
|
|
|
|
"${flags_var_to_scrub}" "${${flags_var_to_scrub}}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set(C_WARNING_FLAGS
|
|
|
|
/W4
|
|
|
|
/wo4324
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(C_WARNING_FLAGS
|
|
|
|
-Weverything
|
|
|
|
-Wall
|
|
|
|
-Wpedantic
|
|
|
|
-Wno-padded
|
|
|
|
-Wno-switch-enum
|
|
|
|
-Wno-cast-align
|
|
|
|
-Wno-declaration-after-statement
|
|
|
|
-Wno-unsafe-buffer-usage
|
|
|
|
-Wno-reserved-identifier
|
|
|
|
-Wno-covered-switch-default
|
2024-09-18 11:54:06 +03:00
|
|
|
-Wno-disabled-macro-expansion
|
2024-09-18 11:11:45 +03:00
|
|
|
-Wno-ctad-maybe-unsupported
|
2024-09-18 12:41:50 +03:00
|
|
|
-Wno-c++98-compat
|
|
|
|
-Wno-c++98-compat-pedantic
|
|
|
|
-Wno-pre-c++17-compat
|
2024-09-20 18:14:14 +03:00
|
|
|
-Wno-exit-time-destructors
|
2024-09-18 11:11:45 +03:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(FLAG ${C_WARNING_FLAGS})
|
|
|
|
CheckCXXFlag(${FLAG})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
|
|
if (ENABLE_WARNING_ERROR)
|
|
|
|
CheckCXXFlag(-Werror)
|
|
|
|
endif()
|
|
|
|
|
2024-10-08 17:30:51 +03:00
|
|
|
# https://stackoverflow.com/questions/4913922/possible-problems-with-nominmax-on-visual-c
|
|
|
|
if (WIN32)
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-DNOMINMAX>)
|
|
|
|
endif()
|
|
|
|
|
2024-09-18 11:11:45 +03:00
|
|
|
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "default CXXFLAGS")
|
|
|
|
message("Using CXXFLAGS ${CMAKE_CXX_FLAGS}")
|