cmake: clang-cl improvements

- 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 fb711b5098 #15449

Closes #15478
This commit is contained in:
Viktor Szakats 2024-11-02 21:11:28 +01:00
parent b4aa93114c
commit fa676a6985
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
2 changed files with 13 additions and 13 deletions

View 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)

View 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")