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