Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | top = '..' |
| 4 | |
| 5 | def build(bld): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 6 | # Single object tools: |
| 7 | # tools/example-tool.cpp is a self-contained tool with a main() function |
| 8 | # and is built as build/bin/example-tool. |
| 9 | # These tools cannot be unit-tested. |
| 10 | for tool in bld.path.ant_glob('*.cpp'): |
| 11 | name = tool.change_ext('').path_from(bld.path.get_bld()) |
| 12 | bld.program(name=name, |
| 13 | target='../bin/%s' % name, |
| 14 | source=[tool], |
| 15 | use='ndns-objects') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 16 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 17 | # Sub-directory tools: |
| 18 | # tools/example-tool/**/*.cpp is compiled and linked into build/bin/example-tool. |
| 19 | # tools/example-tool/main.cpp must exist and must contain the main() function. |
| 20 | # All other objects are collected into 'tools-objects' and can be unit-tested. |
| 21 | testableObjects = [] |
| 22 | for subdir in bld.path.ant_glob('*', dir=True, src=False): |
| 23 | mainFile = subdir.find_node('main.cpp') |
| 24 | if mainFile is None: |
| 25 | continue # not a C++ tool |
| 26 | |
| 27 | name = subdir.path_from(bld.path) |
| 28 | srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp']) |
| 29 | srcObjects = '' |
| 30 | if srcFiles: |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 31 | srcObjects = 'tool-%s-objects' % name |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 32 | bld.objects(target=srcObjects, |
| 33 | source=srcFiles, |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 34 | use='ndns-objects') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 35 | testableObjects.append(srcObjects) |
| 36 | |
| 37 | bld.program(name=name, |
| 38 | target='../bin/%s' % name, |
| 39 | source=[mainFile], |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 40 | use='ndns-objects ' + srcObjects) |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 41 | |
| 42 | bld.objects(target='tools-objects', |
| 43 | source=[], |
| 44 | export_includes='.', |
| 45 | use=testableObjects) |