blob: e699edb3fe27b6614ad3169183a391c0795882cd [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Yingdi Yu40cd1c32014-04-17 15:02:17 -07002
3from waflib import Logs, Configure
4
5def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -07006 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
Vince Lehman0a7da612014-10-29 14:39:29 -05007 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Yingdi Yu40cd1c32014-04-17 15:02:17 -07008
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Vince Lehman0a7da612014-10-29 14:39:29 -050011 defaultFlags = ['-std=c++0x', '-std=c++11',
12 '-stdlib=libc++', # clang on OSX < 10.9 by default uses a non
13 # C++11-compatible STL library
14 '-Wall', '-Wno-long-long']
Yingdi Yu40cd1c32014-04-17 15:02:17 -070015
16 if conf.options.debug:
17 conf.define('_DEBUG', 1)
18 defaultFlags += ['-O0',
19 '-Og', # gcc >= 4.8
20 '-g3',
21 '-fcolor-diagnostics', # clang
22 '-fdiagnostics-color', # gcc >= 4.9
Vince Lehman0a7da612014-10-29 14:39:29 -050023 '-Werror',
24 '-Wno-error=deprecated-register',
25 '-Wno-error=maybe-uninitialized', # Bug #1615
26 '-Wno-error=unneeded-internal-declaration', # Bug #1588
27 '-Wno-nested-anon-types',
Yingdi Yu40cd1c32014-04-17 15:02:17 -070028 ]
29 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'"
33 % " ".join(conf.env.CXXFLAGS))
34 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
35 else:
36 conf.add_supported_cxxflags(defaultFlags)
37 else:
38 defaultFlags += ['-O2', '-g']
39 if not areCustomCxxflagsPresent:
40 conf.add_supported_cxxflags(defaultFlags)
41
Vince Lehman0a7da612014-10-29 14:39:29 -050042 # clang on OSX < 10.9 by default uses a non C++11-compatible STL library
43 conf.add_supported_linkflags(['-stdlib=libc++'])
44
Yingdi Yu40cd1c32014-04-17 15:02:17 -070045@Configure.conf
46def add_supported_cxxflags(self, cxxflags):
47 """
48 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
49 """
Vince Lehman0a7da612014-10-29 14:39:29 -050050 self.start_msg('Checking allowed compile-stage flags for c++ compiler')
Yingdi Yu40cd1c32014-04-17 15:02:17 -070051
52 supportedFlags = []
53 for flag in cxxflags:
Vince Lehman0a7da612014-10-29 14:39:29 -050054 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070055 supportedFlags += [flag]
56
57 self.end_msg(' '.join(supportedFlags))
58 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Vince Lehman0a7da612014-10-29 14:39:29 -050059
60@Configure.conf
61def add_supported_linkflags(self, linkflags):
62 """
63 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
64 """
65 self.start_msg('Checking allowed link-stage flags for c++ compiler')
66
67 supportedFlags = []
68 for flag in linkflags:
69 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
70 supportedFlags += [flag]
71
72 self.end_msg(' '.join(supportedFlags))
73 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS