3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
9 Compile whole groups of C/C++ files at once
10 (C and C++ files are processed independently though).
15 opt.load('compiler_cxx')
17 bld.load('compiler_cxx unity')
19 To enable for specific task generators only::
22 bld(features='c cprogram unity', source='main.c', ...)
24 The file order is often significant in such builds, so it can be
25 necessary to adjust the order of source files and the batch sizes.
26 To control the amount of files processed in a batch per target
30 bld(features='c cprogram', unity_size=20)
34 from waflib import Task, Options
35 from waflib.Tools import c_preproc
36 from waflib import TaskGen
41 EXTS_CXX = ('.cpp','.cc','.cxx','.C','.c++')
45 opt.add_option('--batchsize', action='store', dest='batchsize', type='int', default=MAX_BATCH,
46 help='default unity batch size (0 disables unity builds)')
48 @TaskGen.taskgen_method
50 default = getattr(Options.options, 'batchsize', MAX_BATCH)
53 return getattr(self, 'unity_size', default)
56 class unity(Task.Task):
59 def to_include(self, node):
60 ret = node.path_from(self.outputs[0].parent)
61 ret = ret.replace('\\', '\\\\').replace('"', '\\"')
64 lst = ['#include "%s"\n' % self.to_include(node) for node in self.inputs]
66 self.outputs[0].write(txt)
68 node = self.outputs[0]
69 return node.path_from(node.ctx.launch_node())
71 def bind_unity(obj, cls_name, exts):
72 if not 'mappings' in obj.__dict__:
73 obj.mappings = dict(obj.mappings)
77 if fun.__name__ == 'unity_fun':
78 raise ValueError('Attempt to bind unity mappings multiple times %r' % j)
80 def unity_fun(self, node):
81 cnt = self.batch_size()
83 return fun(self, node)
84 x = getattr(self, 'master_%s' % cls_name, None)
85 if not x or len(x.inputs) >= cnt:
86 x = self.create_task('unity')
87 setattr(self, 'master_%s' % cls_name, x)
89 cnt_cur = getattr(self, 'cnt_%s' % cls_name, 0)
90 c_node = node.parent.find_or_declare('unity_%s_%d_%d.%s' % (self.idx, cnt_cur, cnt, cls_name))
92 setattr(self, 'cnt_%s' % cls_name, cnt_cur + 1)
96 obj.mappings[j] = unity_fun
98 @TaskGen.feature('unity')
99 @TaskGen.before('process_source')
100 def single_unity(self):
101 lst = self.to_list(self.features)
103 bind_unity(self, 'c', EXTS_C)
105 bind_unity(self, 'cxx', EXTS_CXX)
109 bind_unity(TaskGen.task_gen, 'c', EXTS_C)
111 bind_unity(TaskGen.task_gen, 'cxx', EXTS_CXX)