blob: 1bb25636e00eaba2fe6ddb9f5bd417515fea5aab [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 Afanasyev6077b392014-12-11 22:56:23 -080030 '-Wno-error=deprecated-register', # Bug #2288
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070031 ]
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070032 if areCustomCxxflagsPresent:
33 missingFlags = [x for x in defaultFlags if x not in conf.env.CXXFLAGS]
34 if len(missingFlags) > 0:
35 Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
36 % " ".join(conf.env.CXXFLAGS))
37 Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
38 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020039 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070040 else:
Davide Pesavento1bdef282014-04-08 20:59:50 +020041 defaultFlags += ['-O2', '-g']
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070042 if not areCustomCxxflagsPresent:
Davide Pesavento1bdef282014-04-08 20:59:50 +020043 conf.add_supported_cxxflags(defaultFlags)
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070044
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020045 # clang on OSX < 10.9 by default uses gcc's libstdc++, which is not C++11 compatible
46 conf.add_supported_linkflags(['-stdlib=libc++'])
47
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070048@Configure.conf
49def add_supported_cxxflags(self, cxxflags):
50 """
51 Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
52 """
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020053 self.start_msg('Checking supported CXXFLAGS')
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070054
55 supportedFlags = []
56 for flag in cxxflags:
Alexander Afanasyevd35176c2014-04-25 19:09:41 -070057 if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070058 supportedFlags += [flag]
59
Davide Pesavento1bdef282014-04-08 20:59:50 +020060 self.end_msg(' '.join(supportedFlags))
Alexander Afanasyev97e4cac2014-03-28 10:55:11 -070061 self.env.CXXFLAGS = supportedFlags + self.env.CXXFLAGS
Davide Pesaventoab1e8f22014-10-21 22:45:33 +020062
63@Configure.conf
64def add_supported_linkflags(self, linkflags):
65 """
66 Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
67 """
68 self.start_msg('Checking supported LINKFLAGS')
69
70 supportedFlags = []
71 for flag in linkflags:
72 if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
73 supportedFlags += [flag]
74
75 self.end_msg(' '.join(supportedFlags))
76 self.env.LINKFLAGS = supportedFlags + self.env.LINKFLAGS