From: zjyhjqs Date: Wed, 16 Oct 2024 16:17:38 +0000 (+0800) Subject: cmake: fix compile warnings for clang-cl X-Git-Tag: curl-8_11_0~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e89491e1f015bab8b4050ed73d1cedc17419336f;p=thirdparty%2Fcurl.git cmake: fix compile warnings for clang-cl clang-cl is an alternative command-line interface to Clang, designed for compatibility with the Visual C++ compiler, `cl.exe`: https://clang.llvm.org/docs/UsersManual.html#clang-cl The way to test clang-cl in CMake: - `CMAKE__COMPILER_ID`: "Clang" - `CMAKE__COMPILER_FRONTEND_VARIANT`: "MSVC" Note: `CMAKE__COMPILER_FRONTEND_VARIANT` was introduced since CMake 3.14, but the variable `MSVC` works fine here. https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_FRONTEND_VARIANT.html https://cmake.org/cmake/help/latest/variable/MSVC.html Closes #15337 --- diff --git a/CMake/PickyWarnings.cmake b/CMake/PickyWarnings.cmake index 57b176c3fe..d209088276 100644 --- a/CMake/PickyWarnings.cmake +++ b/CMake/PickyWarnings.cmake @@ -30,17 +30,17 @@ if(CURL_WERROR AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0 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")) - set(WPICKY "${WPICKY} -pedantic-errors") + list(APPEND WPICKY "-pedantic-errors") endif() if(APPLE AND (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 3.6) OR (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 6.3)) - set(WPICKY "${WPICKY} -Werror=partial-availability") # clang 3.6 appleclang 6.3 + list(APPEND WPICKY "-Werror=partial-availability") # clang 3.6 appleclang 6.3 endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") - set(WPICKY "${WPICKY} -Werror-implicit-function-declaration") # clang 1.0 gcc 2.95 + list(APPEND WPICKY "-Werror-implicit-function-declaration") # clang 1.0 gcc 2.95 endif() if(PICKY_COMPILER) @@ -221,7 +221,7 @@ if(PICKY_COMPILER) # foreach(_ccopt IN LISTS WPICKY_ENABLE) - set(WPICKY "${WPICKY} ${_ccopt}") + list(APPEND WPICKY "${_ccopt}") endforeach() foreach(_ccopt IN LISTS WPICKY_DETECT) @@ -233,13 +233,24 @@ if(PICKY_COMPILER) string(REPLACE "-Wno-" "-W" _ccopt_on "${_ccopt}") check_c_compiler_flag(${_ccopt_on} ${_optvarname}) if(${_optvarname}) - set(WPICKY "${WPICKY} ${_ccopt}") + list(APPEND WPICKY "${_ccopt}") endif() endforeach() endif() endif() +# clang-cl +if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC) + # list(TRANSFORM WPICKY PREPEND "/clang:") # since CMake 3.12 + set(_wpicky "") + foreach(_ccopt IN LISTS WPICKY) + list(APPEND _wpicky "/clang:${_ccopt}") + endforeach() + set(WPICKY ${_wpicky}) +endif() + if(WPICKY) + string(REPLACE ";" " " WPICKY "${WPICKY}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WPICKY}") message(STATUS "Picky compiler options:${WPICKY}") endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b13b7d604..5a75723da3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1796,7 +1796,7 @@ if(MSVC) endif() # Use multithreaded compilation on VS 2008+ - if(MSVC_VERSION GREATER_EQUAL 1500) + if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1500) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") endif() endif()