From f10c789883603c044131e336cbe7b33c77655118 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 16 Dec 2020 13:19:18 -0600 Subject: [PATCH] CMake: Do not inject -Werror for clang --- cmake/macros/macro_enable_if_supported.cmake | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cmake/macros/macro_enable_if_supported.cmake b/cmake/macros/macro_enable_if_supported.cmake index 9ce7bb5505..996eaa6cb3 100644 --- a/cmake/macros/macro_enable_if_supported.cmake +++ b/cmake/macros/macro_enable_if_supported.cmake @@ -23,18 +23,22 @@ MACRO(ENABLE_IF_SUPPORTED _variable _flag) # - # Clang is too conservative when reporting unsupported compiler flags. - # Therefore, we promote all warnings for an unsupported compiler flag to - # actual errors with the -Werror switch: + # For CMake prior to 3.19: # - IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Old clang versions are too conservative when reporting unsupported + # compiler flags. Therefore, we promote all warnings for an unsupported + # compiler flag to actual errors with the -Werror switch: + # + # Note: For cmake-3.19 onwards the supplied compiler flag must be a + # single flag. See https://github.com/dealii/dealii/issues/11272 + # + IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_VERSION VERSION_LESS 3.19) SET(_werror_string "-Werror ") ELSE() SET(_werror_string "") ENDIF() STRING(STRIP "${_flag}" _flag_stripped) - SET(_flag_stripped_orig "${_flag_stripped}") # # Gcc does not emit a warning if testing -Wno-... flags which leads to @@ -43,21 +47,19 @@ MACRO(ENABLE_IF_SUPPORTED _variable _flag) # compilation unit. # Therefore we invert the test for -Wno-... flags: # + SET(_flag_sanitized "${_flag_stripped}") IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - STRING(REPLACE "-Wno-" "-W" _flag_stripped "${_flag_stripped}") + STRING(REPLACE "-Wno-" "-W" _flag_sanitized "${_flag_stripped}") ENDIF() IF(NOT "${_flag_stripped}" STREQUAL "") STRING(REGEX REPLACE "^-" "" _flag_name "${_flag_stripped}") - STRING(REPLACE "," "" _flag_name "${_flag_name}") - STRING(REPLACE "-" "_" _flag_name "${_flag_name}") - STRING(REPLACE "+" "_" _flag_name "${_flag_name}") - CHECK_CXX_COMPILER_FLAG( - "${_werror_string}${_flag_stripped}" - DEAL_II_HAVE_FLAG_${_flag_name} - ) + STRING(REGEX REPLACE "\[-+,\]" "_" _flag_name "${_flag_name}") + + CHECK_CXX_COMPILER_FLAG("${_flag_sanitized}" DEAL_II_HAVE_FLAG_${_flag_name}) + IF(DEAL_II_HAVE_FLAG_${_flag_name}) - SET(${_variable} "${${_variable}} ${_flag_stripped_orig}") + SET(${_variable} "${${_variable}} ${_flag_stripped}") STRING(STRIP "${${_variable}}" ${_variable}) ENDIF() ENDIF() -- 2.39.5