Check for supported GCC CCFLAGS when building tests.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 3 Dec 2013 17:27:08 +0000 (19:27 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sun, 29 Dec 2013 18:26:58 +0000 (20:26 +0200)
tests/SConstruct

index a44ee55..9480c82 100644 (file)
@@ -33,7 +33,17 @@ env.Append(PROTOCPATH = '#../generator')
 
 # Check the compilation environment, unless we are just cleaning up.
 if not env.GetOption('clean'):
-    conf = Configure(env)
+    def check_ccflags(context, flags):
+        '''Check if given CCFLAGS are supported'''
+        context.Message('Checking support for CCFLAGS="%s"...' % flags)
+        oldflags = context.env['CCFLAGS']
+        context.env.Append(CCFLAGS = flags)
+        result = context.TryCompile("int main() {return 0;}", '.c')
+        context.env.Replace(CCFLAGS = oldflags)
+        context.Result(result)
+        return result
+    
+    conf = Configure(env, custom_tests = {'CheckCCFLAGS': check_ccflags})
 
     # If the platform doesn't support C99, use our own header file instead.
     stdbool = conf.CheckCHeader('stdbool.h')
@@ -62,6 +72,14 @@ if not env.GetOption('clean'):
             conf.env.Append(CCFLAGS = '-fmudflap')
             conf.env.Append(LINKFLAGS = '-lmudflap -fmudflap')
     
+    # Check if we can use extra strict warning flags (only with GCC)
+    extra = '-Wcast-qual -Wlogical-op -Wconversion'
+    extra += ' -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls'
+    extra += ' -Wstack-protector'
+    if 'gcc' in env['CC']:
+        if conf.CheckCCFLAGS(extra):
+            conf.env.Append(CORECFLAGS = extra)
+    
     # End the config stuff
     env = conf.Finish()
 
@@ -71,15 +89,11 @@ if 'gcc' in env['CC']:
     
     # Debug info, warnings as errors
     env.Append(CFLAGS = '-ansi -pedantic -g -O0 -Wall -Werror --coverage -fstack-protector-all')
+    env.Append(CORECFLAGS = '-Wextra')
     env.Append(LINKFLAGS = '--coverage')
     
     # We currently need uint64_t anyway, even though ANSI C90 otherwise..
     env.Append(CFLAGS = '-Wno-long-long')
-
-    # More strict checks on the nanopb core
-    env.Append(CORECFLAGS = '-Wextra -Wcast-qual -Wlogical-op -Wconversion')
-    env.Append(CORECFLAGS = ' -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls')
-    env.Append(CORECFLAGS = ' -Wstack-protector')
 elif 'clang' in env['CC']:
     # CLang
     env.Append(CFLAGS = '-ansi -g -O0 -Wall -Werror')