Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 1 | from waflib import TaskGen |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 2 | |
| 3 | def options(opt): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 4 | opt.add_option('--with-coverage', action='store_true', default=False, |
| 5 | help='Add compiler flags to enable code coverage information') |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 6 | |
| 7 | def configure(conf): |
| 8 | if conf.options.with_coverage: |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 9 | if not conf.options.debug: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 10 | conf.fatal('Code coverage flags require debug mode compilation (add --debug)') |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 11 | conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'], |
| 12 | linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True) |
| 13 | |
| 14 | @TaskGen.feature('cxx','cc') |
| 15 | @TaskGen.after('process_source') |
| 16 | def add_coverage(self): |
| 17 | if getattr(self, 'use', ''): |
| 18 | self.use += ' GCOV' |
| 19 | else: |
| 20 | self.use = 'GCOV' |