blob: 0df034791aa223df89ca586567f94f0e3a136cbe [file] [log] [blame]
Alexander Afanasyev97e4cac2014-03-28 10:55: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 Afanasyev4a771362014-04-24 21:29:33 -070012 opt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
13 help='''Enable C++11 mode (experimental, may not work)''')
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070014
15def configure(conf):
16 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Davide Pesavento1bdef282014-04-08 20:59:50 +020017 defaultFlags = []
18
19 if conf.options.use_cxx11:
20 defaultFlags += ['-std=c++0x', '-std=c++11']
21 else:
22 defaultFlags += ['-std=c++03']
23
24 defaultFlags += ['-pedantic', '-Wall', '-Wno-long-long']
25
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070026 if conf.options.debug:
27 conf.define('_DEBUG', 1)
Davide Pesavento1bdef282014-04-08 20:59:50 +020028 defaultFlags += ['-O0',
29 '-Og', # gcc >= 4.8
30 '-g3',
31 '-fcolor-diagnostics', # clang
32 '-fdiagnostics-color', # gcc >= 4.9
Junxiao Shi22295032014-04-29 22:57:40 -070033 '-Werror',
34 '-Wno-error=maybe-uninitialized', # Bug #1560
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070035 ]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070036 if areCustomCxxflagsPresent:
37 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
38 if len(missingFlags) > 0:
39 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
40 % " ".join(conf.env.CXXFLAGS))
41 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
42 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020043 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070044 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020045 defaultFlags += ['-O2', '-g']
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070046 if not areCustomCxxflagsPresent:
Davide Pesavento1bdef282014-04-08 20:59:50 +020047 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070048
49@Configure.conf
50def add_supported_cxxflags(self, cxxflags):
51 """
52 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
53 """
54 self.start_msg('Checking allowed flags for c++ compiler')
55
56 supportedFlags = []
57 for flag in cxxflags:
Alexander Afanasyevd35176c2014-04-25 19:09:41 -070058 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070059 supportedFlags += [flag]
60
Davide Pesavento1bdef282014-04-08 20:59:50 +020061 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070062 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS