From 6d0e0695d01bf1823a8aae2b3ec1d488e5215b76 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Tue, 3 Dec 2013 19:27:08 +0200 Subject: Check for supported GCC CCFLAGS when building tests. --- tests/SConstruct | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/SConstruct b/tests/SConstruct index a44ee55f..9480c82c 100644 --- a/tests/SConstruct +++ b/tests/SConstruct @@ -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') -- cgit 1.2.3-korg