Alexander Afanasyev | f5df8e6 | 2014-02-16 19:56:21 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 3 | from waflib import TaskGen |
Alexander Afanasyev | f5df8e6 | 2014-02-16 19:56:21 -0800 | [diff] [blame] | 4 | |
| 5 | def options(opt): |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 6 | opt.add_option('--with-coverage', action='store_true', default=False, |
| 7 | help='Add compiler flags to enable code coverage information') |
Alexander Afanasyev | f5df8e6 | 2014-02-16 19:56:21 -0800 | [diff] [blame] | 8 | |
| 9 | def configure(conf): |
| 10 | if conf.options.with_coverage: |
Alexander Afanasyev | 4c32e74 | 2014-11-09 21:37:12 -0800 | [diff] [blame] | 11 | if not conf.options.debug: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 12 | conf.fatal('Code coverage flags require debug mode compilation (add --debug)') |
Alexander Afanasyev | f5df8e6 | 2014-02-16 19:56:21 -0800 | [diff] [blame] | 13 | conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'], |
| 14 | linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True) |
| 15 | |
| 16 | @TaskGen.feature('cxx','cc') |
| 17 | @TaskGen.after('process_source') |
| 18 | def add_coverage(self): |
| 19 | if getattr(self, 'use', ''): |
| 20 | self.use += ' GCOV' |
| 21 | else: |
| 22 | self.use = 'GCOV' |