Alexander Afanasyev | 97e4cac | 2014-03-28 10:55: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 | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 12 | opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11', |
| 13 | help='''Enable C++11 mode (experimental, may not work)''') |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 14 | |
| 15 | def configure(conf): |
| 16 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 17 | defaultFlags = [] |
| 18 | |
| 19 | if conf.options.use_cxx11: |
| 20 | defaultFlags += ['-std=c++0x', '-std=c++11'] |
| 21 | else: |
Alexander Afanasyev | 6a75b76 | 2014-08-14 19:49:36 -0700 | [diff] [blame] | 22 | defaultFlags += ['-std=c++03', '-Wno-variadic-macros', '-Wno-c99-extensions'] |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 23 | |
Alexander Afanasyev | f86b5c4 | 2014-06-13 14:04:42 -0700 | [diff] [blame] | 24 | defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long', '-Wno-unneeded-internal-declaration'] |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 25 | |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 26 | if conf.options.debug: |
| 27 | conf.define('_DEBUG', 1) |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 28 | defaultFlags += ['-O0', |
| 29 | '-Og', # gcc >= 4.8 |
| 30 | '-g3', |
| 31 | '-fcolor-diagnostics', # clang |
| 32 | '-fdiagnostics-color', # gcc >= 4.9 |
Junxiao Shi | 2229503 | 2014-04-29 22:57:40 -0700 | [diff] [blame] | 33 | '-Werror', |
| 34 | '-Wno-error=maybe-uninitialized', # Bug #1560 |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 35 | ] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 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: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 43 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 44 | else: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 45 | defaultFlags += ['-O2', '-g'] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 46 | if not areCustomCxxflagsPresent: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 47 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 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: |
Alexander Afanasyev | d35176c | 2014-04-25 19:09:41 -0700 | [diff] [blame] | 58 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 59 | supportedFlags += [flag] |
| 60 | |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 61 | self.end_msg(' '.join(supportedFlags)) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 62 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |