diff --git a/cmake/nifti_warnings.cmake b/cmake/nifti_warnings.cmake index efbf2b4f..ae30dd5d 100644 --- a/cmake/nifti_warnings.cmake +++ b/cmake/nifti_warnings.cmake @@ -1,9 +1,10 @@ # # Compiler warning flags shared by every nifti_clib target. # -# Every flag below has been measured at zero warnings across the whole -# tree. A flag is added only once the tree is already clean under it, so -# that a warning always means a new defect rather than more noise. +# Every flag in the GCC/Clang and Clang-only blocks has been measured at +# zero warnings across the whole tree. A flag is added only once the +# tree is already clean under it, so that a warning always means a new +# defect rather than more noise. # # Run the census before adding a flag: # @@ -16,6 +17,9 @@ # Warnings are NOT errors by default; set NIFTI_WARNINGS_AS_ERRORS=ON to # make CI fail on them. # +# This branch also enables flags that are not yet clean, so CI measures +# them on every run. Keep NIFTI_WARNINGS_AS_ERRORS OFF here. +# option(NIFTI_ENABLE_WARNINGS "Enable the project's compiler warning set" ON) option(NIFTI_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) @@ -56,6 +60,48 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang|AppleClang") ) endif() +# --------------------------------------------------------------------- +# Ready to promote: measured at zero, not yet in the clean set +# --------------------------------------------------------------------- +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + list(APPEND _nifti_warnings + -Wduplicated-branches + -Wduplicated-cond + -Wjump-misses-init + -Wlogical-op + -Wold-style-definition + ) +endif() + +# clang-cl reports the Clang ID with MSVC set; it takes MSVC-style flags. +if(CMAKE_C_COMPILER_ID MATCHES "^(Clang|AppleClang)$" AND NOT MSVC) + list(APPEND _nifti_warnings + -Wcast-align + -Wextra-semi-stmt + -Wmissing-variable-declarations + -Wnewline-eof + ) +endif() + +# --------------------------------------------------------------------- +# Future set: still warns +# --------------------------------------------------------------------- +if(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$" AND NOT MSVC) + list(APPEND _nifti_warnings + -Wcast-qual + -Wextra + -Wmissing-prototypes + -Wsign-conversion + ) +endif() + +if(CMAKE_C_COMPILER_ID MATCHES "^(Clang|AppleClang)$" AND NOT MSVC) + list(APPEND _nifti_warnings + -Wconditional-uninitialized + -Wshorten-64-to-32 + ) +endif() + if(NIFTI_WARNINGS_AS_ERRORS) if(MSVC) list(APPEND _nifti_warnings /WX)