blob: 29694b9ac31256688229673094a35817e0072c24 [file] [log] [blame]
Alexander Afanasyev7eb59112014-07-02 14:21: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)''')
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)''')
14
15def configure(conf):
16 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
17 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 += [
25 # '-pedantic',
26 '-Wall',
27 '-Wno-long-long',
28 '-Wno-unneeded-internal-declaration'
29 ]
30
31 if conf.options.debug:
32 conf.define('_DEBUG', 1)
33 defaultFlags += ['-O0',
34 '-Og', # gcc >= 4.8
35 '-g3',
36 '-fcolor-diagnostics', # clang
37 '-fdiagnostics-color', # gcc >= 4.9
38 # '-Werror',
39 '-Wno-error=maybe-uninitialized', # Bug #1560
40 ]
41 if areCustomCxxflagsPresent:
42 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
43 if len(missingFlags) > 0:
44 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
45 % " ".join(conf.env.CXXFLAGS))
46 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
47 else:
48 conf.add_supported_cxxflags(defaultFlags)
49 else:
50 defaultFlags += ['-O2', '-g']
51 if not areCustomCxxflagsPresent:
52 conf.add_supported_cxxflags(defaultFlags)
53
54@Configure.conf
55def add_supported_cxxflags(self, cxxflags):
56 """
57 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
58 """
59 self.start_msg('Checking allowed flags for c++ compiler')
60
61 supportedFlags = []
62 for flag in cxxflags:
63 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
64 supportedFlags += [flag]
65
66 self.end_msg(' '.join(supportedFlags))
67 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS