blob: 4dc9ab5c8f5b0ab2ff6bf88d8fe64d113a408767 [file] [log] [blame]
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07002
3from waflib import Logs, Configure
4
5def options(opt):
6 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
Shock Jiang2d8483c2014-10-30 10:15:37 -07007 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07008
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Shock Jiang2d8483c2014-10-30 10:15:37 -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-long-long', '-Wno-unneeded-internal-declaration']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -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
23 '-Werror',
Shock Jiang2d8483c2014-10-30 10:15:37 -070024 '-Wno-error=deprecated-register',
25 '-Wno-error=maybe-uninitialized', # Bug #1615
26 '-Wno-error=unneeded-internal-declaration', # Bug #1588
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070027 ]
28 if areCustomCxxflagsPresent:
29 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
30 if len(missingFlags) > 0:
31 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
32 % " ".join(conf.env.CXXFLAGS))
33 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
34 else:
35 conf.add_supported_cxxflags(defaultFlags)
36 else:
37 defaultFlags += ['-O2', '-g']
38 if not areCustomCxxflagsPresent:
39 conf.add_supported_cxxflags(defaultFlags)
40
Shock Jiang2d8483c2014-10-30 10:15:37 -070041 # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible
42 conf.add_supported_linkflags(['-stdlib=libc++'])
43
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070044@Configure.conf
45def add_supported_cxxflags(self, cxxflags):
46 """
47 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
48 """
Shock Jiang2d8483c2014-10-30 10:15:37 -070049 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070050
51 supportedFlags = []
52 for flag in cxxflags:
53 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
54 supportedFlags += [flag]
55
56 self.end_msg(' '.join(supportedFlags))
57 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Shock Jiang2d8483c2014-10-30 10:15:37 -070058
59@Configure.conf
60def add_supported_linkflags(self, linkflags):
61 """
62 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
63 """
64 self.start_msg('Checking supported LINKFLAGS')
65
66 supportedFlags = []
67 for flag in linkflags:
68 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
69 supportedFlags += [flag]
70
71 self.end_msg(' '.join(supportedFlags))
72 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS