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', |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 11 | help='''Compile in debugging mode without optimizations (-O0 or -Og)''') |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 12 | |
| 13 | def configure(conf): |
| 14 | areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0) |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [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 | '-pedantic', '-Wall'] |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 19 | |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 20 | if conf.options.debug: |
| 21 | conf.define('_DEBUG', 1) |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 22 | defaultFlags += ['-O0', |
| 23 | '-Og', # gcc >= 4.8 |
| 24 | '-g3', |
| 25 | '-fcolor-diagnostics', # clang |
| 26 | '-fdiagnostics-color', # gcc >= 4.9 |
Junxiao Shi | 2229503 | 2014-04-29 22:57:40 -0700 | [diff] [blame] | 27 | '-Werror', |
| 28 | '-Wno-error=maybe-uninitialized', # Bug #1560 |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 29 | '-Wno-error=unneeded-internal-declaration', # Bug #1588 |
Alexander Afanasyev | 6077b39 | 2014-12-11 22:56:23 -0800 | [diff] [blame^] | 30 | '-Wno-error=deprecated-register', # Bug #2288 |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 31 | ] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 32 | if areCustomCxxflagsPresent: |
| 33 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 34 | if len(missingFlags) > 0: |
| 35 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 36 | % " ".join(conf.env.CXXFLAGS)) |
| 37 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 38 | else: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 39 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 40 | else: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 41 | defaultFlags += ['-O2', '-g'] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 42 | if not areCustomCxxflagsPresent: |
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 | |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 45 | # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible |
| 46 | conf.add_supported_linkflags(['-stdlib=libc++']) |
| 47 | |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 48 | @Configure.conf |
| 49 | def add_supported_cxxflags(self, cxxflags): |
| 50 | """ |
| 51 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 52 | """ |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 53 | self.start_msg('Checking supported CXXFLAGS') |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 54 | |
| 55 | supportedFlags = [] |
| 56 | for flag in cxxflags: |
Alexander Afanasyev | d35176c | 2014-04-25 19:09:41 -0700 | [diff] [blame] | 57 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 58 | supportedFlags += [flag] |
| 59 | |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 60 | self.end_msg(' '.join(supportedFlags)) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 61 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame] | 62 | |
| 63 | @Configure.conf |
| 64 | def add_supported_linkflags(self, linkflags): |
| 65 | """ |
| 66 | Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable |
| 67 | """ |
| 68 | self.start_msg('Checking supported LINKFLAGS') |
| 69 | |
| 70 | supportedFlags = [] |
| 71 | for flag in linkflags: |
| 72 | if self.check_cxx(linkflags=['-Werror', flag], mandatory=False): |
| 73 | supportedFlags += [flag] |
| 74 | |
| 75 | self.end_msg(' '.join(supportedFlags)) |
| 76 | self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS |