Skip to content

Commit 0c25e58

Browse files
committed
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.
1 parent 4418abb commit 0c25e58

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmake/check_compiler_flag.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ MACRO (MY_CHECK_CXX_COMPILER_FLAG flag)
3232
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
3333
ENDMACRO()
3434

35-
FUNCTION(MY_CHECK_AND_SET_COMPILER_FLAG flag)
35+
FUNCTION(MY_CHECK_AND_SET_COMPILER_FLAG flag_to_set)
3636
# At the moment this is gcc-only.
3737
# Let's avoid expensive compiler tests on Windows:
3838
IF(WIN32)
3939
RETURN()
4040
ENDIF()
41-
MY_CHECK_C_COMPILER_FLAG(${flag})
42-
MY_CHECK_CXX_COMPILER_FLAG(${flag})
43-
STRING(REGEX REPLACE "[-,= +]" "_" result "${flag}")
41+
STRING(REGEX REPLACE "^-Wno-" "-W" flag_to_check ${flag_to_set})
42+
MY_CHECK_C_COMPILER_FLAG(${flag_to_check})
43+
MY_CHECK_CXX_COMPILER_FLAG(${flag_to_check})
44+
STRING(REGEX REPLACE "[-,= +]" "_" result "${flag_to_check}")
4445
FOREACH(lang C CXX)
4546
IF (HAVE_${lang}_${result})
4647
IF(ARGN)
4748
FOREACH(type ${ARGN})
48-
SET(CMAKE_${lang}_FLAGS_${type} "${CMAKE_${lang}_FLAGS_${type}} ${flag}" PARENT_SCOPE)
49+
SET(CMAKE_${lang}_FLAGS_${type} "${CMAKE_${lang}_FLAGS_${type}} ${flag_to_set}" PARENT_SCOPE)
4950
ENDFOREACH()
5051
ELSE()
51-
SET(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${flag}" PARENT_SCOPE)
52+
SET(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${flag_to_set}" PARENT_SCOPE)
5253
ENDIF()
5354
ENDIF()
5455
ENDFOREACH()
5556
ENDFUNCTION()
56-

0 commit comments

Comments
 (0)