Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions cmake/nifti_warnings.cmake
Original file line number Diff line number Diff line change
@@ -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:
#
Expand All @@ -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)
Expand Down Expand Up @@ -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
Comment thread
hjmjohnson marked this conversation as resolved.
Resolved
-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)
Expand Down
Loading