@@ -43,31 +43,37 @@ endfunction()
4343# enable extra flags (warnings) if we're not in release mode
4444if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "" )
4545 message (STATUS "[proj] Warnings Enabled" )
46- # enable all warnings about 'questionable constructs'
47- enable_cxx_compiler_flag_if_supported("-Wall" )
48- # issue 'pedantic' warnings for strict ISO compliance
49- enable_cxx_compiler_flag_if_supported("-pedantic" )
50- # enable 'extra' strict warnings
51- enable_cxx_compiler_flag_if_supported("-Wextra" )
52- # enable sign and type conversion warnings
53- enable_cxx_compiler_flag_if_supported("-Wsign-conversion" )
54- # enable warnings about mistakes in Doxygen documentation
55- enable_cxx_compiler_flag_if_supported("-Wdocumentation" )
56- # convert all warnings into errors
57- enable_cxx_compiler_flag_if_supported("-Werror" )
58- # exclude the following kinds of warnings from being converted into errors
59- # there are some pragmas in tests/check_wrapper.h that are not for GCC
60- enable_cxx_compiler_flag_if_supported("-Wno-error=unknown-pragmas" )
61- # unused variable and function warnings are helpful but we don't need them as errors
62- enable_cxx_compiler_flag_if_supported("-Wno-error=unused-function" )
63- enable_cxx_compiler_flag_if_supported("-Wno-error=unused-variable" )
64- enable_cxx_compiler_flag_if_supported("-Wno-error=unused-parameter" )
46+ if (MSVC ) # MSVC supports different warning options to GCC/Clang
47+ add_compile_options (/WX /W3) # treat all warnings as errors, set warning level 3
48+ else () # GCC/Clang warning option
49+ # NOTE: GCC and Clang support most of the same options, but neither supports all
50+ # of the others'. By only enabling them if supported, we get graceful failure
51+ # when trying to enable unsupported flags
52+ # e.g. at the time of writing, GCC does not support -Wdocumentation
53+ #
54+ # enable all warnings about 'questionable constructs'
55+ enable_cxx_compiler_flag_if_supported("-Wall" )
56+ # issue 'pedantic' warnings for strict ISO compliance
57+ enable_cxx_compiler_flag_if_supported("-pedantic" )
58+ # enable 'extra' strict warnings
59+ enable_cxx_compiler_flag_if_supported("-Wextra" )
60+ # enable sign conversion warnings
61+ enable_cxx_compiler_flag_if_supported("-Wsign-conversion" )
62+ # enable warnings about mistakes in Doxygen documentation
63+ enable_cxx_compiler_flag_if_supported("-Wdocumentation" )
64+ # convert all warnings into errors
65+ enable_cxx_compiler_flag_if_supported("-Werror" )
66+ # exclude the following kinds of warnings from being converted into errors
67+ # unknown-pragma is useful to have as a warning but not as an error, if you have
68+ # pragmas which are for the consumption of one compiler only
69+ enable_cxx_compiler_flag_if_supported("-Wno-error=unknown-pragmas" )
70+ # unused variable and function warnings are helpful but we don't need them as errors
71+ enable_cxx_compiler_flag_if_supported("-Wno-error=unused-function" )
72+ enable_cxx_compiler_flag_if_supported("-Wno-error=unused-variable" )
73+ enable_cxx_compiler_flag_if_supported("-Wno-error=unused-parameter" )
74+ endif ()
6575endif ()
6676
67- # MSVC options appear unable to be set using this method, so they are set here instead
68- if (MSVC )
69- add_compile_options (/WX /W3) # treat all warnings as errors, set warning level 3
70- endif ()
7177
7278# add custom dependencies directory
7379set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/Modules/" )
0 commit comments