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 | |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 5 | top = '..' |
| 6 | |
| 7 | def build(bld): |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [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()) |
Davide Pesavento | 1944281 | 2018-11-23 14:00:04 -0500 | [diff] [blame] | 14 | bld.program(name='tool-%s' % name, |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 15 | target='../bin/%s' % name, |
| 16 | source=[tool], |
| 17 | use='ndn-cxx') |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 18 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [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 |
Alexander Afanasyev | 28d0d94 | 2015-01-04 14:52:19 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 29 | name = subdir.path_from(bld.path) |
| 30 | srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp']) |
| 31 | srcObjects = '' |
| 32 | if srcFiles: |
Davide Pesavento | 1944281 | 2018-11-23 14:00:04 -0500 | [diff] [blame] | 33 | srcObjects = 'tool-%s-objects' % name |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 34 | bld.objects(target=srcObjects, |
| 35 | source=srcFiles, |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame^] | 36 | use='ndn-cxx') |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 37 | testableObjects.append(srcObjects) |
| 38 | |
Davide Pesavento | 1944281 | 2018-11-23 14:00:04 -0500 | [diff] [blame] | 39 | bld.program(name='tool-%s' % name, |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 40 | target='../bin/%s' % name, |
| 41 | source=[mainFile], |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame^] | 42 | use='ndn-cxx ' + srcObjects) |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 43 | |
| 44 | bld.objects(target='tools-objects', |
| 45 | source=[], |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 46 | use=testableObjects) |
| 47 | |
| 48 | # Tool wrappers |
| 49 | wrapperFiles = bld.path.ant_glob('wrapper/*.sh') |
Davide Pesavento | 1944281 | 2018-11-23 14:00:04 -0500 | [diff] [blame] | 50 | bld(name='tool-wrappers', |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 51 | features='subst', |
| 52 | source=wrapperFiles, |
| 53 | target=['../bin/%s' % node.change_ext('', '.sh').path_from(bld.path.find_dir('wrapper').get_bld()) |
| 54 | for node in wrapperFiles], |
| 55 | install_path='${BINDIR}', |
| 56 | chmod=Utils.O755) |