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', |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 7 | help='''Compile in debugging mode without optimizations (-O0 or -Og)''') |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 8 | |
| 9 | def configure(conf): |
| 10 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 11 | defaultFlags = ['-std=c++0x', '-std=c++11', |
| 12 | '-stdlib=libc++', # clang on OSX < 10.9 by default uses gcc's |
| 13 | # libstdc++, which is not C++11 compatible |
| 14 | '-Wall', '-Wno-nested-anon-types'] |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 15 | |
| 16 | if conf.options.debug: |
| 17 | conf.define('_DEBUG', 1) |
| 18 | conf.env['_DEBUG'] = 1 |
| 19 | defaultFlags += ['-O0', |
| 20 | '-Og', # gcc >= 4.8 |
| 21 | '-g3', |
| 22 | '-fcolor-diagnostics', # clang |
| 23 | '-fdiagnostics-color', # gcc >= 4.9 |
| 24 | '-Werror', |
| 25 | '-Wno-unused-variable', |
| 26 | '-Wno-error=deprecated-register', |
| 27 | '-Wno-error=maybe-uninitialized', # Bug #1615 |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 28 | '-Wno-error=unneeded-internal-declaration', # Bug #1588 |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 29 | ] |
| 30 | if areCustomCxxflagsPresent: |
| 31 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 32 | if len(missingFlags) > 0: |
| 33 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 34 | % " ".join(conf.env.CXXFLAGS)) |
| 35 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 36 | else: |
| 37 | conf.add_supported_cxxflags(defaultFlags) |
| 38 | else: |
| 39 | defaultFlags += ['-O2', '-g'] |
| 40 | if not areCustomCxxflagsPresent: |
| 41 | conf.add_supported_cxxflags(defaultFlags) |
| 42 | |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 43 | # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible |
| 44 | conf.add_supported_linkflags(['-stdlib=libc++']) |
| 45 | |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 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 | """ |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 51 | self.start_msg('Checking supported CXXFLAGS') |
Yingdi Yu | 0b0a736 | 2014-08-05 16:31:30 -0700 | [diff] [blame] | 52 | |
| 53 | supportedFlags = [] |
| 54 | for flag in cxxflags: |
| 55 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
| 56 | supportedFlags += [flag] |
| 57 | |
| 58 | self.end_msg(' '.join(supportedFlags)) |
| 59 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |
Yingdi Yu | 6a61444 | 2014-10-31 17:42:43 -0700 | [diff] [blame] | 60 | |
| 61 | @Configure.conf |
| 62 | def add_supported_linkflags(self, linkflags): |
| 63 | """ |
| 64 | Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable |
| 65 | """ |
| 66 | self.start_msg('Checking supported LINKFLAGS') |
| 67 | |
| 68 | supportedFlags = [] |
| 69 | for flag in linkflags: |
| 70 | if self.check_cxx(linkflags=['-Werror', flag], mandatory=False): |
| 71 | supportedFlags += [flag] |
| 72 | |
| 73 | self.end_msg(' '.join(supportedFlags)) |
| 74 | self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS |