From caea9adb44e9ebf177416d79daf401309d410562 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Mon, 28 Apr 2025 15:21:43 +0200 Subject: [PATCH 1/2] whisper: suppress Windows compiler warnings This commit disables compiler warnings on window using MSVC. The motivation for these changes is that some compilers generate warnings for these conversion, for example Windows MSVC, and there are quite a few of them. This makes it a little difficult to spot new warnings that may be introduced and also can be difficult for users/embedders of ggml where these warnings are hard to separate from their own warnings. --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34ef7958f6d..e3d99d80325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,3 +213,37 @@ endif () if (WHISPER_BUILD_EXAMPLES) add_subdirectory(examples) endif() + +if(MSVC) + set(MSVC_WARNING_FLAGS + /wd4101 # Unreferenced local variable + /wd4005 # Macro redefinition + /wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data + /wd4244 # Conversion from one type to another type, possible loss of data + /wd4267 # Duplicate of 4267 above - you might want to remove this duplicate + /wd4305 # Truncation from 'type1' to 'type2' (often double to float) + /wd4996 # Function or variable may be unsafe/deprecated + ) + function(disable_msvc_warnings target_name) + target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_FLAGS}) + endfunction() + + disable_msvc_warnings(ggml-base) + disable_msvc_warnings(ggml) + disable_msvc_warnings(ggml-cpu) + + if (WHISPER_BUILD_EXAMPLES) + message(STATUS "Disabling MSVC warnings for examples") + disable_msvc_warnings(common) + disable_msvc_warnings(common-sdl) + disable_msvc_warnings(lsp) + disable_msvc_warnings(wchess-core) + disable_msvc_warnings(whisper-command) + disable_msvc_warnings(whisper-cli) + disable_msvc_warnings(whisper-server) + disable_msvc_warnings(whisper-stream) + disable_msvc_warnings(whisper-talk-llama) + disable_msvc_warnings(whisper-bench) + disable_msvc_warnings(quantize) + endif() +endif() From 5a144ac8df7605219e033c6897949b6afbced00d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 29 Apr 2025 12:11:14 +0200 Subject: [PATCH 2/2] squash! whisper: suppress Windows compiler warnings Move ggml related warnings into ggml. This commit also fixes the indentation and adds a missing whitespace to the if statement. --- CMakeLists.txt | 22 +++++++++------------- ggml/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3d99d80325..ec750928247 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,26 +214,22 @@ if (WHISPER_BUILD_EXAMPLES) add_subdirectory(examples) endif() -if(MSVC) +if (MSVC) set(MSVC_WARNING_FLAGS - /wd4101 # Unreferenced local variable - /wd4005 # Macro redefinition - /wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data - /wd4244 # Conversion from one type to another type, possible loss of data - /wd4267 # Duplicate of 4267 above - you might want to remove this duplicate - /wd4305 # Truncation from 'type1' to 'type2' (often double to float) - /wd4996 # Function or variable may be unsafe/deprecated + /wd4101 # Unreferenced local variable + /wd4005 # Macro redefinition + /wd4065 # switch statement contains 'default' but no 'case' labels + /wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data + /wd4244 # Conversion from one type to another type, possible loss of ata + /wd4805 # Unsafe mix of type + /wd4305 # Truncation from 'type1' to 'type2' (often double to float) + /wd4996 # Function or variable may be unsafe/deprecated ) function(disable_msvc_warnings target_name) target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_FLAGS}) endfunction() - disable_msvc_warnings(ggml-base) - disable_msvc_warnings(ggml) - disable_msvc_warnings(ggml-cpu) - if (WHISPER_BUILD_EXAMPLES) - message(STATUS "Disabling MSVC warnings for examples") disable_msvc_warnings(common) disable_msvc_warnings(common-sdl) disable_msvc_warnings(lsp) diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt index 61fe15a15f0..e632af010c7 100644 --- a/ggml/CMakeLists.txt +++ b/ggml/CMakeLists.txt @@ -360,3 +360,18 @@ write_basic_package_version_file( install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/ggml-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ggml) + +if (MSVC) + set(MSVC_WARNING_FLAGS + /wd4005 # Macro redefinition + /wd4244 # Conversion from one type to another type, possible loss of data + /wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data + ) + function(disable_msvc_warnings target_name) + target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_FLAGS}) + endfunction() + + disable_msvc_warnings(ggml-base) + disable_msvc_warnings(ggml) + disable_msvc_warnings(ggml-cpu) +endif()