From 0c25e58db6b045df92c209d396031cac5b528bbf Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 6 Feb 2018 02:38:01 +0100 Subject: [PATCH] correctly detect unsupported compiler flags in gcc `-Wno-unsupported-something` will not be an error or even a warning, so cmake will think the flag is supported. But if there's any other warning during compilation, for any reason, unknown option will be a warning too. Or an error when -Werror, even if that "other warning" would not be an error on itself. So we need to detect whether `-Wno-unsupported-something` is *really* supported. Luckily, `-Wunsupported-something` will always fail with an error. So, whenever there's a need to detect if -Wno-something is supported, test -Wsomething instead. --- cmake/check_compiler_flag.cmake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/check_compiler_flag.cmake b/cmake/check_compiler_flag.cmake index ef675959059..673361ab8fe 100644 --- a/cmake/check_compiler_flag.cmake +++ b/cmake/check_compiler_flag.cmake @@ -32,25 +32,25 @@ MACRO (MY_CHECK_CXX_COMPILER_FLAG flag) SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}") ENDMACRO() -FUNCTION(MY_CHECK_AND_SET_COMPILER_FLAG flag) +FUNCTION(MY_CHECK_AND_SET_COMPILER_FLAG flag_to_set) # At the moment this is gcc-only. # Let's avoid expensive compiler tests on Windows: IF(WIN32) RETURN() ENDIF() - MY_CHECK_C_COMPILER_FLAG(${flag}) - MY_CHECK_CXX_COMPILER_FLAG(${flag}) - STRING(REGEX REPLACE "[-,= +]" "_" result "${flag}") + STRING(REGEX REPLACE "^-Wno-" "-W" flag_to_check ${flag_to_set}) + MY_CHECK_C_COMPILER_FLAG(${flag_to_check}) + MY_CHECK_CXX_COMPILER_FLAG(${flag_to_check}) + STRING(REGEX REPLACE "[-,= +]" "_" result "${flag_to_check}") FOREACH(lang C CXX) IF (HAVE_${lang}_${result}) IF(ARGN) FOREACH(type ${ARGN}) - SET(CMAKE_${lang}_FLAGS_${type} "${CMAKE_${lang}_FLAGS_${type}} ${flag}" PARENT_SCOPE) + SET(CMAKE_${lang}_FLAGS_${type} "${CMAKE_${lang}_FLAGS_${type}} ${flag_to_set}" PARENT_SCOPE) ENDFOREACH() ELSE() - SET(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${flag}" PARENT_SCOPE) + SET(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${flag_to_set}" PARENT_SCOPE) ENDIF() ENDIF() ENDFOREACH() ENDFUNCTION() -