blob: ce19594ffa3f33dec4c102285114c4de72e17de1 [file] [log] [blame]
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3from waflib import Logs, Configure
4
Shuo Chen478204c2014-03-18 18:27:04 -07005def options(opt):
Shuo Chen478204c2014-03-18 18:27:04 -07006 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
Wentao Shanga8f3c402014-10-30 14:03:27 -07007 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Shuo Chen478204c2014-03-18 18:27:04 -07008
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -07009def configure(conf):
10 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Wentao Shanga8f3c402014-10-30 14:03:27 -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 '-pedantic', '-Wall']
Shuo Chen478204c2014-03-18 18:27:04 -070015
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070016 if conf.options.debug:
17 conf.define('_DEBUG', 1)
Shuo Chen478204c2014-03-18 18:27:04 -070018 defaultFlags += ['-O0',
19 '-Og', # gcc >= 4.8
20 '-g3',
21 '-fcolor-diagnostics', # clang
22 '-fdiagnostics-color', # gcc >= 4.9
Wentao Shanga8f3c402014-10-30 14:03:27 -070023 '-Werror',
24 '-Wno-error=deprecated-register',
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070025 ]
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070026 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'"
Shuo Chen478204c2014-03-18 18:27:04 -070030 % " ".join(conf.env.CXXFLAGS))
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070031 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
32 else:
Shuo Chen478204c2014-03-18 18:27:04 -070033 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070034 else:
Shuo Chen478204c2014-03-18 18:27:04 -070035 defaultFlags += ['-O2', '-g']
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070036 if not areCustomCxxflagsPresent:
Shuo Chen478204c2014-03-18 18:27:04 -070037 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070038
Wentao Shanga8f3c402014-10-30 14:03:27 -070039 # 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
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070042@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 """
Wentao Shanga8f3c402014-10-30 14:03:27 -070047 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070048
49 supportedFlags = []
50 for flag in cxxflags:
Wentao Shanga8f3c402014-10-30 14:03:27 -070051 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Alexander Afanasyev3fd14f02014-03-26 14:34:39 -070052 supportedFlags += [flag]
53
Shuo Chen478204c2014-03-18 18:27:04 -070054 self.end_msg(' '.join(supportedFlags))
55 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Wentao Shanga8f3c402014-10-30 14:03:27 -070056
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