blob: 4f1d11a27d95f8d7aa281d9b46be8e37730f8625 [file] [log] [blame]
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyevfff47d62014-05-11 19:24:46 -07003from waflib import Utils
4
Davide Pesaventoc9967422023-09-07 22:04:34 -04005top = '..'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08006
7def build(bld):
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05008 # Single object tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -04009 # 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 Afanasyev5560fd42018-03-07 17:03:03 -050011 for tool in bld.path.ant_glob('*.cpp'):
12 name = tool.change_ext('').path_from(bld.path.get_bld())
Davide Pesaventoc9967422023-09-07 22:04:34 -040013 bld.program(name=f'tool-{name}',
14 target=f'{top}/bin/{name}',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050015 source=[tool],
16 use='ndn-cxx')
Yingdi Yu8d7468f2014-02-21 14:49:45 -080017
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050018 # Sub-directory tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040019 # 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 Afanasyev5560fd42018-03-07 17:03:03 -050022 for subdir in bld.path.ant_glob('*', dir=True, src=False):
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040023 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 Afanasyev5560fd42018-03-07 17:03:03 -050030 mainFile = subdir.find_node('main.cpp')
31 if mainFile is None:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040032 # not a C++ tool, skip the subdir
33 continue
Alexander Afanasyev28d0d942015-01-04 14:52:19 -080034
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050035 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
36 srcObjects = ''
37 if srcFiles:
Davide Pesaventoc9967422023-09-07 22:04:34 -040038 srcObjects = f'tool-{name}-objects'
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050039 bld.objects(target=srcObjects,
40 source=srcFiles,
Davide Pesavento7e780642018-11-24 15:51:34 -050041 use='ndn-cxx')
Davide Pesaventoc9967422023-09-07 22:04:34 -040042 bld.program(name=f'tool-{name}',
43 target=f'{top}/bin/{name}',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050044 source=[mainFile],
Davide Pesavento7e780642018-11-24 15:51:34 -050045 use='ndn-cxx ' + srcObjects)