blob: 31f070ed8d7aca89620940f280e774e0d1086840 [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',
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020011 help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070012
13def configure(conf):
14 areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020015 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 '-pedantic', '-Wall']
Davide Pesavento1bdef282014-04-08 20:59:50 +020019
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070020 if conf.options.debug:
21 conf.define('_DEBUG', 1)
Davide Pesavento1bdef282014-04-08 20:59:50 +020022 defaultFlags += ['-O0',
23 '-Og', # gcc >= 4.8
24 '-g3',
25 '-fcolor-diagnostics', # clang
26 '-fdiagnostics-color', # gcc >= 4.9
Junxiao Shi22295032014-04-29 22:57:40 -070027 '-Werror',
28 '-Wno-error=maybe-uninitialized', # Bug #1560
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020029 '-Wno-error=unneeded-internal-declaration', # Bug #1588
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070030 ]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070031 if areCustomCxxflagsPresent:
32 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
33 if len(missingFlags) > 0:
34 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
35 % " ".join(conf.env.CXXFLAGS))
36 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
37 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020038 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070039 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020040 defaultFlags += ['-O2', '-g']
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070041 if not areCustomCxxflagsPresent:
Davide Pesavento1bdef282014-04-08 20:59:50 +020042 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070043
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020044 # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible
45 conf.add_supported_linkflags(['-stdlib=libc++'])
46
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070047@Configure.conf
48def add_supported_cxxflags(self, cxxflags):
49 """
50 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
51 """
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020052 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070053
54 supportedFlags = []
55 for flag in cxxflags:
Alexander Afanasyevd35176c2014-04-25 19:09:41 -070056 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070057 supportedFlags += [flag]
58
Davide Pesavento1bdef282014-04-08 20:59:50 +020059 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070060 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020061
62@Configure.conf
63def add_supported_linkflags(self, linkflags):
64 """
65 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
66 """
67 self.start_msg('Checking supported LINKFLAGS')
68
69 supportedFlags = []
70 for flag in linkflags:
71 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
72 supportedFlags += [flag]
73
74 self.end_msg(' '.join(supportedFlags))
75 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS