blob: 337bc7f60d78bf2219a391d133e00bd4eeb085dc [file] [log] [blame]
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -04003top = '..'
4
5def build(bld):
6 # Single object tools:
Davide Pesaventof3872f22023-09-14 15:37:03 -04007 # 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 Afanasyev2b57aeb2018-06-15 18:32:28 -04009 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 Pesaventof3872f22023-09-14 15:37:03 -040012 target=f'{top}/bin/{name}',
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040013 source=[tool],
Davide Pesaventof3872f22023-09-14 15:37:03 -040014 use='BOOST_TOOLS libndn-nac')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040015
16 # Sub-directory tools:
Davide Pesaventof3872f22023-09-14 15:37:03 -040017 # 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 Afanasyev2b57aeb2018-06-15 18:32:28 -040019 # 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 Pesaventof3872f22023-09-14 15:37:03 -040022 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 Afanasyev2b57aeb2018-06-15 18:32:28 -040029 mainFile = subdir.find_node('main.cpp')
30 if mainFile is None:
Davide Pesaventof3872f22023-09-14 15:37:03 -040031 # not a C++ tool, skip the subdir
32 continue
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040033
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040034 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
35 srcObjects = ''
36 if srcFiles:
Davide Pesaventof3872f22023-09-14 15:37:03 -040037 srcObjects = f'tools-{name}-objects'
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040038 bld.objects(target=srcObjects,
39 source=srcFiles,
Davide Pesaventof3872f22023-09-14 15:37:03 -040040 use='libndn-nac',
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040041 includes=name)
42 testableObjects.append(srcObjects)
43
44 bld.program(name=name,
Davide Pesaventof3872f22023-09-14 15:37:03 -040045 target=f'{top}/bin/{name}',
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040046 source=[mainFile],
Davide Pesaventof3872f22023-09-14 15:37:03 -040047 use=f'BOOST_TOOLS libndn-nac {srcObjects}',
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040048 includes=name)
49
50 bld.objects(target='tools-objects',
51 source=[],
52 export_includes='.',
53 use=testableObjects)