compile_flag: workaround gcc's -Wno-foo handling

This commit is contained in:
Danny Robson 2018-01-23 18:53:45 +11:00
parent 8c9ca6a372
commit 21e8792153

View File

@ -4,10 +4,24 @@ macro (append_compile_flag _flag)
string (MAKE_C_IDENTIFIER ${_flag} _name) string (MAKE_C_IDENTIFIER ${_flag} _name)
if (NOT DEFINED compile_flag_${_name}) if (NOT DEFINED compile_flag_${_name})
check_cxx_compiler_flag (${_flag} compile_flag_${_name}) # If we have an argument of the form "-Wno-foo" then we can't test it
# directly as GCC will unconditioally succeed right up until the
# point any other warning or error is triggered and *then* dump a
# warning message.
#
# Instead you have to test for -Wfoo and only if that succeeds can
# you use the negation.
string (REGEX MATCH "^-Wno-(.+)$" compile_flag_inverse ${_flag})
if ("x" STREQUAL "x${compile_flag_inverse}")
check_cxx_compiler_flag (${_flag} compile_flag${_name})
else ()
string (REGEX REPLACE "-Wno-" "" _inverse_flag ${_flag})
check_cxx_compiler_flag ("-W${_inverse_flag}" compile_flag${_name})
endif ()
endif () endif ()
if (compile_flag_${_name}) if (compile_flag${_name})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
endif() endif()
endmacro(append_compile_flag) endmacro(append_compile_flag)