blob: 541c66c63c06e6dbf58036360ecc1f0ebc1c09bf [file] [log] [blame]
Yingdi Yu40cd1c32014-04-17 15:02:17 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2#
3# Copyright (c) 2014 University of Memphis,
4# Regents of the University of California
5#
6# GPL 3.0 license, see the COPYING.md file for more information
7
8from waflib import Logs, Configure
9
10def options(opt):
11 opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
12 help='''Enable C++11 mode (experimental, may not work)''')
13 opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
14 help='''Compile in debugging mode without all optimizations (-O0)''')
15
16def configure(conf):
17 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
18 defaultFlags = []
19
20 if conf.options.use_cxx11:
21 defaultFlags += ['-std=c++0x', '-std=c++11']
22 else:
23 defaultFlags += ['-std=c++03']
24
25 # defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
26 defaultFlags += ['-Wall', '-Wno-long-long']
27
28 if conf.options.debug:
29 conf.define('_DEBUG', 1)
30 defaultFlags += ['-O0',
31 '-Og', # gcc >= 4.8
32 '-g3',
33 '-fcolor-diagnostics', # clang
34 '-fdiagnostics-color', # gcc >= 4.9
35 '-Werror'
36 ]
37 if areCustomCxxflagsPresent:
38 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
39 if len(missingFlags) > 0:
40 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
41 % " ".join(conf.env.CXXFLAGS))
42 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
43 else:
44 conf.add_supported_cxxflags(defaultFlags)
45 else:
46 defaultFlags += ['-O2', '-g']
47 if not areCustomCxxflagsPresent:
48 conf.add_supported_cxxflags(defaultFlags)
49
50@Configure.conf
51def add_supported_cxxflags(self, cxxflags):
52 """
53 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
54 """
55 self.start_msg('Checking allowed flags for c++ compiler')
56
57 supportedFlags = []
58 for flag in cxxflags:
59 if self.check_cxx(cxxflags=[flag], mandatory=False):
60 supportedFlags += [flag]
61
62 self.end_msg(' '.join(supportedFlags))
63 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS