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)''') |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 8 | opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11', |
| 9 | help='''Use C++ 11 features if available in the compiler''') |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 10 | |
| 11 | def configure(conf): |
| 12 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 13 | defaultFlags = [] |
| 14 | |
| 15 | if conf.options.use_cxx11: |
| 16 | defaultFlags += ['-std=c++0x', '-std=c++11'] |
| 17 | else: |
| 18 | defaultFlags += ['-std=c++03'] |
| 19 | |
| 20 | defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long'] |
| 21 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 22 | if conf.options.debug: |
| 23 | conf.define('_DEBUG', 1) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 24 | defaultFlags += ['-O0', |
| 25 | '-Og', # gcc >= 4.8 |
| 26 | '-g3', |
| 27 | '-fcolor-diagnostics', # clang |
| 28 | '-fdiagnostics-color', # gcc >= 4.9 |
Alexander Afanasyev | b67090a | 2014-04-29 22:31:01 -0700 | [diff] [blame] | 29 | '-Werror', |
| 30 | '-Wno-error=deprecated-register', |
Junxiao Shi | 46ffa69 | 2014-05-16 11:11:00 -0700 | [diff] [blame] | 31 | '-Wno-error=maybe-uninitialized', # Bug #1615 |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 32 | ] |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 33 | if areCustomCxxflagsPresent: |
| 34 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 35 | if len(missingFlags) > 0: |
| 36 | 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] | 37 | % " ".join(conf.env.CXXFLAGS)) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 38 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 39 | else: |
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 | else: |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 42 | defaultFlags += ['-O2', '-g'] |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 43 | if not areCustomCxxflagsPresent: |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 44 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 45 | |
| 46 | @Configure.conf |
| 47 | def add_supported_cxxflags(self, cxxflags): |
| 48 | """ |
| 49 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 50 | """ |
| 51 | self.start_msg('Checking allowed flags for c++ compiler') |
| 52 | |
| 53 | supportedFlags = [] |
| 54 | for flag in cxxflags: |
Alexander Afanasyev | 3e6a98e | 2014-04-25 12:02:13 -0700 | [diff] [blame] | 55 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 56 | supportedFlags += [flag] |
| 57 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 58 | self.end_msg(' '.join(supportedFlags)) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 59 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |