Skip to content

Commit 55d73a1

Browse files
authored
ggml : suppress Windows compiler warnings (#3075)
* 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. * 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.
1 parent 2e30e6d commit 55d73a1

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,33 @@ endif ()
213213
if (WHISPER_BUILD_EXAMPLES)
214214
add_subdirectory(examples)
215215
endif()
216+
217+
if (MSVC)
218+
set(MSVC_WARNING_FLAGS
219+
/wd4101 # Unreferenced local variable
220+
/wd4005 # Macro redefinition
221+
/wd4065 # switch statement contains 'default' but no 'case' labels
222+
/wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data
223+
/wd4244 # Conversion from one type to another type, possible loss of ata
224+
/wd4805 # Unsafe mix of type
225+
/wd4305 # Truncation from 'type1' to 'type2' (often double to float)
226+
/wd4996 # Function or variable may be unsafe/deprecated
227+
)
228+
function(disable_msvc_warnings target_name)
229+
target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_FLAGS})
230+
endfunction()
231+
232+
if (WHISPER_BUILD_EXAMPLES)
233+
disable_msvc_warnings(common)
234+
disable_msvc_warnings(common-sdl)
235+
disable_msvc_warnings(lsp)
236+
disable_msvc_warnings(wchess-core)
237+
disable_msvc_warnings(whisper-command)
238+
disable_msvc_warnings(whisper-cli)
239+
disable_msvc_warnings(whisper-server)
240+
disable_msvc_warnings(whisper-stream)
241+
disable_msvc_warnings(whisper-talk-llama)
242+
disable_msvc_warnings(whisper-bench)
243+
disable_msvc_warnings(quantize)
244+
endif()
245+
endif()

ggml/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,18 @@ write_basic_package_version_file(
360360
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml-config.cmake
361361
${CMAKE_CURRENT_BINARY_DIR}/ggml-version.cmake
362362
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ggml)
363+
364+
if (MSVC)
365+
set(MSVC_WARNING_FLAGS
366+
/wd4005 # Macro redefinition
367+
/wd4244 # Conversion from one type to another type, possible loss of data
368+
/wd4267 # Conversion from 'size_t' to a smaller type, possible loss of data
369+
)
370+
function(disable_msvc_warnings target_name)
371+
target_compile_options(${target_name} PRIVATE ${MSVC_WARNING_FLAGS})
372+
endfunction()
373+
374+
disable_msvc_warnings(ggml-base)
375+
disable_msvc_warnings(ggml)
376+
disable_msvc_warnings(ggml-cpu)
377+
endif()

0 commit comments

Comments
 (0)