]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: merge `CURL_WERROR` logic into `PickyWarnings.cmake`
authorViktor Szakats <commit@vsz.me>
Tue, 15 Apr 2025 11:12:35 +0000 (13:12 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 15 Apr 2025 12:48:48 +0000 (14:48 +0200)
Safe to do this now, as the code no longer relies on setting these
options after feature detection.

Also: Tidy up the way we handle options not to be passed to feature
checks, and make sure to show them in the configure log.

Follow-up to e86542038dda88dadf8959584e803895f979310c #17047
Closes #17062

CMake/PickyWarnings.cmake
CMakeLists.txt

index 70641763ebd0859637e83b91bd2e0a40a25d66b3..e86e184bfa60059abe09dab881f2d4438892bb3d 100644 (file)
 include(CheckCCompilerFlag)
 
 set(_picky "")
+set(_picky_nocheck "")  # not to pass to feature checks
 
-if(CURL_WERROR AND
-   ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
-     NOT DOS AND  # Watt-32 headers use the '#include_next' GCC extension
-     CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0) OR
-   CMAKE_C_COMPILER_ID MATCHES "Clang"))
-  list(APPEND _picky "-pedantic-errors")
+if(CURL_WERROR)
+  if(MSVC)
+    list(APPEND _picky_nocheck "-WX")
+  else()  # llvm/clang and gcc style options
+    list(APPEND _picky_nocheck "-Werror")
+  endif()
+
+  if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND
+      NOT DOS AND  # Watt-32 headers use the '#include_next' GCC extension
+      CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 5.0) OR
+     CMAKE_C_COMPILER_ID MATCHES "Clang")
+    list(APPEND _picky_nocheck "-pedantic-errors")
+  endif()
 endif()
 
 if(APPLE AND
@@ -44,6 +52,7 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
 endif()
 
 if(MSVC)
+  # Use the highest warning level for Visual Studio.
   string(REGEX REPLACE "[/-]W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
   list(APPEND _picky "-W4")
 elseif(BORLAND)
@@ -278,25 +287,28 @@ endif()
 if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND MSVC)
   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}")
-    endif()
+  foreach(_wlist IN ITEMS _picky_nocheck _picky)
+    set(_picky_tmp "")
+    foreach(_ccopt IN LISTS "${_wlist}")
+      # 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}")
+      endif()
+    endforeach()
+    set("${_wlist}" ${_picky_tmp})
   endforeach()
-  set(_picky ${_picky_tmp})
 endif()
 
-if(_picky)
-  string(REPLACE ";" " " _picky_tmp "${_picky}")
+if(_picky_nocheck OR _picky)
+  set(_picky_tmp "${_picky_nocheck}" "${_picky}")
+  string(REPLACE ";" " " _picky_tmp "${_picky_tmp}")
+  string(STRIP "${_picky_tmp}" _picky_tmp)
   message(STATUS "Picky compiler options: ${_picky_tmp}")
-  set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "${_picky}")
+  set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "${_picky_nocheck}" "${_picky}")
 
   # Apply to all feature checks
-  list(REMOVE_ITEM _picky "-pedantic-errors")  # Must not pass to feature checks
   string(REPLACE ";" " " _picky_tmp "${_picky}")
   string(APPEND CMAKE_REQUIRED_FLAGS " ${_picky_tmp}")
 
index c25d823ef950be704a75d41a94f677c78a181669..bb645ac3721750730ac6ac2c36b84eebb007d628 100644 (file)
@@ -2009,14 +2009,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")  # MSVC but exclude clang-cl
   set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-MP")  # Parallel compilation
 endif()
 
-if(CURL_WERROR)
-  if(MSVC)
-    set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-WX")
-  else()
-    set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-Werror")  # This assumes clang or gcc style options
-  endif()
-endif()
-
 if(CURL_LTO)
   if(CMAKE_VERSION VERSION_LESS 3.9)
     message(FATAL_ERROR "LTO has been requested, but your cmake version ${CMAKE_VERSION} is to old. You need at least 3.9")