Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 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 | 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''') |
| 10 | |
| 11 | def configure(conf): |
| 12 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
| 13 | defaultFlags = [] |
| 14 | |
| 15 | if conf.options.use_cxx11: |
| 16 | defaultFlags += ['-std=c++0x', '-std=c++11'] |
| 17 | else: |
Yingdi Yu | 5ab7a9c | 2014-08-15 10:23:07 -0700 | [diff] [blame] | 18 | defaultFlags += ['-std=c++03', '-Wno-variadic-macros', '-Wno-c99-extensions'] |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 19 | |
| 20 | defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long', '-Wno-unneeded-internal-declaration', |
| 21 | '-Wno-c++11-extensions', '-Wno-nested-anon-types'] |
| 22 | |
| 23 | if conf.options.debug: |
| 24 | conf.define('_DEBUG', 1) |
| 25 | conf.env['_DEBUG'] = 1 |
| 26 | defaultFlags += ['-O0', |
| 27 | '-Og', # gcc >= 4.8 |
| 28 | '-g3', |
| 29 | '-fcolor-diagnostics', # clang |
| 30 | '-fdiagnostics-color', # gcc >= 4.9 |
| 31 | '-Werror', |
| 32 | '-Wno-unused-variable', |
| 33 | '-Wno-error=deprecated-register', |
| 34 | '-Wno-error=maybe-uninitialized', # Bug #1615 |
| 35 | ] |
| 36 | if areCustomCxxflagsPresent: |
| 37 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 38 | if len(missingFlags) > 0: |
| 39 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 40 | % " ".join(conf.env.CXXFLAGS)) |
| 41 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 42 | else: |
| 43 | conf.add_supported_cxxflags(defaultFlags) |
| 44 | else: |
| 45 | defaultFlags += ['-O2', '-g'] |
| 46 | if not areCustomCxxflagsPresent: |
| 47 | conf.add_supported_cxxflags(defaultFlags) |
| 48 | |
| 49 | @Configure.conf |
| 50 | def add_supported_cxxflags(self, cxxflags): |
| 51 | """ |
| 52 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 53 | """ |
| 54 | self.start_msg('Checking allowed flags for c++ compiler') |
| 55 | |
| 56 | supportedFlags = [] |
| 57 | for flag in cxxflags: |
| 58 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
| 59 | supportedFlags += [flag] |
| 60 | |
| 61 | self.end_msg(' '.join(supportedFlags)) |
| 62 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |