2984fbe4bfa5675a82ae2667586c18cbef529504
[senf.git] / senfscons / BoostUnitTest.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 # ARGH ... Why do they put a '+' in the module name ????????
30 SCons.Tool.cplusplus=getattr(__import__('SCons.Tool.c++', globals(), locals(), []).Tool, 'c++')
31
32 def BoostUnitTest(env, target=None, source=None,  **kw):
33     target = env.arg2nodes(target)[0]
34     source = env.arg2nodes(source)
35
36     binnode = target.dir.File('.' + target.name + '.bin')
37     stampnode = target.dir.File('.' + target.name + '.stamp')
38
39     bin = env.Program(binnode, source, 
40                       LIBS = env['LIBS'] + [ '$TEST_EXTRA_LIBS' ],
41                       _LIBFLAGS = ' -Wl,-Bstatic -l$BOOSTTESTLIB -Wl,-Bdynamic ' + env['_LIBFLAGS'],
42                       **kw)
43
44     stamp = env.Command(stampnode, bin,
45                         [ '$SOURCE $BOOSTTESTARGS',
46                           'touch $TARGET' ],
47                         **kw)
48
49     alias = env.Command(env.File(target), stamp, [ 'true' ])
50
51     compileTests = [ src for src in source 
52                      if src.suffix in SCons.Tool.cplusplus.CXXSuffixes \
53                          and src.exists() \
54                          and 'COMPILE_CHECK' in file(str(src)).read() ]
55     if compileTests:
56         env.Depends(alias, env.CompileCheck(source = compileTests))
57         
58     return alias
59
60 def generate(env):
61     env['BOOSTTESTLIB'] = 'boost_unit_test_framework'
62     env['BOOSTTESTARGS'] = [ '--build_info=yes', '--log_level=test_suite' ]
63     env['BUILDERS']['BoostUnitTest'] = BoostUnitTest
64
65 def exists(env):
66     return 1