2 Type 'scons' to build and run all the available test cases.
3 It will automatically detect your platform and C compiler and
6 You can modify the behavious using following options:
8 CXX Name of C++ compiler
9 CCFLAGS Flags to pass to the C compiler
10 CXXFLAGS Flags to pass to the C++ compiler
12 For example, for a clang build, use:
13 scons CC=clang CXX=clang++
17 env = Environment(ENV = os.environ, tools = ['default', 'nanopb'])
19 # Allow overriding the compiler with scons CC=???
20 if 'CC' in ARGUMENTS: env.Replace(CC = ARGUMENTS['CC'])
21 if 'CXX' in ARGUMENTS: env.Replace(CXX = ARGUMENTS['CXX'])
22 if 'CFLAGS' in ARGUMENTS: env.Append(CCFLAGS = ARGUMENTS['CFLAGS'])
23 if 'CXXFLAGS' in ARGUMENTS: env.Append(CCFLAGS = ARGUMENTS['CXXFLAGS'])
25 # Add the builders defined in site_init.py
26 add_nanopb_builders(env)
28 # Path to the files shared by tests, and to the nanopb core.
29 env.Append(CPPPATH = ["#../", "$COMMON"])
31 # Path for finding nanopb.proto
32 env.Append(PROTOCPATH = '#../generator')
34 # Check the compilation environment, unless we are just cleaning up.
35 if not env.GetOption('clean'):
36 def check_ccflags(context, flags):
37 '''Check if given CCFLAGS are supported'''
38 context.Message('Checking support for CCFLAGS="%s"... ' % flags)
39 oldflags = context.env['CCFLAGS']
40 context.env.Append(CCFLAGS = flags)
41 result = context.TryCompile("int main() {return 0;}", '.c')
42 context.env.Replace(CCFLAGS = oldflags)
43 context.Result(result)
46 conf = Configure(env, custom_tests = {'CheckCCFLAGS': check_ccflags})
48 # If the platform doesn't support C99, use our own header file instead.
49 stdbool = conf.CheckCHeader('stdbool.h')
50 stdint = conf.CheckCHeader('stdint.h')
51 stddef = conf.CheckCHeader('stddef.h')
52 string = conf.CheckCHeader('string.h')
53 stdlib = conf.CheckCHeader('stdlib.h')
54 if not stdbool or not stdint or not stddef or not string:
55 conf.env.Append(CPPDEFINES = {'PB_SYSTEM_HEADER': '\\"pb_syshdr.h\\"'})
56 conf.env.Append(CPPPATH = "#../extra")
58 if stdbool: conf.env.Append(CPPDEFINES = {'HAVE_STDBOOL_H': 1})
59 if stdint: conf.env.Append(CPPDEFINES = {'HAVE_STDINT_H': 1})
60 if stddef: conf.env.Append(CPPDEFINES = {'HAVE_STDDEF_H': 1})
61 if string: conf.env.Append(CPPDEFINES = {'HAVE_STRING_H': 1})
62 if stdlib: conf.env.Append(CPPDEFINES = {'HAVE_STDLIB_H': 1})
64 # Check if we can use pkg-config to find protobuf include path
65 status, output = conf.TryAction('pkg-config protobuf --variable=includedir > $TARGET')
67 conf.env.Append(PROTOCPATH = output.strip())
69 conf.env.Append(PROTOCPATH = '/usr/include')
71 # Check if libmudflap is available (only with GCC)
72 if 'gcc' in env['CC']:
73 if conf.CheckLib('mudflap'):
74 conf.env.Append(CCFLAGS = '-fmudflap')
75 conf.env.Append(LINKFLAGS = '-fmudflap')
77 # Check if we can use extra strict warning flags (only with GCC)
78 extra = '-Wcast-qual -Wlogical-op -Wconversion'
79 extra += ' -fstrict-aliasing -Wstrict-aliasing=1'
80 extra += ' -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls'
81 extra += ' -Wstack-protector '
82 if 'gcc' in env['CC']:
83 if conf.CheckCCFLAGS(extra):
84 conf.env.Append(CORECFLAGS = extra)
86 # End the config stuff
89 # Initialize the CCFLAGS according to the compiler
90 if 'gcc' in env['CC']:
91 # GNU Compiler Collection
93 # Debug info, warnings as errors
94 env.Append(CFLAGS = '-ansi -pedantic -g -O0 -Wall -Werror --coverage -fstack-protector-all')
95 env.Append(CORECFLAGS = '-Wextra')
96 env.Append(LINKFLAGS = '--coverage')
98 # We currently need uint64_t anyway, even though ANSI C90 otherwise..
99 env.Append(CFLAGS = '-Wno-long-long')
100 elif 'clang' in env['CC']:
102 env.Append(CFLAGS = '-ansi -g -O0 -Wall -Werror')
103 env.Append(CORECFLAGS = ' -Wextra -Wcast-qual -Wconversion')
104 elif 'cl' in env['CC']:
105 # Microsoft Visual C++
107 # Debug info on, warning level 2 for tests, warnings as errors
108 env.Append(CFLAGS = '/Zi /W2 /WX')
109 env.Append(LINKFLAGS = '/DEBUG')
111 # More strict checks on the nanopb core
112 env.Append(CORECFLAGS = '/W4')
114 # PB_RETURN_ERROR triggers C4127 because of while(0)
115 env.Append(CFLAGS = '/wd4127')
116 elif 'tcc' in env['CC']:
118 env.Append(CFLAGS = '-Wall -Werror -g')
120 env.SetDefault(CORECFLAGS = '')
122 if 'clang++' in env['CXX']:
123 env.Append(CXXFLAGS = '-g -O0 -Wall -Werror -Wextra -Wno-missing-field-initializers')
124 elif 'g++' in env['CXX']:
125 env.Append(CXXFLAGS = '-g -O0 -Wall -Werror -Wextra -Wno-missing-field-initializers')
126 elif 'cl' in env['CXX']:
127 env.Append(CXXFLAGS = '/Zi /W2 /WX')
129 # Now include the SConscript files from all subdirectories
131 env['VARIANT_DIR'] = 'build'
132 env['BUILD'] = '#' + env['VARIANT_DIR']
133 env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
134 for subdir in Glob('*/SConscript'):
135 SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))