Author: brane
Date: Sun Jul  6 12:54:56 2025
New Revision: 1926999

URL: http://svn.apache.org/viewvc?rev=1926999&view=rev
Log:
All GCC-like compilers were not created equal. Make sure we don't use extra
warning flags that the C compiler doesn't accept.

* build/SerfChecks.cmake:
  (CheckCFlag): New macro, checks if a warning flag is acceptable.
* CMakeLists.txt: Use CheckCFlag for maintainer-mode flags.

* build/scons_extras.py
  (__env_check_c_flag): New, check if a compiler flag is acceptable.
  (AddEnvironmentMethods): Register it as SerfCheckCFlag.
* SConstruct: Use SerfCheckCFlag for debug-mode flags.

Modified:
    serf/trunk/CMakeLists.txt
    serf/trunk/SConstruct
    serf/trunk/build/SerfChecks.cmake
    serf/trunk/build/scons_extras.py

Modified: serf/trunk/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/serf/trunk/CMakeLists.txt?rev=1926999&r1=1926998&r2=1926999&view=diff
==============================================================================
--- serf/trunk/CMakeLists.txt (original)
+++ serf/trunk/CMakeLists.txt Sun Jul  6 12:54:56 2025
@@ -370,14 +370,16 @@ if(NOT MSVC)
     string(APPEND CMAKE_C_FLAGS_DEBUG " -O0")
 
     if(SERF_MAINTAINER_MODE)
+      # This is for clang, which happily accepts unknow warning options.
+      CheckCFlag(SERF_C_WARNINGS "-Werror=unknown-warning-option")
       # Additional warning flags for more pedantic checks
-      list(APPEND SERF_C_WARNINGS "-Wimplicit-function-declaration")
-      list(APPEND SERF_C_WARNINGS "-Wmissing-variable-declarations")
-      list(APPEND SERF_C_WARNINGS "-Wunreachable-code")
-      list(APPEND SERF_C_WARNINGS "-Wshorten-64-to-32")
-      list(APPEND SERF_C_WARNINGS "-Wno-system-headers")
-      list(APPEND SERF_C_WARNINGS "-Wextra-tokens")
-      list(APPEND SERF_C_WARNINGS "-Wnewline-eof")
+      CheckCFlag(SERF_C_WARNINGS "-Wimplicit-function-declaration")
+      CheckCFlag(SERF_C_WARNINGS "-Wmissing-variable-declarations")
+      CheckCFlag(SERF_C_WARNINGS "-Wunreachable-code")
+      CheckCFlag(SERF_C_WARNINGS "-Wshorten-64-to-32")
+      CheckCFlag(SERF_C_WARNINGS "-Wno-system-headers")
+      CheckCFlag(SERF_C_WARNINGS "-Wextra-tokens")
+      CheckCFlag(SERF_C_WARNINGS "-Wnewline-eof")
     endif()
   endif()
 else()

Modified: serf/trunk/SConstruct
URL: 
http://svn.apache.org/viewvc/serf/trunk/SConstruct?rev=1926999&r1=1926998&r2=1926999&view=diff
==============================================================================
--- serf/trunk/SConstruct (original)
+++ serf/trunk/SConstruct Sun Jul  6 12:54:56 2025
@@ -368,13 +368,16 @@ if sys.platform != 'win32':
     # env.Append(CCFLAGS=['-g'])
     env.SerfAppendIf(['CFLAGS', 'CCFLAGS'], r'-g\S*', CCFLAGS=['-g'])
     env.Append(CPPDEFINES=['DEBUG', '_DEBUG'])
-    env.Append(CCFLAGS=['-Wimplicit-function-declaration',
-                        '-Wmissing-variable-declarations',
-                        '-Wunreachable-code',
-                        '-Wshorten-64-to-32',
-                        '-Wno-system-headers',
-                        '-Wextra-tokens',
-                        '-Wnewline-eof'])
+    for flag in ['-Werror=unknown-warning-option',
+                 '-Wimplicit-function-declaration',
+                 '-Wmissing-variable-declarations',
+                 '-Wunreachable-code',
+                 '-Wshorten-64-to-32',
+                 '-Wno-system-headers',
+                 '-Wextra-tokens',
+                 '-Wnewline-eof']:
+        if env.SerfCheckCFlag(flag):
+          env.Append(CCFLAGS=[flag])
   else:
     # env.Append(CCFLAGS=['-O2'])
     env.SerfAppendIf(['CFLAGS', 'CCFLAGS'], r'-O\S*', CCFLAGS=['-O2'])

Modified: serf/trunk/build/SerfChecks.cmake
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfChecks.cmake?rev=1926999&r1=1926998&r2=1926999&view=diff
==============================================================================
--- serf/trunk/build/SerfChecks.cmake (original)
+++ serf/trunk/build/SerfChecks.cmake Sun Jul  6 12:54:56 2025
@@ -18,6 +18,7 @@
 # ===================================================================
 
 include(CheckCSourceCompiles)
+include(CheckCCompilerFlag)
 include(CheckIncludeFile)
 include(CheckTypeSize)
 
@@ -141,3 +142,13 @@ macro(CheckType name_ header_ symbol_)
     list(APPEND SERF_C_DEFINES "${symbol_}")
   endif()
 endmacro(CheckType)
+
+
+macro(CheckCFlag list_ flag_)
+  string(REGEX REPLACE "[/=-]" "__" __c__ "serf_feature_CheckCFlag_${flag_}")
+  check_c_compiler_flag(${flag_} ${__c__})
+  if(${__c__})
+    list(APPEND ${list_} ${flag_})
+  endif()
+  unset(__c__)
+endmacro(CheckCFlag)

Modified: serf/trunk/build/scons_extras.py
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/scons_extras.py?rev=1926999&r1=1926998&r2=1926999&view=diff
==============================================================================
--- serf/trunk/build/scons_extras.py (original)
+++ serf/trunk/build/scons_extras.py Sun Jul  6 12:54:56 2025
@@ -22,6 +22,7 @@
 import re
 
 import SCons.Environment
+import SCons.SConf
 import SCons.Util
 
 
@@ -54,6 +55,20 @@ def __env_munge_if(env, method, variable
   getattr(env, method)(**kwargs)
 
 
+def __env_check_c_flag(env, flag):
+  '''Check if the C compiler accepts the `flag`'''
+
+  xenv = env.Clone()
+  xenv.Append(CCFLAGS=[flag])
+  xonf = SCons.SConf.SConf(xenv)
+  xmsg = SCons.SConf.CheckContext(xonf)
+  xmsg.Display('Checking if the C compiler accepts %s... ' % (flag,))
+  result = xonf.TryCompile('int main(void) { return 0; }', '.c')
+  xmsg.Result(result)
+  xonf.Finish()
+  return result
+
+
 def AddEnvironmentMethods():
   SCons.Util.AddMethod(
     SCons.Environment.Environment,
@@ -65,6 +80,9 @@ def AddEnvironmentMethods():
     lambda env, variables, pattern, **kwargs:
     __env_munge_if(env, 'Prepend', variables, pattern, **kwargs),
     'SerfPrependIf')
+  SCons.Util.AddMethod(
+    SCons.Environment.Environment,
+    __env_check_c_flag, 'SerfCheckCFlag')
 
 
 #


Reply via email to