f2516f338833f91a5ef7312975d992e531947784
[senf.git] / senfscons / BoostUnitTests.py
1 ## \file
2 # \brief BoostUnitTests build
3
4 ## \package senfscons.BoostUnitTests
5 # \brief Builder utilizing the <a href="http://www.boost.org/libs/test/doc/index.html">Boost.Test</a> unit-test framework
6 #
7 # The BoostUnitTests builder will build a unit-test executable using
8 # the <a
9 # href="http://www.boost.org/libs/test/doc/index.html">Boost.Test</a>
10 # library. After building, the unit-test will be executed.
11 #
12 # This builder is used by the SENFSCons.Object() helper to build the
13 # unit test.
14 #
15 # \par Construction Envrionment Variables:
16 # <table class="senf">
17 # <tr><td>\c BOOSTTESTLIB</td><td>Name of the library to use, defaults to \c boost_unit_test_framework</td></tr>
18 # <tr><td>\c BOOSTTESTARGS</td><td>Command line arguments of the test, defaults to <tt>--build_info=yes --log_level=test_suite</tt></td></tr>
19 # </table>
20 #
21 # \todo This is not really a builder. This should be rewritten as one
22 # \ingroup builder
23
24 import SCons.Script.SConscript
25 import SCons.Defaults
26 import os.path
27 import os
28
29 def BoostUnitTests(env, target, objects, test_sources=None, LIBS = [], OBJECTS = [], DEPENDS = [], **kw):
30     path, name = os.path.split(target)
31     if test_sources:
32         if type(test_sources) is not type([]):
33             test_sources = [ test_sources ]
34     else:
35         test_sources = []
36     testEnv = env.Copy(**kw)
37     testEnv.Prepend(_LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ')
38     testEnv.Prepend(LIBS = LIBS)
39     testEnv.Append(LIBS = env['TEST_EXTRA_LIBS'])
40     all_objects = []
41     if not objects:
42         objects = []
43     all_objects = objects + env.Object(test_sources) + OBJECTS
44     binName = os.path.join(path,'.' + name +'.bin')
45     testRunner = testEnv.Program(binName, all_objects)
46     stamp = os.path.join(path,'.' + os.path.splitext(name)[0]+'.stamp')
47     if DEPENDS:
48         env.Depends(testRunner, DEPENDS)
49     return env.Command([ stamp ], testRunner,
50                        [ '$SOURCE $BOOSTTESTARGS',
51                          'touch $TARGET' ])
52
53 def dispatcher(*arg,**kw):
54     return BoostUnitTests(*arg,**kw)
55
56 def generate(env):
57     env['BOOSTTESTLIB'] = 'boost_unit_test_framework'
58     env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ]
59     env.__class__.BoostUnitTests = dispatcher
60
61 def exists(env):
62     return 1