wscript (2078B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Thomas Nagy, 2010 (ita) 4 5 VERSION='0.0.1' 6 APPNAME='crazy_test' 7 8 top = '.' 9 out = 'build' 10 11 def options(opt): 12 opt.load('compiler_cxx') 13 14 def configure(conf): 15 conf.load('compiler_cxx') 16 17 def build(bld): 18 bld.program(source='main.cpp', target='app') 19 20 """ 21 Only main.cpp is added to the program, then by looking at the include files, 22 a <file.h> file is found. If a corresponding <file.cpp> exists, 23 then a new c++ task is created to compile that file and to add it to the 24 program (modify the link task). 25 26 The idea is to change the method runnable_status of the task. A more correct but less obvious 27 approach would be the creation of a specific c++ subclass, and using another 28 extension mapping function (@extension). 29 """ 30 31 from waflib.Task import ASK_LATER 32 from waflib.Tools.cxx import cxx 33 def runnable_status(self): 34 ret = super(cxx, self).runnable_status() 35 self.more_tasks = [] 36 37 # use a cache to avoid creating the same tasks 38 # for example, truc.cpp might be compiled twice 39 try: 40 shared = self.generator.bld.shared_tasks 41 except AttributeError: 42 shared = self.generator.bld.shared_tasks = {} 43 44 if ret != ASK_LATER: 45 for x in self.generator.bld.node_deps[self.uid()]: 46 node = x.parent.get_src().find_resource(x.name.replace('.h', '.cpp')) 47 if node: 48 try: 49 tsk = shared[node] 50 except: 51 tsk = shared[node] = self.generator.cxx_hook(node) 52 53 self.more_tasks.append(tsk) 54 55 56 # add the node created to the link task outputs 57 try: 58 link = self.generator.link_task 59 except AttributeError: 60 pass 61 else: 62 if not tsk.outputs[0] in link.inputs: 63 link.inputs.append(tsk.outputs[0]) 64 link.set_run_after(tsk) 65 66 # any change in the order of the input nodes may cause a recompilation 67 link.inputs.sort(key=lambda x: x.abspath()) 68 69 # if you want to modify some flags 70 # you *must* have the task recompute the signature 71 self.env.append_value('CXXFLAGS', '-O2') 72 delattr(self, 'cache_sig') 73 return super(cxx, self).runnable_status() 74 75 return ret 76 77 cxx.runnable_status = runnable_status 78