wscript 2.0 KB

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