]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: Do not inject -Werror for clang
authorMatthias Maier <tamiko@43-1.org>
Wed, 16 Dec 2020 19:19:18 +0000 (13:19 -0600)
committerMatthias Maier <tamiko@43-1.org>
Thu, 17 Dec 2020 02:13:58 +0000 (20:13 -0600)
cmake/macros/macro_enable_if_supported.cmake

index 9ce7bb550580d3a793520715d64acea3032b925c..996eaa6cb38fbd2135570718b8d0d9a290c4ef5e 100644 (file)
 
 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()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.