Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 2 | |
| 3 | from waflib import Logs, Configure |
| 4 | |
| 5 | def options(opt): |
| 6 | opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug', |
| 7 | help='''Compile in debugging mode without all optimizations (-O0)''') |
| 8 | |
| 9 | def configure(conf): |
| 10 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 11 | defaultFlags = [] |
| 12 | |
| 13 | if conf.options.use_cxx11: |
| 14 | defaultFlags += ['-std=c++0x', '-std=c++11'] |
| 15 | else: |
| 16 | defaultFlags += ['-std=c++03'] |
| 17 | |
| 18 | defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long'] |
| 19 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 20 | if conf.options.debug: |
| 21 | conf.define('_DEBUG', 1) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 22 | defaultFlags += ['-O0', |
| 23 | '-Og', # gcc >= 4.8 |
| 24 | '-g3', |
| 25 | '-fcolor-diagnostics', # clang |
| 26 | '-fdiagnostics-color', # gcc >= 4.9 |
| 27 | '-Werror' |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 28 | ] |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 29 | if areCustomCxxflagsPresent: |
| 30 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 31 | if len(missingFlags) > 0: |
| 32 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 33 | % " ".join(conf.env.CXXFLAGS)) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 34 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 35 | else: |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 36 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 37 | else: |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 38 | defaultFlags += ['-O2', '-g'] |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 39 | if not areCustomCxxflagsPresent: |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 40 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 41 | |
| 42 | @Configure.conf |
| 43 | def add_supported_cxxflags(self, cxxflags): |
| 44 | """ |
| 45 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 46 | """ |
| 47 | self.start_msg('Checking allowed flags for c++ compiler') |
| 48 | |
| 49 | supportedFlags = [] |
| 50 | for flag in cxxflags: |
| 51 | if self.check_cxx(cxxflags=[flag], mandatory=False): |
| 52 | supportedFlags += [flag] |
| 53 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 54 | self.end_msg(' '.join(supportedFlags)) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 55 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |