blob: 190c9a16ed4eba8e478a91113542c4fcf8ed2def [file] [log] [blame]
Yingdi Yu0b0a7362014-08-05 16:31:30 -07001# -*- 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',
Yingdi Yu6a614442014-10-31 17:42:43 -07007 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Yingdi Yu0b0a7362014-08-05 16:31:30 -07008
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Yingdi Yu6a614442014-10-31 17:42:43 -070011 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']
Yingdi Yu0b0a7362014-08-05 16:31:30 -070015
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
Yingdi Yu6a614442014-10-31 17:42:43 -070028 '-Wno-error=unneeded-internal-declaration', # Bug #1588
Yingdi Yu0b0a7362014-08-05 16:31:30 -070029 ]
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
Yingdi Yu6a614442014-10-31 17:42:43 -070043 # 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
Yingdi Yu0b0a7362014-08-05 16:31:30 -070046@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 """
Yingdi Yu6a614442014-10-31 17:42:43 -070051 self.start_msg('Checking supported CXXFLAGS')
Yingdi Yu0b0a7362014-08-05 16:31:30 -070052
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
Yingdi Yu6a614442014-10-31 17:42:43 -070060
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