blob: 93cabd7f2c935492f2e2154562b8b87ca94a3d46 [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
Davide Pesaventoc9967422023-09-07 22:04:34 -04003top = '..'
Alexander Afanasyeva1ae0a12014-01-28 15:21:02 -08004
5def build(bld):
Alexander Afanasyev5560fd42018-03-07 17:03:03 -05006 # Single object tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -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 Afanasyev5560fd42018-03-07 17:03:03 -05009 for tool in bld.path.ant_glob('*.cpp'):
10 name = tool.change_ext('').path_from(bld.path.get_bld())
Davide Pesavento550d8c92023-11-05 01:30:01 -040011 bld.program(name=name,
Davide Pesaventoc9967422023-09-07 22:04:34 -040012 target=f'{top}/bin/{name}',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050013 source=[tool],
14 use='ndn-cxx')
Yingdi Yu8d7468f2014-02-21 14:49:45 -080015
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050016 # Sub-directory tools:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -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.
Davide Pesavento550d8c92023-11-05 01:30:01 -040019 # All other objects are collected into 'tools-foo-objects' and can be unit-tested.
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050020 for subdir in bld.path.ant_glob('*', dir=True, src=False):
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040021 name = subdir.path_from(bld.path)
22 subWscript = subdir.find_node('wscript')
23 if subWscript:
24 # if the subdir has a wscript, delegate to it
25 bld.recurse(name)
26 continue
27
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050028 mainFile = subdir.find_node('main.cpp')
29 if mainFile is None:
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040030 # not a C++ tool, skip the subdir
31 continue
Alexander Afanasyev28d0d942015-01-04 14:52:19 -080032
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050033 srcFiles = subdir.ant_glob('**/*.cpp', excl=['main.cpp'])
34 srcObjects = ''
35 if srcFiles:
Davide Pesavento550d8c92023-11-05 01:30:01 -040036 srcObjects = f'tools-{name}-objects'
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050037 bld.objects(target=srcObjects,
38 source=srcFiles,
Davide Pesavento7e780642018-11-24 15:51:34 -050039 use='ndn-cxx')
Davide Pesavento550d8c92023-11-05 01:30:01 -040040 bld.program(name=name,
Davide Pesaventoc9967422023-09-07 22:04:34 -040041 target=f'{top}/bin/{name}',
Alexander Afanasyev5560fd42018-03-07 17:03:03 -050042 source=[mainFile],
Davide Pesavento550d8c92023-11-05 01:30:01 -040043 use=f'ndn-cxx {srcObjects}')