Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Davide Pesavento | c996742 | 2023-09-07 22:04:34 -0400 | [diff] [blame] | 3 | top = '..' |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 4 | |
| 5 | def build(bld): |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 6 | # Single object tools: |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -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 | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 9 | for tool in bld.path.ant_glob('*.cpp'): |
| 10 | name = tool.change_ext('').path_from(bld.path.get_bld()) |
Davide Pesavento | 550d8c9 | 2023-11-05 01:30:01 -0400 | [diff] [blame] | 11 | bld.program(name=name, |
Davide Pesavento | c996742 | 2023-09-07 22:04:34 -0400 | [diff] [blame] | 12 | target=f'{top}/bin/{name}', |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 13 | source=[tool], |
| 14 | use='ndn-cxx') |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 15 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 16 | # Sub-directory tools: |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -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. |
Davide Pesavento | 550d8c9 | 2023-11-05 01:30:01 -0400 | [diff] [blame] | 19 | # All other objects are collected into 'tools-foo-objects' and can be unit-tested. |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 20 | for subdir in bld.path.ant_glob('*', dir=True, src=False): |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 21 | name = subdir.path_from(bld.path) |
| 22 | subWscript = subdir.find_node('wscript') |
| 23 | if subWscript: |
| 24 | # if the subdir has a wscript, delegate to it |
| 25 | bld.recurse(name) |
| 26 | continue |
| 27 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 28 | mainFile = subdir.find_node('main.cpp') |
| 29 | if mainFile is None: |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 30 | # not a C++ tool, skip the subdir |
| 31 | continue |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 33 | srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp']) |
| 34 | srcObjects = '' |
| 35 | if srcFiles: |
Davide Pesavento | 550d8c9 | 2023-11-05 01:30:01 -0400 | [diff] [blame] | 36 | srcObjects = f'tools-{name}-objects' |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 37 | bld.objects(target=srcObjects, |
| 38 | source=srcFiles, |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 39 | use='ndn-cxx') |
Davide Pesavento | 550d8c9 | 2023-11-05 01:30:01 -0400 | [diff] [blame] | 40 | bld.program(name=name, |
Davide Pesavento | c996742 | 2023-09-07 22:04:34 -0400 | [diff] [blame] | 41 | target=f'{top}/bin/{name}', |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 42 | source=[mainFile], |
Davide Pesavento | 550d8c9 | 2023-11-05 01:30:01 -0400 | [diff] [blame] | 43 | use=f'ndn-cxx {srcObjects}') |