From b7f9c2089a3e4af15e1fa8a9ab0911e1b1980562 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 23 Nov 2021 18:56:50 +0300 Subject: [PATCH] cmake: handle warning flags properly (thanks to hgs3 for pointers.) fixes https://github.com/libsdl-org/SDL/issues/4983 --- CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 725ed3362..e8963a297 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,15 @@ if(MSVC) string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}") endforeach(flag_var) endif() + + if(MSVC_CLANG) + # clang-cl treats '/W4' as '-Wall -Wextra' -- we don't need -Wextra. + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) + string(REGEX REPLACE "/W4" "/W3" ${flag_var} "${${flag_var}}") + endforeach(flag_var) + endif() endif() # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config, @@ -495,8 +504,12 @@ endif() # Compiler option evaluation if(USE_GCC OR USE_CLANG) # Check for -Wall first, so later things can override pieces of it. + # Note: clang-cl treats -Wall as -Weverything (which is very loud), + # /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough. check_c_compiler_flag(-Wall HAVE_GCC_WALL) - if(HAVE_GCC_WALL) + if(MSVC_CLANG) + list(APPEND EXTRA_CFLAGS "/W3") + elseif(HAVE_GCC_WALL) list(APPEND EXTRA_CFLAGS "-Wall") if(HAIKU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")