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 | |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 3 | import os.path |
| 4 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 5 | top = '..' |
| 6 | |
| 7 | def build(bld): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 8 | # Single object tools: |
| 9 | # tools/example-tool.cpp is a self-contained tool with a main() function |
| 10 | # and is built as build/bin/example-tool. |
| 11 | # These tools cannot be unit-tested. |
| 12 | for tool in bld.path.ant_glob('*.cpp'): |
| 13 | name = tool.change_ext('').path_from(bld.path.get_bld()) |
| 14 | bld.program(name=name, |
| 15 | target='../bin/%s' % name, |
| 16 | source=[tool], |
| 17 | use='ndns-objects') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 18 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 19 | # Sub-directory tools: |
| 20 | # tools/example-tool/**/*.cpp is compiled and linked into build/bin/example-tool. |
| 21 | # tools/example-tool/main.cpp must exist and must contain the main() function. |
| 22 | # All other objects are collected into 'tools-objects' and can be unit-tested. |
| 23 | testableObjects = [] |
| 24 | for subdir in bld.path.ant_glob('*', dir=True, src=False): |
| 25 | mainFile = subdir.find_node('main.cpp') |
| 26 | if mainFile is None: |
| 27 | continue # not a C++ tool |
| 28 | |
| 29 | name = subdir.path_from(bld.path) |
| 30 | srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp']) |
| 31 | srcObjects = '' |
| 32 | if srcFiles: |
| 33 | srcObjects = 'tools-%s-objects' % name |
| 34 | bld.objects(target=srcObjects, |
| 35 | source=srcFiles, |
| 36 | use='ndn-cxx', |
| 37 | includes=name) |
| 38 | testableObjects.append(srcObjects) |
| 39 | |
| 40 | bld.program(name=name, |
| 41 | target='../bin/%s' % name, |
| 42 | source=[mainFile], |
| 43 | use='ndns-objects ' + srcObjects, |
| 44 | includes=name) |
| 45 | |
| 46 | bld.objects(target='tools-objects', |
| 47 | source=[], |
| 48 | export_includes='.', |
| 49 | use=testableObjects) |