blob: c8b11e0f14124728f9f2da6d18a25762e0ec4552 [file] [log] [blame]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07002
3from waflib import Logs, Configure
4
5def options(opt):
6 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +02007 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -07008
9def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +020011 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']
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070015
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070016 if conf.options.debug:
17 conf.define('_DEBUG', 1)
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070018 defaultFlags += ['-O0',
19 '-Og', # gcc >= 4.8
20 '-g3',
21 '-fcolor-diagnostics', # clang
22 '-fdiagnostics-color', # gcc >= 4.9
Alexander Afanasyevb67090a2014-04-29 22:31:01 -070023 '-Werror',
24 '-Wno-error=deprecated-register',
Junxiao Shi46ffa692014-05-16 11:11:00 -070025 '-Wno-error=maybe-uninitialized', # Bug #1615
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +020026 '-Wno-error=unneeded-internal-declaration', # Bug #1588
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070027 ]
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070028 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'"
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070032 % " ".join(conf.env.CXXFLAGS))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070033 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
34 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070035 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070036 else:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070037 defaultFlags += ['-O2', '-g']
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070038 if not areCustomCxxflagsPresent:
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070039 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070040
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +020041 # 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 Afanasyev5e1288e2014-03-28 11:11:48 -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 """
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +020049 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070050
51 supportedFlags = []
52 for flag in cxxflags:
Alexander Afanasyev3e6a98e2014-04-25 12:02:13 -070053 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070054 supportedFlags += [flag]
55
Alexander Afanasyevb78bc4d2014-04-09 21:20:52 -070056 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev5e1288e2014-03-28 11:11:48 -070057 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Davide Pesaventodfe9c6b2014-08-25 21:17:10 +020058
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