diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a916bba26f3..6be8ece13282 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,80 @@ if (TARGET_VULKAN) set(TARGET_SPIRV ON) # required endif() +# Helper function to set C++ compiler warnings in a sane way +function(set_halide_compiler_warnings NAME) + target_compile_options( + ${NAME} + PRIVATE + $<$:-Wall> + + # variable length arrays in C++ are a Clang extension, we don't want to use them + $<$:-Wvla-extension> + + $<$:-Wcast-qual> + $<$:-Wignored-qualifiers> + $<$:-Woverloaded-virtual> + + $<$:-Wsuggest-override> + + $<$:-Winconsistent-missing-destructor-override> + $<$:-Winconsistent-missing-override> + $<$:-Wdeprecated-declarations> + + $<$:-Wno-double-promotion> + $<$:-Wno-float-conversion> + $<$:-Wno-float-equal> + $<$:-Wno-missing-field-initializers> + $<$:-Wno-old-style-cast> + $<$:-Wno-shadow> + $<$:-Wno-sign-conversion> + $<$:-Wno-switch-enum> + $<$:-Wno-undef> + $<$:-Wno-unused-function> + $<$:-Wno-unused-macros> + $<$:-Wno-unused-parameter> + + $<$:-Wno-c++98-compat-pedantic> + $<$:-Wno-c++98-compat> + $<$:-Wno-cast-align> + $<$:-Wno-comma> + $<$:-Wno-covered-switch-default> + $<$:-Wno-documentation-unknown-command> + $<$:-Wno-documentation> + $<$:-Wno-exit-time-destructors> + $<$:-Wno-global-constructors> + $<$:-Wno-implicit-float-conversion> + $<$:-Wno-implicit-int-conversion> + $<$:-Wno-implicit-int-float-conversion> + $<$:-Wno-missing-prototypes> + $<$:-Wno-nonportable-system-include-path> + $<$:-Wno-reserved-id-macro> + $<$:-Wno-shadow-field-in-constructor> + $<$:-Wno-shadow-field> + $<$:-Wno-shorten-64-to-32> + $<$:-Wno-undefined-func-template> + $<$:-Wno-unused-member-function> + $<$:-Wno-unused-template> + + # This warning was removed in Clang 13 + $<$,$,13.0>>:-Wno-return-std-move-in-c++11> + + $<$:/W3> + $<$:/wd4018> # 4018: disable "signed/unsigned mismatch" + $<$:/wd4141> # 4141: 'inline' used more than once + $<$:/wd4146> # 4146: unary minus applied to unsigned type + $<$:/wd4244> # 4244: conversion, possible loss of data + $<$:/wd4267> # 4267: conversion from 'size_t' to 'int', possible loss of data + $<$:/wd4291> # 4291: No matching operator delete found + $<$:/wd4503> # 4503: disable "decorated name length exceeded, name was truncated" + $<$:/wd4800> # 4800: forcing value to bool 'true' or 'false' (performance warning) + + # No: enable deprecation warnings + # $<$:/wd4996> # 4996: compiler encountered deprecated declaration + ) +endfunction() + + ## # Import dependencies ## diff --git a/cmake/HalideTestHelpers.cmake b/cmake/HalideTestHelpers.cmake index e938d11d53ec..b6b9b70551ff 100644 --- a/cmake/HalideTestHelpers.cmake +++ b/cmake/HalideTestHelpers.cmake @@ -54,6 +54,7 @@ function(add_halide_test TARGET) add_test(NAME ${TARGET} COMMAND ${args_COMMAND} ${args_ARGS} WORKING_DIRECTORY "${args_WORKING_DIRECTORY}") + set_halide_compiler_warnings(${TARGET}) # We can't add Halide::TerminateHandler here, because it requires Halide::Error # and friends to be present in the final linkage, but some callers of add_halide_test() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 390fee9a64e5..cfb092d29bf0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -575,73 +575,7 @@ endif () ## # Set compiler options for libHalide ## - -target_compile_options( - Halide - PRIVATE - $<$:-Wall> - - $<$:-Wcast-qual> - $<$:-Wignored-qualifiers> - $<$:-Woverloaded-virtual> - - $<$:-Wsuggest-override> - - $<$:-Winconsistent-missing-destructor-override> - $<$:-Winconsistent-missing-override> - $<$:-Wdeprecated-declarations> - - $<$:-Wno-double-promotion> - $<$:-Wno-float-conversion> - $<$:-Wno-float-equal> - $<$:-Wno-missing-field-initializers> - $<$:-Wno-old-style-cast> - $<$:-Wno-shadow> - $<$:-Wno-sign-conversion> - $<$:-Wno-switch-enum> - $<$:-Wno-undef> - $<$:-Wno-unused-function> - $<$:-Wno-unused-macros> - $<$:-Wno-unused-parameter> - - $<$:-Wno-c++98-compat-pedantic> - $<$:-Wno-c++98-compat> - $<$:-Wno-cast-align> - $<$:-Wno-comma> - $<$:-Wno-covered-switch-default> - $<$:-Wno-documentation-unknown-command> - $<$:-Wno-documentation> - $<$:-Wno-exit-time-destructors> - $<$:-Wno-global-constructors> - $<$:-Wno-implicit-float-conversion> - $<$:-Wno-implicit-int-conversion> - $<$:-Wno-implicit-int-float-conversion> - $<$:-Wno-missing-prototypes> - $<$:-Wno-nonportable-system-include-path> - $<$:-Wno-reserved-id-macro> - $<$:-Wno-shadow-field-in-constructor> - $<$:-Wno-shadow-field> - $<$:-Wno-shorten-64-to-32> - $<$:-Wno-undefined-func-template> - $<$:-Wno-unused-member-function> - $<$:-Wno-unused-template> - - # This warning was removed in Clang 13 - $<$,$,13.0>>:-Wno-return-std-move-in-c++11> - - $<$:/W3> - $<$:/wd4018> # 4018: disable "signed/unsigned mismatch" - $<$:/wd4141> # 4141: 'inline' used more than once - $<$:/wd4146> # 4146: unary minus applied to unsigned type - $<$:/wd4244> # 4244: conversion, possible loss of data - $<$:/wd4267> # 4267: conversion from 'size_t' to 'int', possible loss of data - $<$:/wd4291> # 4291: No matching operator delete found - $<$:/wd4503> # 4503: disable "decorated name length exceeded, name was truncated" - $<$:/wd4800> # 4800: forcing value to bool 'true' or 'false' (performance warning) - - # No: enable deprecation warnings - # $<$:/wd4996> # 4996: compiler encountered deprecated declaration -) +set_halide_compiler_warnings(Halide) if (CMAKE_GENERATOR MATCHES "Visual Studio") # We could expose the /MP flag to all targets, but that might end up saturating the build diff --git a/test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt index 44ebf4c39d9d..b432b4299804 100644 --- a/test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -15,6 +15,7 @@ function(_set_target_options NAME) COMPILING_HALIDE_RUNTIME COMPILING_HALIDE_RUNTIME_TESTS ) + set_halide_compiler_warnings(${NAME}) endfunction() function(halide_define_runtime_internal_test NAME)