7d250ad3ac94c994e5901afcdaeb1d5afea9a792
[senf.git] / senfscons / BoostUnitTests.py
1 import SCons.Script.SConscript
2 import SCons.Defaults
3 import os.path
4 import os
5
6 def BoostUnitTests(env, target, source, test_source=None, LIBS = [], DEPENDS = [], **kw):
7     path, name = os.path.split(target)
8     if test_source:
9         if type(test_source) is not type([]):
10             test_source = [ test_source ]
11     else:
12         test_source = []
13     testEnv = env.Copy(**kw)
14     testEnv.Prepend(LIBS = '$BOOSTTESTLIB')
15     testEnv.Prepend(LIBS = LIBS)
16     sources = []
17     if source:
18         sources = sources + env.Object(source)
19     sources = sources + test_source
20     binName = os.path.join(path,'.' + name +'.bin')
21     testRunner = testEnv.Program(binName, sources)
22     stamp = os.path.join(path,'.' + os.path.splitext(name)[0]+'.stamp')
23     if DEPENDS:
24         env.Depends(testRunner, DEPENDS)
25     return env.Command([ stamp ], testRunner,
26                        [ '$SOURCE $BOOSTTESTARGS',
27                          'touch $TARGET' ])
28
29 def dispatcher(*arg,**kw):
30     return BoostUnitTests(*arg,**kw)
31     
32 def generate(env):
33     env['BOOSTTESTLIB'] = 'boost_unit_test_framework'
34     env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ]
35     env.__class__.BoostUnitTests = dispatcher
36
37 def exists(env):
38     return 1