1 import os.path, SCons.Options, SCons.Environment, SCons.Script.SConscript, glob
8 if opts is not None: return
9 opts = SCons.Options.Options('SConfig')
10 opts.Add('CXX', 'C++ compiler to use', 'g++')
11 opts.Add(SCons.Options.BoolOption('final','Enable optimization',0))
20 opts.Add('BOOST_INCLUDES', 'Boost include directory', '')
21 opts.Add('BOOST_VARIANT', 'The boost variant to use', '')
22 opts.Add('BOOST_TOOLSET', 'The boost toolset to use', '')
23 opts.Add('BOOST_LIBDIR', 'The directory of the boost libraries', '')
24 Finalizer(FinalizeBoost)
26 def FinalizeBoost(env):
27 env.Tool('BoostUnitTests', [os.path.split(__file__)[0]])
29 if env['BOOST_TOOLSET']:
31 if not env['final'] : runtime += "gd"
32 if env['STLPORT_LIB'] : runtime += "p"
33 if runtime: runtime = "-" + runtime
34 env['BOOST_VARIANT'] = "-" + env['BOOST_TOOLSET'] + runtime
36 env['BOOSTTESTLIB'] = 'libboost_unit_test_framework' + env['BOOST_VARIANT']
38 env.Append(LIBPATH = [ '$BOOST_LIBDIR' ],
39 CPPPATH = [ '$BOOST_INCLUDES' ])
44 opts.Add('STLPORT_INCLUDES', 'STLport include directory', '')
45 opts.Add('STLPORT_LIB', 'Name of the stlport library or empty to not use stlport', '')
46 opts.Add('STLPORT_LIBDIR', 'The directory of the stlport libraries','')
47 Finalizer(FinalizeSTLPort)
49 def FinalizeSTLPort(env):
50 env['STLPORT_DEBUGLIB'] = ''
51 if env['STLPORT_LIB']:
52 env['STLPORT_DEBUGLIB'] = env['STLPORT_LIB'] + '_stldebug'
53 env.Append(LIBPATH = [ '$STLPORT_LIBDIR' ],
54 CPPPATH = [ '$STLPORT_INCLUDES' ])
56 env.Append(LIBS = [ '$STLPORT_LIB' ])
58 env.Append(LIBS = [ '$STLPORT_DEBUGLIB' ],
59 CPPDEFINES = [ '_STLP_DEBUG' ])
62 Finalizer(FinalizeDoxygen)
64 def FinalizeDoxygen(env):
65 env.Tool('Doxygen', [os.path.split(__file__)[0]])
67 def MakeEnvironment():
68 global opts, finalizers
70 env = SCons.Environment.Environment(options=opts)
71 if SCons.Script.SConscript.Arguments.get('final'):
73 env.Help(opts.GenerateHelpText(env))
74 #conf = env.Configure()
76 if os.environ.has_key('SSH_AUTH_SOCK'):
77 env.Append( ENV = { 'SSH_AUTH_SOCK': os.environ['SSH_AUTH_SOCK'] } )
79 for finalizer in finalizers:
82 env.Append(CXXFLAGS = [ '-Wall', '-Woverloaded-virtual', '-Wno-long-long',
83 '-pedantic', '-ansi' ],
84 LOCALLIBDIR = [ '#' ],
85 LIBPATH = [ '$LOCALLIBDIR' ])
88 env.Append(CXXFLAGS = [ '-O3' ],
89 CPPDEFINES = [ 'NDEBUG' ])
91 env.Append(CXXFLAGS = [ '-O0', '-g', '-fno-inline' ],
97 def GlobSources(exclude=[]):
98 testSources = glob.glob("*.test.cc")
99 sources = [ x for x in glob.glob("*.cc") if x not in testSources and x not in exclude ]
100 return (sources, testSources)
102 def StandardTargets(env):
103 all = env.Alias('all')
104 env.Clean(all, [ '.sconsign', '.sconf_temp', 'config.log', 'ChangeLog.bak', '.clean'
106 env.Depends(all, '.')
108 def GlobalTargets(env):
109 command = "find -name .svn -prune -o \( -name '*.hh' -o -name '*.ih' -o -name '*.cc' -o -name '*.cci' -o -name '*.ct' -o -name '*.cti' -o -name '*.mpp' \) -print " \
110 "| xargs -r awk -F '//' '/%s/{print ARGV[ARGIND] \":\" FNR \":\" $2}' > $TARGET"
111 env.AlwaysBuild(env.Command('TODOS',None,[ command % 'TODO' ]))
112 env.AlwaysBuild(env.Command('FIXMES',None,[ command % ' FIXME' ]))
113 env.AlwaysBuild(env.Command('BUGS',None,[ command % 'BUG' ] ))
114 env.Alias('status',[ 'TODOS', 'FIXMES', 'BUGS' ])
116 def LibPath(lib): return '$LOCALLIBDIR/lib%s.a' % lib
118 def Objects(env, sources, testSources = None, LIBS = []):
119 if type(sources) == type(()):
120 testSources = sources[1]
125 objects = env.Object(sources)
128 test = env.BoostUnitTests(
131 test_source = testSources,
133 DEPENDS = [ env.File(LibPath(x)) for x in LIBS ])
134 env.Alias('all_tests', test)
135 # Hmm ... here I'd like to use an Alias instead of a file
136 # however the alias does not seem to live in the subdirectory
137 # which breaks 'scons -u test'
138 env.Alias(env.File('test'), test)
142 def Doxygen(env, sources, testSources = None, target='doc', image = []):
143 if type(sources) == type(()):
144 testSources = sources[1]
152 env.Alias('all_docs', doc)
155 def Lib(env, library, sources, testSources = None, LIBS = []):
156 objects = Objects(env,sources,testSources,LIBS=LIBS)
159 lib = env.Library(env.File(LibPath(library)),objects)
161 env.Append(ALLLIBS = library)
164 def Binary(env, binary, sources, testSources = None, LIBS = []):
165 objects = Objects(env,sources,testSources,LIBS=LIBS)
169 progEnv.Prepend(LIBS = LIBS)
170 program = progEnv.Program(target=binary,source=objects)
172 env.Depends(program, [ env.File(LibPath(x)) for x in LIBS ])