blob: 21060a2e30679c0cd2a1c27f7f53ea732f430622 [file] [log] [blame]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07002
3from waflib import Logs, Configure
4
5def options(opt):
6 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
7 help='''Compile in debugging mode without all optimizations (-O0)''')
8
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070011 defaultFlags = []
12
13 if conf.options.use_cxx11:
14 defaultFlags += ['-std=c++0x', '-std=c++11']
15 else:
16 defaultFlags += ['-std=c++03']
17
18 defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
19
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070020 if conf.options.debug:
21 conf.define('_DEBUG', 1)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070022 defaultFlags += ['-O0',
23 '-Og', # gcc >= 4.8
24 '-g3',
25 '-fcolor-diagnostics', # clang
26 '-fdiagnostics-color', # gcc >= 4.9
27 '-Werror'
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070028 ]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070029 if areCustomCxxflagsPresent:
30 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
31 if len(missingFlags) > 0:
32 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070033 % " ".join(conf.env.CXXFLAGS))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070034 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
35 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070036 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070037 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070038 defaultFlags += ['-O2', '-g']
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070039 if not areCustomCxxflagsPresent:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070040 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070041
42@Configure.conf
43def add_supported_cxxflags(self, cxxflags):
44 """
45 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
46 """
47 self.start_msg('Checking allowed flags for c++ compiler')
48
49 supportedFlags = []
50 for flag in cxxflags:
51 if self.check_cxx(cxxflags=[flag], mandatory=False):
52 supportedFlags += [flag]
53
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070054 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070055 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS