blob: 225833a9ec838d1215c7202942410dd367e53bae [file] [log] [blame]
Alexander Afanasyev7eb59112014-07-02 14:21:11 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2#
3# Copyright (c) 2014, Regents of the University of California
4#
5# GPL 3.0 license, see the COPYING.md file for more information
6
7from waflib import Logs, Configure
8
9def options(opt):
10 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
11 help='''Compile in debugging mode without all optimizations (-O0)''')
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070012
13def configure(conf):
14 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Yingdi Yu906c2ea2014-10-31 11:24:50 -070015 defaultFlags = ['-std=c++0x', '-std=c++11',
16 '-stdlib=libc++', # clang on OSX < 10.9 by default uses gcc's
17 # libstdc++, which is not C++11 compatible
18 '-Wall', '-Wno-long-long', '-Wno-nested-anon-types']
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070019
20 if conf.options.debug:
21 conf.define('_DEBUG', 1)
22 defaultFlags += ['-O0',
23 '-Og', # gcc >= 4.8
24 '-g3',
25 '-fcolor-diagnostics', # clang
26 '-fdiagnostics-color', # gcc >= 4.9
Alexander Afanasyev7eb59112014-07-02 14:21:11 -070027 '-Wno-error=maybe-uninitialized', # Bug #1560
Yingdi Yu906c2ea2014-10-31 11:24:50 -070028 '-Wno-unneeded-internal-declaration',
Alexander Afanasyev7eb59112014-07-02 14:21:11 -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 Yu906c2ea2014-10-31 11:24:50 -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
Alexander Afanasyev7eb59112014-07-02 14:21:11 -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 Yu906c2ea2014-10-31 11:24:50 -070051 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev7eb59112014-07-02 14:21:11 -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 Yu906c2ea2014-10-31 11:24:50 -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