]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: clang-cl improvements
authorViktor Szakats <commit@vsz.me>
Sat, 2 Nov 2024 20:11:28 +0000 (21:11 +0100)
committerViktor Szakats <commit@vsz.me>
Mon, 16 Dec 2024 20:45:07 +0000 (21:45 +0100)
- drop `/clang:` prefix for `-W` options for clang-cl.
  Except for `-Wall` which gets interpreted as MSVC `/Wall`
  and translated to `-Weverything`, which is undesired.
  Related: https://github.com/llvm/llvm-project/issues/102982

- include `MSVC_VERSION` in target flags.
  Useful for clang-cl builds where this information doesn't appear
  elsewhere in the cmake configure log.

- suppress `-Wlanguage-extension-token` more for clang-cl.
  This fixes clang-cl builds with default `CURL_WERROR=OFF` and
  `PICKY_COMPILER=ON`.
  This warning is enabled by `-pedantic` as a warning and by
  `-pedantic-errors` as an error. Verifiable using llvm's
  `diagtool show-enabled -pedantic test.c`.
  Follow-up to fb711b50981e86c9dcdd6c2ba468b5d32edbcfce #15449

Closes #15478

CMake/PickyWarnings.cmake
CMakeLists.txt

index eccab10deedfe40cebcf5a5da361d490e322ae8e..e431df4ccc9a2a9c7ce13a94437a73630b86a333 100644 (file)
@@ -31,9 +31,6 @@ if(CURL_WERROR AND
      NOT CMAKE_VERSION VERSION_LESS 3.23.0) OR  # to avoid check_symbol_exists() conflicting with GCC -pedantic-errors
    CMAKE_C_COMPILER_ID MATCHES "Clang"))
   list(APPEND _picky "-pedantic-errors")
-  if(MSVC)  # clang-cl
-    list(APPEND _picky "-Wno-language-extension-token")  # Override default error to make __int64 size detection pass
-  endif()
 endif()
 
 if(APPLE AND
@@ -137,7 +134,7 @@ if(PICKY_COMPILER)
       )
       if(NOT MSVC)
         list(APPEND _picky_enable
-          -Wlanguage-extension-token         # clang  3.0  # Avoid for clang-cl to allow __int64
+          -Wlanguage-extension-token       # clang  3.0
         )
       endif()
       # Enable based on compiler version
@@ -247,15 +244,18 @@ endif()
 
 # clang-cl
 if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC)
-  if(CMAKE_VERSION VERSION_LESS 3.12)
-    set(_picky_tmp "")
-    foreach(_ccopt IN LISTS _picky)
+  list(APPEND _picky "-Wno-language-extension-token")  # Allow __int64
+
+  set(_picky_tmp "")
+  foreach(_ccopt IN LISTS _picky)
+    # Prefix -Wall, otherwise clang-cl interprets it as an MSVC option and translates it to -Weverything
+    if(_ccopt MATCHES "^-W" AND NOT _ccopt STREQUAL "-Wall")
+      list(APPEND _picky_tmp ${_ccopt})
+    else()
       list(APPEND _picky_tmp "/clang:${_ccopt}")
-    endforeach()
-    set(_picky ${_picky_tmp})
-  else()
-    list(TRANSFORM _picky PREPEND "/clang:")
-  endif()
+    endif()
+  endforeach()
+  set(_picky ${_picky_tmp})
 endif()
 
 if(_picky)
index 412c8a4ab22bf674535fcb4f2aab54b0da1489b6..dbee3ffd16dad16a29ce920ee945c71921b83d60 100644 (file)
@@ -115,7 +115,7 @@ if(MINGW)
   set(_target_flags "${_target_flags} MINGW")
 endif()
 if(MSVC)
-  set(_target_flags "${_target_flags} MSVC")
+  set(_target_flags "${_target_flags} MSVC-${MSVC_VERSION}")
 endif()
 if(VCPKG_TOOLCHAIN)
   set(_target_flags "${_target_flags} VCPKG")