From 4e5ad7937a6d4cabee8b4d059f476b85e32c0932 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Tue, 18 Aug 2020 10:37:39 +0300 Subject: [PATCH] Don't add warning flags that don't apply to a specific language Some compilers issue additional CLI-level warning, that cannot be suppressed, when passed flags that are irrelevant for a particular invocation. Temporarily treat warnings as errors when testing flags support so that those warnings lead to flags being excluded. --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7803dc104..4ebd8b2b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -456,6 +456,20 @@ else() list(APPEND WARNING_CANDIDATES -Wformat-security) endif() +set(CMAKE_REQUIRED_FLAGS) + +foreach(FLAG -Werror /WX) + tr_make_id("${FLAG}" FLAG_ID) + set(CACHE_ID "${CMAKE_C_COMPILER_ID}_C_HAS${FLAG_ID}") + string(TOLOWER "${CACHE_ID}" CACHE_ID) + check_c_compiler_flag(${FLAG} ${CACHE_ID}) + if (${CACHE_ID}) + # Make sure the next loop only adds flags that are relevant for a particular language + set(CMAKE_REQUIRED_FLAGS ${FLAG}) + break() + endif() +endforeach() + foreach(FLAG ${WARNING_CANDIDATES}) tr_make_id("${FLAG}" FLAG_ID) @@ -479,6 +493,7 @@ foreach(FLAG ${WARNING_CANDIDATES}) unset(FLAG_ID) endforeach() +unset(CMAKE_REQUIRED_FLAGS) unset(WARNING_CANDIDATES) ###