From c898c156c93ab8b06d9a1dc6027274b1cb0135b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Fri, 6 Sep 2019 11:54:29 +0200 Subject: [PATCH] cmake: Fix bug where -Wno- flags could not be compatbility-checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out that 'check_compiler_flag' has not been working for flags that start with -Wno-. This has caused old compilers to accidentally use flags that they do not support. To fix this we check for compatibility with the appropriate -W flag instead and infer the -Wno- compatibility from this check. The root cause of this problem is explained well here: https://github.com/zephyrproject-rtos/zephyr/pull/18922#discussion_r321537098 Signed-off-by: Sebastian Bøe --- cmake/extensions.cmake | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmake/extensions.cmake b/cmake/extensions.cmake index e28f416b9dd..cbb640ca158 100644 --- a/cmake/extensions.cmake +++ b/cmake/extensions.cmake @@ -747,8 +747,17 @@ function(zephyr_check_compiler_flag lang option check) return() endif() - # Test the flag - check_compiler_flag(${lang} "${option}" inner_check) + # Flags that start with -Wno- can not be tested by + # check_compiler_flag, they will always pass, but -W can be + # tested, so to test -Wno- flags we test -W + # instead. + if("${option}" MATCHES "-Wno-(.*)") + set(possibly_translated_option -W${CMAKE_MATCH_1}) + else() + set(possibly_translated_option ${option}) + endif() + + check_compiler_flag(${lang} "${possibly_translated_option}" inner_check) set(${check} ${inner_check} PARENT_SCOPE)