• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Help('''
2Type 'scons' to build and run all the available test cases.
3It will automatically detect your platform and C compiler and
4build appropriately.
5
6You can modify the behavious using following options:
7CC          Name of C compiler
8CXX         Name of C++ compiler
9CCFLAGS     Flags to pass to the C compiler
10CXXFLAGS    Flags to pass to the C++ compiler
11
12For example, for a clang build, use:
13scons CC=clang CXX=clang++
14''')
15
16import os
17env = Environment(ENV = os.environ, tools = ['default', 'nanopb'])
18
19# Allow overriding the compiler with scons CC=???
20if 'CC' in ARGUMENTS: env.Replace(CC = ARGUMENTS['CC'])
21if 'CXX' in ARGUMENTS: env.Replace(CXX = ARGUMENTS['CXX'])
22if 'CCFLAGS' in ARGUMENTS: env.Append(CCFLAGS = ARGUMENTS['CCFLAGS'])
23if 'CXXFLAGS' in ARGUMENTS: env.Append(CXXFLAGS = ARGUMENTS['CXXFLAGS'])
24
25# Add the builders defined in site_init.py
26add_nanopb_builders(env)
27
28# Path to the files shared by tests, and to the nanopb core.
29env.Append(CPPPATH = ["#../", "$COMMON"])
30
31# Path for finding nanopb.proto
32env.Append(PROTOCPATH = '#../generator')
33
34# Check the compilation environment, unless we are just cleaning up.
35if not env.GetOption('clean'):
36    def check_ccflags(context, flags, linkflags = ''):
37        '''Check if given CCFLAGS are supported'''
38        context.Message('Checking support for CCFLAGS="%s"... ' % flags)
39        oldflags = context.env['CCFLAGS']
40        oldlinkflags = context.env['CCFLAGS']
41        context.env.Append(CCFLAGS = flags)
42        context.env.Append(LINKFLAGS = linkflags)
43        result = context.TryCompile("int main() {return 0;}", '.c')
44        context.env.Replace(CCFLAGS = oldflags)
45        context.env.Replace(LINKFLAGS = oldlinkflags)
46        context.Result(result)
47        return result
48
49    conf = Configure(env, custom_tests = {'CheckCCFLAGS': check_ccflags})
50
51    # If the platform doesn't support C99, use our own header file instead.
52    stdbool = conf.CheckCHeader('stdbool.h')
53    stdint = conf.CheckCHeader('stdint.h')
54    stddef = conf.CheckCHeader('stddef.h')
55    string = conf.CheckCHeader('string.h')
56    stdlib = conf.CheckCHeader('stdlib.h')
57    if not stdbool or not stdint or not stddef or not string:
58        conf.env.Append(CPPDEFINES = {'PB_SYSTEM_HEADER': '\\"pb_syshdr.h\\"'})
59        conf.env.Append(CPPPATH = "#../extra")
60	conf.env.Append(SYSHDR = '\\"pb_syshdr.h\\"')
61
62        if stdbool: conf.env.Append(CPPDEFINES = {'HAVE_STDBOOL_H': 1})
63        if stdint: conf.env.Append(CPPDEFINES = {'HAVE_STDINT_H': 1})
64        if stddef: conf.env.Append(CPPDEFINES = {'HAVE_STDDEF_H': 1})
65        if string: conf.env.Append(CPPDEFINES = {'HAVE_STRING_H': 1})
66        if stdlib: conf.env.Append(CPPDEFINES = {'HAVE_STDLIB_H': 1})
67
68    # Check if we can use pkg-config to find protobuf include path
69    status, output = conf.TryAction('pkg-config protobuf --variable=includedir > $TARGET')
70    if status:
71        conf.env.Append(PROTOCPATH = output.strip())
72    else:
73        conf.env.Append(PROTOCPATH = '/usr/include')
74
75    # Check protoc version
76    status, output = conf.TryAction('$PROTOC --version > $TARGET')
77    if status:
78        conf.env['PROTOC_VERSION'] = output
79
80    # Check if libmudflap is available (only with GCC)
81    if 'gcc' in env['CC']:
82        if conf.CheckLib('mudflap'):
83            conf.env.Append(CCFLAGS = '-fmudflap')
84            conf.env.Append(LINKFLAGS = '-fmudflap')
85
86    # Check if we can use extra strict warning flags (only with GCC)
87    extra = '-Wcast-qual -Wlogical-op -Wconversion'
88    extra += ' -fstrict-aliasing -Wstrict-aliasing=1'
89    extra += ' -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls'
90    extra += ' -Wstack-protector '
91    if 'gcc' in env['CC']:
92        if conf.CheckCCFLAGS(extra):
93            conf.env.Append(CORECFLAGS = extra)
94
95    # Check if we can use undefined behaviour sanitizer (only with clang)
96    extra = '-fsanitize=undefined '
97    if 'clang' in env['CC']:
98        if conf.CheckCCFLAGS(extra, linkflags = extra):
99            conf.env.Append(CORECFLAGS = extra)
100            conf.env.Append(LINKFLAGS = extra)
101
102    # End the config stuff
103    env = conf.Finish()
104
105# Initialize the CCFLAGS according to the compiler
106if 'gcc' in env['CC']:
107    # GNU Compiler Collection
108
109    # Debug info, warnings as errors
110    env.Append(CFLAGS = '-ansi -pedantic -g -Wall -Werror -fprofile-arcs -ftest-coverage ')
111    env.Append(CORECFLAGS = '-Wextra')
112    env.Append(LINKFLAGS = '-g --coverage')
113
114    # We currently need uint64_t anyway, even though ANSI C90 otherwise..
115    env.Append(CFLAGS = '-Wno-long-long')
116elif 'clang' in env['CC']:
117    # CLang
118    env.Append(CFLAGS = '-ansi -g -Wall -Werror')
119    env.Append(CORECFLAGS = ' -Wextra -Wcast-qual -Wconversion')
120elif 'cl' in env['CC']:
121    # Microsoft Visual C++
122
123    # Debug info on, warning level 2 for tests, warnings as errors
124    env.Append(CFLAGS = '/Zi /W2 /WX')
125    env.Append(LINKFLAGS = '/DEBUG')
126
127    # More strict checks on the nanopb core
128    env.Append(CORECFLAGS = '/W4')
129elif 'tcc' in env['CC']:
130    # Tiny C Compiler
131    env.Append(CFLAGS = '-Wall -Werror -g')
132
133env.SetDefault(CORECFLAGS = '')
134
135if 'clang' in env['CXX']:
136    env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
137elif 'g++' in env['CXX'] or 'gcc' in env['CXX']:
138    env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
139elif 'cl' in env['CXX']:
140    env.Append(CXXFLAGS = '/Zi /W2 /WX')
141
142# Now include the SConscript files from all subdirectories
143import os.path
144env['VARIANT_DIR'] = 'build'
145env['BUILD'] = '#' + env['VARIANT_DIR']
146env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
147
148# Include common/SConscript first to make sure its exports are available
149# to other SConscripts.
150SConscript("common/SConscript", exports = 'env', variant_dir = env['VARIANT_DIR'] + '/common')
151
152for subdir in Glob('*/SConscript') + Glob('regression/*/SConscript'):
153    if str(subdir).startswith("common"): continue
154    SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))
155
156