From: Viktor Szakats Date: Sat, 2 Nov 2024 20:11:28 +0000 (+0100) Subject: cmake: clang-cl improvements X-Git-Tag: curl-8_12_0~335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa676a6985ce6471858258326acc82dd80d08369;p=thirdparty%2Fcurl.git 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 fb711b50981e86c9dcdd6c2ba468b5d32edbcfce #15449 Closes #15478 --- diff --git a/CMake/PickyWarnings.cmake b/CMake/PickyWarnings.cmake index eccab10dee..e431df4ccc 100644 --- a/CMake/PickyWarnings.cmake +++ b/CMake/PickyWarnings.cmake @@ -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) diff --git a/CMakeLists.txt b/CMakeLists.txt index 412c8a4ab2..dbee3ffd16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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")