Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | # |
| 3 | # Copyright (c) 2014, Regents of the University of California |
| 4 | # |
| 5 | # GPL 3.0 license, see the COPYING.md file for more information |
| 6 | |
| 7 | from waflib import Logs, Configure |
| 8 | |
| 9 | def options(opt): |
| 10 | opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug', |
| 11 | help='''Compile in debugging mode without all optimizations (-O0)''') |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 12 | |
| 13 | def configure(conf): |
| 14 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 15 | defaultFlags = ['-std=c++0x', '-std=c++11', |
| 16 | '-stdlib=libc++', # clang on OSX < 10.9 by default uses gcc's |
| 17 | # libstdc++, which is not C++11 compatible |
| 18 | '-Wall', '-Wno-long-long', '-Wno-nested-anon-types'] |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 19 | |
| 20 | if conf.options.debug: |
| 21 | conf.define('_DEBUG', 1) |
| 22 | defaultFlags += ['-O0', |
| 23 | '-Og', # gcc >= 4.8 |
| 24 | '-g3', |
| 25 | '-fcolor-diagnostics', # clang |
| 26 | '-fdiagnostics-color', # gcc >= 4.9 |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 27 | '-Wno-error=maybe-uninitialized', # Bug #1560 |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 28 | '-Wno-unneeded-internal-declaration', |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -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 | 906c2ea | 2014-10-31 11:24:50 -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 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -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 | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame^] | 51 | self.start_msg('Checking supported CXXFLAGS') |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -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 | 906c2ea | 2014-10-31 11:24:50 -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 |