Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | # encoding: utf-8 |
| 3 | |
| 4 | from waflib import Logs, Utils, Task, TaskGen |
| 5 | from waflib.Tools import c_preproc |
| 6 | |
| 7 | def options(opt): |
| 8 | opt.add_option('--with-pch', action='store_true', default=False, dest='with_pch', |
| 9 | help='''Try to use precompiled header to speed up compilation ''' |
| 10 | '''(only gcc and clang)''') |
| 11 | |
| 12 | def configure(conf): |
| 13 | conf.env['WITH_PCH'] = conf.options.with_pch |
| 14 | |
| 15 | |
| 16 | @TaskGen.feature('cxx') |
| 17 | @TaskGen.before('process_source') |
| 18 | def process_pch(self): |
| 19 | if getattr(self, 'pch', ''): |
| 20 | # for now support only gcc-compatible things |
| 21 | if self.env['COMPILER_CXX'] == 'g++': |
| 22 | nodes = self.to_nodes(self.pch, path=self.path) |
| 23 | for x in nodes: |
| 24 | z = self.create_task('gchx', x, x.change_ext('.hpp.gch')) |
| 25 | z.orig_self = self |
| 26 | |
| 27 | class gchx(Task.Task): |
| 28 | run_str = '${CXX} -x c++-header ${CXXFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ' + \ |
| 29 | '${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ' + \ |
| 30 | '${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT}' |
| 31 | scan = c_preproc.scan |
| 32 | ext_out = ['.hpp'] |
| 33 | color = 'BLUE' |
| 34 | |
| 35 | def post_run(self): |
| 36 | super(gchx, self).post_run() |
| 37 | self.orig_self.env['CXXFLAGS'] = ['-include', self.inputs[0].relpath()] + \ |
| 38 | self.env['CXXFLAGS'] |