Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 1 | import platform |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 2 | from waflib import Configure, Logs, Utils |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 3 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 4 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 5 | def options(opt): |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 6 | opt.add_option('--debug', '--with-debug', action='store_true', default=False, |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 7 | help='Compile in debugging mode with minimal optimizations (-Og)') |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 8 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 9 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 10 | def configure(conf): |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 11 | conf.start_msg('Checking C++ compiler version') |
| 12 | |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 13 | cxx = conf.env.CXX_NAME # generic name of the compiler |
| 14 | ccver = tuple(int(i) for i in conf.env.CC_VERSION) |
| 15 | ccverstr = '.'.join(conf.env.CC_VERSION) |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 16 | errmsg = '' |
| 17 | warnmsg = '' |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 18 | if cxx == 'gcc': |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 19 | if ccver < (7, 4, 0): |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 20 | errmsg = ('The version of gcc you are using is too old.\n' |
Davide Pesavento | 762548b | 2023-03-05 11:02:02 -0500 | [diff] [blame] | 21 | 'The minimum supported gcc version is 9.3.') |
| 22 | elif ccver < (9, 3, 0): |
| 23 | warnmsg = ('Using a version of gcc older than 9.3 is not ' |
| 24 | 'officially supported and may result in build failures.') |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 25 | conf.flags = GccFlags() |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 26 | elif cxx == 'clang': |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 27 | if Utils.unversioned_sys_platform() == 'darwin': |
| 28 | if ccver < (10, 0, 0): |
| 29 | errmsg = ('The version of Xcode you are using is too old.\n' |
Davide Pesavento | 762548b | 2023-03-05 11:02:02 -0500 | [diff] [blame] | 30 | 'The minimum supported Xcode version is 12.4.') |
| 31 | elif ccver < (12, 0, 0): |
| 32 | warnmsg = ('Using a version of Xcode older than 12.4 is not ' |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 33 | 'officially supported and may result in build failures.') |
Davide Pesavento | 762548b | 2023-03-05 11:02:02 -0500 | [diff] [blame] | 34 | elif ccver < (7, 0, 0): |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 35 | errmsg = ('The version of clang you are using is too old.\n' |
Davide Pesavento | 762548b | 2023-03-05 11:02:02 -0500 | [diff] [blame] | 36 | 'The minimum supported clang version is 7.0.') |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 37 | conf.flags = ClangFlags() |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 38 | else: |
Davide Pesavento | f662500 | 2022-07-31 17:15:02 -0400 | [diff] [blame] | 39 | warnmsg = f'{cxx} compiler is unsupported' |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 40 | conf.flags = CompilerFlags() |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 41 | |
| 42 | if errmsg: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 43 | conf.end_msg(ccverstr, color='RED') |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 44 | conf.fatal(errmsg) |
| 45 | elif warnmsg: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 46 | conf.end_msg(ccverstr, color='YELLOW') |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 47 | Logs.warn('WARNING: ' + warnmsg) |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 48 | else: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 49 | conf.end_msg(ccverstr) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 50 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 51 | conf.areCustomCxxflagsPresent = len(conf.env.CXXFLAGS) > 0 |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 52 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 53 | # General flags are always applied (e.g., selecting C++ language standard) |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 54 | generalFlags = conf.flags.getGeneralFlags(conf) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 55 | conf.add_supported_cxxflags(generalFlags['CXXFLAGS']) |
| 56 | conf.add_supported_linkflags(generalFlags['LINKFLAGS']) |
| 57 | conf.env.DEFINES += generalFlags['DEFINES'] |
| 58 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 59 | |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 60 | @Configure.conf |
| 61 | def check_compiler_flags(conf): |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 62 | # Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 63 | # corresponding environment variables are not set. |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 64 | # DEFINES are always applied. |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 65 | if conf.options.debug: |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 66 | extraFlags = conf.flags.getDebugFlags(conf) |
| 67 | if conf.areCustomCxxflagsPresent: |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 68 | missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS] |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 69 | if missingFlags: |
| 70 | Logs.warn('Selected debug mode, but CXXFLAGS is set to a custom value "%s"' |
| 71 | % ' '.join(conf.env.CXXFLAGS)) |
| 72 | Logs.warn('Default flags "%s" will not be used' % ' '.join(missingFlags)) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 73 | else: |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 74 | extraFlags = conf.flags.getOptimizedFlags(conf) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 76 | if not conf.areCustomCxxflagsPresent: |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 77 | conf.add_supported_cxxflags(extraFlags['CXXFLAGS']) |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 78 | conf.add_supported_linkflags(extraFlags['LINKFLAGS']) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 79 | |
| 80 | conf.env.DEFINES += extraFlags['DEFINES'] |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 81 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 82 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 83 | @Configure.conf |
| 84 | def add_supported_cxxflags(self, cxxflags): |
| 85 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 86 | Check which cxxflags are supported by the active compiler and add them to env.CXXFLAGS variable. |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 87 | """ |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 88 | if len(cxxflags) == 0: |
| 89 | return |
| 90 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 91 | self.start_msg('Checking supported CXXFLAGS') |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 92 | |
| 93 | supportedFlags = [] |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 94 | for flags in cxxflags: |
| 95 | flags = Utils.to_list(flags) |
| 96 | if self.check_cxx(cxxflags=['-Werror'] + flags, mandatory=False): |
| 97 | supportedFlags += flags |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 99 | self.end_msg(' '.join(supportedFlags)) |
Davide Pesavento | 1349d2d | 2016-08-09 06:43:57 +0200 | [diff] [blame] | 100 | self.env.prepend_value('CXXFLAGS', supportedFlags) |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 101 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 102 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 103 | @Configure.conf |
| 104 | def add_supported_linkflags(self, linkflags): |
| 105 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 106 | Check which linkflags are supported by the active compiler and add them to env.LINKFLAGS variable. |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 107 | """ |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 108 | if len(linkflags) == 0: |
| 109 | return |
| 110 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 111 | self.start_msg('Checking supported LINKFLAGS') |
| 112 | |
| 113 | supportedFlags = [] |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 114 | for flags in linkflags: |
| 115 | flags = Utils.to_list(flags) |
| 116 | if self.check_cxx(linkflags=['-Werror'] + flags, mandatory=False): |
| 117 | supportedFlags += flags |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 118 | |
| 119 | self.end_msg(' '.join(supportedFlags)) |
Davide Pesavento | 1349d2d | 2016-08-09 06:43:57 +0200 | [diff] [blame] | 120 | self.env.prepend_value('LINKFLAGS', supportedFlags) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 121 | |
| 122 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 123 | class CompilerFlags: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 124 | def getCompilerVersion(self, conf): |
| 125 | return tuple(int(i) for i in conf.env.CC_VERSION) |
| 126 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 127 | def getGeneralFlags(self, conf): |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 128 | """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed""" |
Davide Pesavento | 682b2af | 2024-02-23 21:25:41 -0500 | [diff] [blame^] | 129 | return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []} |
| 130 | |
| 131 | def getDebugFlags(self, conf): |
| 132 | """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in debug mode""" |
Davide Pesavento | 2f46d65 | 2023-11-09 23:40:01 -0500 | [diff] [blame] | 133 | return { |
| 134 | 'CXXFLAGS': [], |
| 135 | 'LINKFLAGS': [], |
| 136 | 'DEFINES': ['BOOST_ASIO_NO_DEPRECATED', 'BOOST_FILESYSTEM_NO_DEPRECATED'], |
| 137 | } |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 138 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 139 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 140 | """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode""" |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 141 | return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']} |
| 142 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 143 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 144 | class GccClangCommonFlags(CompilerFlags): |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 145 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 146 | This class defines common flags that work for both gcc and clang compilers. |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 147 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 148 | |
Davide Pesavento | 724d65a | 2017-06-23 17:14:08 -0400 | [diff] [blame] | 149 | def getGeneralFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 150 | flags = super().getGeneralFlags(conf) |
Davide Pesavento | fcd3e44 | 2023-03-10 18:44:11 -0500 | [diff] [blame] | 151 | flags['CXXFLAGS'] += ['-std=c++17'] |
Davide Pesavento | ea5ce49 | 2022-09-30 20:25:25 -0400 | [diff] [blame] | 152 | if Utils.unversioned_sys_platform() != 'darwin': |
Davide Pesavento | 64ae55d | 2018-12-19 00:25:47 -0500 | [diff] [blame] | 153 | flags['LINKFLAGS'] += ['-fuse-ld=lld'] |
Davide Pesavento | 724d65a | 2017-06-23 17:14:08 -0400 | [diff] [blame] | 154 | return flags |
| 155 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 156 | __cxxFlags = [ |
| 157 | '-fdiagnostics-color', |
| 158 | '-Wall', |
| 159 | '-Wextra', |
| 160 | '-Wpedantic', |
| 161 | '-Wenum-conversion', |
| 162 | '-Wextra-semi', |
| 163 | '-Wnon-virtual-dtor', |
| 164 | '-Wno-unused-parameter', |
| 165 | ] |
| 166 | __linkFlags = ['-Wl,-O1'] |
| 167 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 168 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 169 | flags = super().getDebugFlags(conf) |
| 170 | flags['CXXFLAGS'] += ['-Og', '-g'] + self.__cxxFlags + [ |
| 171 | '-Werror', |
| 172 | '-Wno-error=deprecated-declarations', # Bug #3795 |
| 173 | '-Wno-error=maybe-uninitialized', # Bug #1615 |
| 174 | ] |
| 175 | flags['LINKFLAGS'] += self.__linkFlags |
Davide Pesavento | 5fdab13 | 2024-01-14 16:30:06 -0500 | [diff] [blame] | 176 | # Enable assertions in libstdc++ |
| 177 | # https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html |
| 178 | flags['DEFINES'] += ['_GLIBCXX_ASSERTIONS=1'] |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 179 | return flags |
| 180 | |
| 181 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 182 | flags = super().getOptimizedFlags(conf) |
| 183 | flags['CXXFLAGS'] += ['-O2', '-g1'] + self.__cxxFlags |
| 184 | flags['LINKFLAGS'] += self.__linkFlags |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 185 | return flags |
| 186 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 187 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 188 | class GccFlags(GccClangCommonFlags): |
| 189 | __cxxFlags = [ |
| 190 | '-Wcatch-value=2', |
| 191 | '-Wcomma-subscript', # enabled by default in C++20 |
| 192 | '-Wduplicated-branches', |
| 193 | '-Wduplicated-cond', |
| 194 | '-Wlogical-op', |
| 195 | '-Wredundant-tags', |
| 196 | '-Wvolatile', # enabled by default in C++20 |
| 197 | ] |
| 198 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 199 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 200 | flags = super().getDebugFlags(conf) |
| 201 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 202 | if platform.machine() == 'armv7l': |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 203 | flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106 |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 204 | return flags |
| 205 | |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 206 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 207 | flags = super().getOptimizedFlags(conf) |
| 208 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 209 | if platform.machine() == 'armv7l': |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 210 | flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106 |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 211 | return flags |
| 212 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 213 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 214 | class ClangFlags(GccClangCommonFlags): |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 215 | def getGeneralFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 216 | flags = super().getGeneralFlags(conf) |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 217 | if Utils.unversioned_sys_platform() == 'darwin': |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 218 | # Bug #4296 |
Davide Pesavento | f662500 | 2022-07-31 17:15:02 -0400 | [diff] [blame] | 219 | brewdir = '/opt/homebrew' if platform.machine() == 'arm64' else '/usr/local' |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 220 | flags['CXXFLAGS'] += [ |
| 221 | ['-isystem', f'{brewdir}/include'], # for Homebrew |
| 222 | ['-isystem', '/opt/local/include'], # for MacPorts |
| 223 | ] |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 224 | elif Utils.unversioned_sys_platform() == 'freebsd': |
| 225 | # Bug #4790 |
| 226 | flags['CXXFLAGS'] += [['-isystem', '/usr/local/include']] |
Davide Pesavento | ecfb217 | 2024-01-13 18:26:18 -0500 | [diff] [blame] | 227 | if self.getCompilerVersion(conf) >= (18, 0, 0): |
| 228 | # Bug #5300 |
| 229 | flags['CXXFLAGS'] += ['-Wno-enum-constexpr-conversion'] |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 230 | return flags |
| 231 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 232 | __cxxFlags = [ |
| 233 | '-Wundefined-func-template', |
| 234 | '-Wno-unused-local-typedef', # Bugs #2657 and #3209 |
| 235 | ] |
| 236 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 237 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 238 | flags = super().getDebugFlags(conf) |
| 239 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 5fdab13 | 2024-01-14 16:30:06 -0500 | [diff] [blame] | 240 | # Enable assertions in libc++ |
| 241 | if self.getCompilerVersion(conf) >= (18, 0, 0): |
| 242 | # https://libcxx.llvm.org/Hardening.html |
| 243 | flags['DEFINES'] += ['_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE'] |
| 244 | elif self.getCompilerVersion(conf) >= (15, 0, 0): |
| 245 | # https://releases.llvm.org/15.0.0/projects/libcxx/docs/UsingLibcxx.html#enabling-the-safe-libc-mode |
| 246 | flags['DEFINES'] += ['_LIBCPP_ENABLE_ASSERTIONS=1'] |
Davide Pesavento | 682b2af | 2024-02-23 21:25:41 -0500 | [diff] [blame^] | 247 | # Tell libc++ to avoid including transitive headers |
| 248 | # https://libcxx.llvm.org/DesignDocs/HeaderRemovalPolicy.html |
| 249 | flags['DEFINES'] += ['_LIBCPP_REMOVE_TRANSITIVE_INCLUDES=1'] |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 250 | return flags |
| 251 | |
| 252 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 253 | flags = super().getOptimizedFlags(conf) |
| 254 | flags['CXXFLAGS'] += self.__cxxFlags |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 255 | return flags |