Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 2 | |
| 3 | from waflib import Logs, Configure |
| 4 | |
| 5 | def options(opt): |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 6 | opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug', |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 7 | help='''Compile in debugging mode without optimizations (-O0 or -Og)''') |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 8 | |
| 9 | def configure(conf): |
| 10 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 11 | defaultFlags = ['-std=c++0x', '-std=c++11', |
| 12 | '-stdlib=libc++', # clang on OSX < 10.9 by default uses a non |
| 13 | # C++11-compatible STL library |
| 14 | '-Wall', '-Wno-long-long'] |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 15 | |
| 16 | if conf.options.debug: |
| 17 | conf.define('_DEBUG', 1) |
| 18 | defaultFlags += ['-O0', |
| 19 | '-Og', # gcc >= 4.8 |
| 20 | '-g3', |
| 21 | '-fcolor-diagnostics', # clang |
| 22 | '-fdiagnostics-color', # gcc >= 4.9 |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 23 | '-Werror', |
| 24 | '-Wno-error=deprecated-register', |
| 25 | '-Wno-error=maybe-uninitialized', # Bug #1615 |
| 26 | '-Wno-error=unneeded-internal-declaration', # Bug #1588 |
| 27 | '-Wno-nested-anon-types', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 28 | ] |
| 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'" |
| 33 | % " ".join(conf.env.CXXFLAGS)) |
| 34 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 35 | else: |
| 36 | conf.add_supported_cxxflags(defaultFlags) |
| 37 | else: |
| 38 | defaultFlags += ['-O2', '-g'] |
| 39 | if not areCustomCxxflagsPresent: |
| 40 | conf.add_supported_cxxflags(defaultFlags) |
| 41 | |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 42 | # clang on OSX < 10.9 by default uses a non C++11-compatible STL library |
| 43 | conf.add_supported_linkflags(['-stdlib=libc++']) |
| 44 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 45 | @Configure.conf |
| 46 | def add_supported_cxxflags(self, cxxflags): |
| 47 | """ |
| 48 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 49 | """ |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 50 | self.start_msg('Checking allowed compile-stage flags for c++ compiler') |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 51 | |
| 52 | supportedFlags = [] |
| 53 | for flag in cxxflags: |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 54 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 55 | supportedFlags += [flag] |
| 56 | |
| 57 | self.end_msg(' '.join(supportedFlags)) |
| 58 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |
Vince Lehman | 0a7da61 | 2014-10-29 14:39:29 -0500 | [diff] [blame] | 59 | |
| 60 | @Configure.conf |
| 61 | def add_supported_linkflags(self, linkflags): |
| 62 | """ |
| 63 | Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable |
| 64 | """ |
| 65 | self.start_msg('Checking allowed link-stage flags for c++ compiler') |
| 66 | |
| 67 | supportedFlags = [] |
| 68 | for flag in linkflags: |
| 69 | if self.check_cxx(linkflags=['-Werror', flag], mandatory=False): |
| 70 | supportedFlags += [flag] |
| 71 | |
| 72 | self.end_msg(' '.join(supportedFlags)) |
| 73 | self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS |