blob: 190c9a16ed4eba8e478a91113542c4fcf8ed2def [file] [log] [blame]
spirosmastorakisa99994c2016-01-24 15:26:53 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
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 optimizations (-O0 or -Og)''')
8
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
11 defaultFlags = ['-std=c++0x', '-std=c++11',
12 '-stdlib=libc++', # clang on OSX < 10.9 by default uses gcc's
13 # libstdc++, which is not C++11 compatible
14 '-Wall', '-Wno-nested-anon-types']
15
16 if conf.options.debug:
17 conf.define('_DEBUG', 1)
18 conf.env['_DEBUG'] = 1
19 defaultFlags += ['-O0',
20 '-Og', # gcc >= 4.8
21 '-g3',
22 '-fcolor-diagnostics', # clang
23 '-fdiagnostics-color', # gcc >= 4.9
24 '-Werror',
25 '-Wno-unused-variable',
26 '-Wno-error=deprecated-register',
27 '-Wno-error=maybe-uninitialized', # Bug #1615
28 '-Wno-error=unneeded-internal-declaration', # Bug #1588
29 ]
30 if areCustomCxxflagsPresent:
31 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
32 if len(missingFlags) > 0:
33 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
34 % " ".join(conf.env.CXXFLAGS))
35 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
36 else:
37 conf.add_supported_cxxflags(defaultFlags)
38 else:
39 defaultFlags += ['-O2', '-g']
40 if not areCustomCxxflagsPresent:
41 conf.add_supported_cxxflags(defaultFlags)
42
43 # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible
44 conf.add_supported_linkflags(['-stdlib=libc++'])
45
46@Configure.conf
47def add_supported_cxxflags(self, cxxflags):
48 """
49 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
50 """
51 self.start_msg('Checking supported CXXFLAGS')
52
53 supportedFlags = []
54 for flag in cxxflags:
55 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
56 supportedFlags += [flag]
57
58 self.end_msg(' '.join(supportedFlags))
59 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
60
61@Configure.conf
62def add_supported_linkflags(self, linkflags):
63 """
64 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
65 """
66 self.start_msg('Checking supported LINKFLAGS')
67
68 supportedFlags = []
69 for flag in linkflags:
70 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
71 supportedFlags += [flag]
72
73 self.end_msg(' '.join(supportedFlags))
74 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS