[Insight-developers] Useful compiler warning flags? Add as a patch?

Williams, Norman K norman-k-williams at uiowa.edu
Fri Mar 18 14:07:23 EDT 2011


Wrote this for BRAINS, and it could/should be part of ITK. It has a list
of GCC/G++ picky compiler warnings, and checks to see if they're supported
by the current compiler.  For BRAINS we run with these full time. It
doesn't make us write better code, necessarily but it has flushed a few
bugs and ends up being a first-line critique of our code as we write it.

A few questions.


Should I just chuck it in ITK/CMake, include it in top level
CMakeLists.txt?

Should there be (yet another) ITK CMake option to turn this on/off, and
what should it be named -- ITK_USE_PICKY_COMPILER_WARNINGS?

We append the list to CMAKE_C_FLAGS and CMAKE_CXX_FLAGS CMake variables --
which in CMake-land usually contains the CFLAGS & CXXFLAGS env variables.
Is there a better way?

Those of you who use non-GCC compilers, what are your favorite picky
warning options?

include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)

#
# this functions loops through the list to add the flags
# supported by the current compiler
function(test_cc_flags c_flag_var flag_list)
  set(local_c_flags "")
  foreach(flag IN LISTS ${flag_list})
    check_c_compiler_flag(${flag} C_HAS${flag})
    if(${C_HAS${flag}})
      set(local_c_flags "${local_c_flags} ${flag}")
    endif()
  endforeach(flag)
  set(${c_flag_var} "${local_c_flags}" PARENT_SCOPE)
endfunction(test_cc_flags)

#
# this functions loops through the list to add the flags
# supported by the current compiler
function(test_cxx_flags cxx_flag_var flag_list)
  set(local_cxx_flags "")
  foreach(flag IN LISTS ${flag_list})
    check_cxx_compiler_flag(${flag} CXX_HAS${flag})
    if(${CXX_HAS${flag}})
      set(local_cxx_flags "${local_cxx_flags} ${flag}")
    endif()
  endforeach(flag)
  set(${cxx_flag_var} "${local_cxx_flags}" PARENT_SCOPE)
endfunction(test_cxx_flags)

#-pedantic
set(common_flags_to_test
-Wall
-Wextra
#-Wshadow
-Wlong-long
-fopenmp
)

set(cc_flags_to_test ${common_flags_to_test})

test_cc_flags(C_RELEASE_DESIRED_FLAGS cc_flags_to_test)
test_cc_flags(C_DEBUG_DESIRED_FLAGS cc_flags_to_test)

set(cxx_flags_to_test ${common_flags_to_test} -Wno-invalid-offsetof )
test_cxx_flags(CXX_RELEASE_DESIRED_FLAGS cxx_flags_to_test)
test_cxx_flags(CXX_DEBUG_DESIRED_FLAGS cxx_flags_to_test)



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the Insight-developers mailing list