blob: 4e9548c68ea5888ee2f1a2e3a21840fca0ae0d5a [file] [log] [blame]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -07001# -*- 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
7from waflib import Logs, Configure
8
9def 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 Afanasyev4a771362014-04-24 21:29:33 -070012 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 Afanasyev97e4cac2014-03-28 10:55:11 -070014
15def configure(conf):
16 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Davide Pesavento1bdef282014-04-08 20:59:50 +020017 defaultFlags = []
18
19 if conf.options.use_cxx11:
20 defaultFlags += ['-std=c++0x', '-std=c++11']
21 else:
22 defaultFlags += ['-std=c++03']
23
24 defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
25
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070026 if conf.options.debug:
27 conf.define('_DEBUG', 1)
Davide Pesavento1bdef282014-04-08 20:59:50 +020028 defaultFlags += ['-O0',
29 '-Og', # gcc >= 4.8
30 '-g3',
31 '-fcolor-diagnostics', # clang
32 '-fdiagnostics-color', # gcc >= 4.9
33 '-Werror'
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070034 ]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070035 if areCustomCxxflagsPresent:
36 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
37 if len(missingFlags) > 0:
38 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
39 % " ".join(conf.env.CXXFLAGS))
40 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
41 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020042 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070043 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020044 defaultFlags += ['-O2', '-g']
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070045 if not areCustomCxxflagsPresent:
Davide Pesavento1bdef282014-04-08 20:59:50 +020046 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070047
48@Configure.conf
49def add_supported_cxxflags(self, cxxflags):
50 """
51 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
52 """
53 self.start_msg('Checking allowed flags for c++ compiler')
54
55 supportedFlags = []
56 for flag in cxxflags:
57 if self.check_cxx(cxxflags=[flag], mandatory=False):
58 supportedFlags += [flag]
59
Davide Pesavento1bdef282014-04-08 20:59:50 +020060 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070061 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS