blob: 458677e70a4a1458931058ae6d12d80e2133669c [file] [log] [blame]
Alexander Afanasyev740812e2014-10-30 15:37:45 -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',
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 '-pedantic', '-Wall']
15
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',
24 '-Wno-error=maybe-uninitialized',
25 ]
26 if areCustomCxxflagsPresent:
27 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
28 if len(missingFlags) > 0:
29 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
30 % " ".join(conf.env.CXXFLAGS))
31 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
32 else:
33 conf.add_supported_cxxflags(defaultFlags)
34 else:
35 defaultFlags += ['-O2', '-g']
36 if not areCustomCxxflagsPresent:
37 conf.add_supported_cxxflags(defaultFlags)
38
39 # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible
40 conf.add_supported_linkflags(['-stdlib=libc++'])
41
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 supported CXXFLAGS')
48
49 supportedFlags = []
50 for flag in cxxflags:
51 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
52 supportedFlags += [flag]
53
54 self.end_msg(' '.join(supportedFlags))
55 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
56
57@Configure.conf
58def add_supported_linkflags(self, linkflags):
59 """
60 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
61 """
62 self.start_msg('Checking supported LINKFLAGS')
63
64 supportedFlags = []
65 for flag in linkflags:
66 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
67 supportedFlags += [flag]
68
69 self.end_msg(' '.join(supportedFlags))
70 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS