Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 3 | top = '..' |
| 4 | |
| 5 | def build(bld): |
| 6 | # Single object tools: |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 7 | # tools/foo.cpp is a self-contained tool with a main() function |
| 8 | # and is built as build/bin/foo. These tools cannot be unit-tested. |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 9 | for tool in bld.path.ant_glob('*.cpp'): |
| 10 | name = tool.change_ext('').path_from(bld.path.get_bld()) |
| 11 | bld.program(name=name, |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 12 | target=f'{top}/bin/{name}', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 13 | source=[tool], |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 14 | use='BOOST_TOOLS libndn-nac') |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 15 | |
| 16 | # Sub-directory tools: |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 17 | # tools/foo/**/*.cpp are compiled and linked into build/bin/foo. |
| 18 | # tools/foo/main.cpp must exist and must contain the main() function. |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 19 | # All other objects are collected into 'tools-objects' and can be unit-tested. |
| 20 | testableObjects = [] |
| 21 | for subdir in bld.path.ant_glob('*', dir=True, src=False): |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 22 | name = subdir.path_from(bld.path) |
| 23 | subWscript = subdir.find_node('wscript') |
| 24 | if subWscript: |
| 25 | # if the subdir has a wscript, delegate to it |
| 26 | bld.recurse(name) |
| 27 | continue |
| 28 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 29 | mainFile = subdir.find_node('main.cpp') |
| 30 | if mainFile is None: |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 31 | # not a C++ tool, skip the subdir |
| 32 | continue |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 33 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 34 | srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp']) |
| 35 | srcObjects = '' |
| 36 | if srcFiles: |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 37 | srcObjects = f'tools-{name}-objects' |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 38 | bld.objects(target=srcObjects, |
| 39 | source=srcFiles, |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 40 | use='libndn-nac', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 41 | includes=name) |
| 42 | testableObjects.append(srcObjects) |
| 43 | |
| 44 | bld.program(name=name, |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 45 | target=f'{top}/bin/{name}', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 46 | source=[mainFile], |
Davide Pesavento | f3872f2 | 2023-09-14 15:37:03 -0400 | [diff] [blame] | 47 | use=f'BOOST_TOOLS libndn-nac {srcObjects}', |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 48 | includes=name) |
| 49 | |
| 50 | bld.objects(target='tools-objects', |
| 51 | source=[], |
| 52 | export_includes='.', |
| 53 | use=testableObjects) |