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.
This commit is contained in:
parent
4418abb267
commit
0c25e58db6
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user