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 | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 30 | ] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 31 | if areCustomCxxflagsPresent: |
| 32 | missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS] |
| 33 | if len(missingFlags) > 0: |
| 34 | Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'" |
| 35 | % " ".join(conf.env.CXXFLAGS)) |
| 36 | Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags)) |
| 37 | else: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 38 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 39 | else: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 40 | defaultFlags += ['-O2', '-g'] |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 41 | if not areCustomCxxflagsPresent: |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 42 | conf.add_supported_cxxflags(defaultFlags) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 43 | |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame^] | 44 | # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible |
| 45 | conf.add_supported_linkflags(['-stdlib=libc++']) |
| 46 | |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 47 | @Configure.conf |
| 48 | def add_supported_cxxflags(self, cxxflags): |
| 49 | """ |
| 50 | Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable |
| 51 | """ |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame^] | 52 | self.start_msg('Checking supported CXXFLAGS') |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 53 | |
| 54 | supportedFlags = [] |
| 55 | for flag in cxxflags: |
Alexander Afanasyev | d35176c | 2014-04-25 19:09:41 -0700 | [diff] [blame] | 56 | if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False): |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 57 | supportedFlags += [flag] |
| 58 | |
Davide Pesavento | 1bdef28 | 2014-04-08 20:59:50 +0200 | [diff] [blame] | 59 | self.end_msg(' '.join(supportedFlags)) |
Alexander Afanasyev | 97e4cac | 2014-03-28 10:55:11 -0700 | [diff] [blame] | 60 | self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS |
Davide Pesavento | ab1e8f2 | 2014-10-21 22:45:33 +0200 | [diff] [blame^] | 61 | |
| 62 | @Configure.conf |
| 63 | def add_supported_linkflags(self, linkflags): |
| 64 | """ |
| 65 | Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable |
| 66 | """ |
| 67 | self.start_msg('Checking supported LINKFLAGS') |
| 68 | |
| 69 | supportedFlags = [] |
| 70 | for flag in linkflags: |
| 71 | if self.check_cxx(linkflags=['-Werror', flag], mandatory=False): |
| 72 | supportedFlags += [flag] |
| 73 | |
| 74 | self.end_msg(' '.join(supportedFlags)) |
| 75 | self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS |