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