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