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