cmake: Fix -Wno- handling in add_cxx_flag_if_supported (#1656)

The `-Wno-...` compiler flags only result in a diagnostic if another
diagnostic is emitted.  When passing such flags to
`add_cxx_flag_if_supported` (and `check_cxx_compiler_flag`), the test
would always succeed.  For such cases, test the `-W...` flag instead
of the `-Wno-...` flag.

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt
2023-03-29 11:10:27 +01:00
committed by GitHub
parent 9afb918bf5
commit 8e74722a0a

View File

@@ -82,7 +82,13 @@ endif()
macro(add_cxx_flag_if_supported flag)
string(REGEX REPLACE "[-=+]" "" FLAG_NO_SIGNS ${flag})
check_cxx_compiler_flag(${flag} COMPILER_SUPPORTS_${FLAG_NO_SIGNS})
set(FLAG_TO_TEST ${flag})
if((${flag} MATCHES "^-Wno-") AND NOT (${flag} MATCHES "^-Wno-error="))
# -Wno-... only causes a diagnostic if another diagnostic is emitted.
# Change such flags into a -W... flag to test if the warning is known.
string(REGEX REPLACE "^-Wno-" "-W" FLAG_TO_TEST ${flag})
endif()
check_cxx_compiler_flag(${FLAG_TO_TEST} COMPILER_SUPPORTS_${FLAG_NO_SIGNS})
if(COMPILER_SUPPORTS_${FLAG_NO_SIGNS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()