blob: 0b109de4934076eb7fe5bfe9730777372a92cda2 [file] [log] [blame]
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3top = '..'
4
5def build(bld):
Alexander Afanasyev08d18742018-03-15 16:31:28 -04006 # Single object tools:
7 # tools/example-tool.cpp is a self-contained tool with a main() function
8 # and is built as build/bin/example-tool.
9 # These tools cannot be unit-tested.
10 for tool in bld.path.ant_glob('*.cpp'):
11 name = tool.change_ext('').path_from(bld.path.get_bld())
12 bld.program(name=name,
13 target='../bin/%s' % name,
14 source=[tool],
15 use='ndns-objects')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070016
Alexander Afanasyev08d18742018-03-15 16:31:28 -040017 # Sub-directory tools:
18 # tools/example-tool/**/*.cpp is compiled and linked into build/bin/example-tool.
19 # tools/example-tool/main.cpp must exist and must contain the main() function.
20 # All other objects are collected into 'tools-objects' and can be unit-tested.
21 testableObjects = []
22 for subdir in bld.path.ant_glob('*', dir=True, src=False):
23 mainFile = subdir.find_node('main.cpp')
24 if mainFile is None:
25 continue # not a C++ tool
26
27 name = subdir.path_from(bld.path)
28 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
29 srcObjects = ''
30 if srcFiles:
Davide Pesavento5704fdf2019-01-20 16:23:11 -050031 srcObjects = 'tool-%s-objects' % name
Alexander Afanasyev08d18742018-03-15 16:31:28 -040032 bld.objects(target=srcObjects,
33 source=srcFiles,
Davide Pesavento5704fdf2019-01-20 16:23:11 -050034 use='ndns-objects')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040035 testableObjects.append(srcObjects)
36
37 bld.program(name=name,
38 target='../bin/%s' % name,
39 source=[mainFile],
Davide Pesavento5704fdf2019-01-20 16:23:11 -050040 use='ndns-objects ' + srcObjects)
Alexander Afanasyev08d18742018-03-15 16:31:28 -040041
42 bld.objects(target='tools-objects',
43 source=[],
44 export_includes='.',
45 use=testableObjects)