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)
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'):
38 # If the platform doesn't support C99, use our own header file instead.
39 stdbool = conf.CheckCHeader('stdbool.h')
40 stdint = conf.CheckCHeader('stdint.h')
41 stddef = conf.CheckCHeader('stddef.h')
42 string = conf.CheckCHeader('string.h')
43 if not stdbool or not stdint or not stddef or not string:
44 conf.env.Append(CPPDEFINES = {'PB_SYSTEM_HEADER': '\\"pb_syshdr.h\\"'})
45 conf.env.Append(CPPPATH = "#../compat")
47 if stdbool: conf.env.Append(CPPDEFINES = {'HAVE_STDBOOL_H': 1})
48 if stdint: conf.env.Append(CPPDEFINES = {'HAVE_STDINT_H': 1})
49 if stddef: conf.env.Append(CPPDEFINES = {'HAVE_STDDEF_H': 1})
50 if string: conf.env.Append(CPPDEFINES = {'HAVE_STRING_H': 1})
52 # Check if we can use pkg-config to find protobuf include path
53 status, output = conf.TryAction('pkg-config protobuf --variable=includedir > $TARGET')
55 conf.env.Append(PROTOCPATH = output.strip())
57 conf.env.Append(PROTOCPATH = '/usr/include')
59 # Check if libmudflap is available (only with GCC)
60 if 'gcc' in env['CC']:
61 if conf.CheckLib('mudflap'):
62 conf.env.Append(CCFLAGS = '-fmudflap')
63 conf.env.Append(LINKFLAGS = '-lmudflap -fmudflap')
65 # End the config stuff
68 # Initialize the CCFLAGS according to the compiler
69 if 'gcc' in env['CC']:
70 # GNU Compiler Collection
72 # Debug info, warnings as errors
73 env.Append(CFLAGS = '-ansi -pedantic -g -O0 -Wall -Werror --coverage -fstack-protector-all')
74 env.Append(LINKFLAGS = '--coverage')
76 # More strict checks on the nanopb core
77 env.Append(CORECFLAGS = '-Wextra -Wcast-qual -Wlogical-op -Wconversion')
78 elif 'clang' in env['CC']:
80 env.Append(CFLAGS = '-ansi -pedantic -g -O0 -Wall -Werror')
81 env.Append(CORECFLAGS = ' -Wextra -Wcast-qual -Wconversion')
82 elif 'cl' in env['CC']:
83 # Microsoft Visual C++
85 # Debug info on, warning level 2 for tests, warnings as errors
86 env.Append(CFLAGS = '/Zi /W2 /WX')
87 env.Append(LINKFLAGS = '/DEBUG')
89 # More strict checks on the nanopb core
90 env.Append(CORECFLAGS = '/W4')
92 # PB_RETURN_ERROR triggers C4127 because of while(0)
93 env.Append(CFLAGS = '/wd4127')
94 elif 'tcc' in env['CC']:
96 env.Append(CFLAGS = '-Wall -Werror -g')
98 env.SetDefault(CORECFLAGS = '')
100 if 'clang++' in env['CXX']:
101 env.Append(CXXFLAGS = '-g -O0 -Wall -Werror -Wextra -Wno-missing-field-initializers')
102 elif 'g++' in env['CXX']:
103 env.Append(CXXFLAGS = '-g -O0 -Wall -Werror -Wextra -Wno-missing-field-initializers')
104 elif 'cl' in env['CXX']:
105 env.Append(CXXFLAGS = '/Zi /W2 /WX')
107 # Now include the SConscript files from all subdirectories
108 SConscript(Glob('*/SConscript'), exports = 'env')