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 | e913e3a | 2024-12-10 20:25:04 -0500 | [diff] [blame] | 19 | if ccver < (9, 1, 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 | e913e3a | 2024-12-10 20:25:04 -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 | 762548b | 2023-03-05 11:02:02 -0500 | [diff] [blame] | 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': |
Davide Pesavento | e913e3a | 2024-12-10 20:25:04 -0500 | [diff] [blame] | 28 | if ccver < (11, 0, 0): |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 29 | errmsg = ('The version of Xcode you are using is too old.\n' |
Davide Pesavento | 2be774b | 2024-06-07 17:25:31 -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 | 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 | e913e3a | 2024-12-10 20:25:04 -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 | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 40 | conf.flags = ClangFlags() |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 41 | else: |
Davide Pesavento | f662500 | 2022-07-31 17:15:02 -0400 | [diff] [blame] | 42 | warnmsg = f'{cxx} compiler is unsupported' |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 43 | conf.flags = CompilerFlags() |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 44 | |
| 45 | if errmsg: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 46 | conf.end_msg(ccverstr, color='RED') |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 47 | conf.fatal(errmsg) |
| 48 | elif warnmsg: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 49 | conf.end_msg(ccverstr, color='YELLOW') |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 50 | Logs.warn('WARNING: ' + warnmsg) |
Davide Pesavento | 88a0d81 | 2017-08-19 21:31:42 -0400 | [diff] [blame] | 51 | else: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 52 | conf.end_msg(ccverstr) |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 53 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 54 | conf.areCustomCxxflagsPresent = len(conf.env.CXXFLAGS) > 0 |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 55 | |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 56 | # General flags are always applied (e.g., selecting C++ language standard) |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 57 | generalFlags = conf.flags.getGeneralFlags(conf) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -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 | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 62 | |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 63 | @Configure.conf |
| 64 | def check_compiler_flags(conf): |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 65 | # Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 66 | # corresponding environment variables are not set. |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 67 | # DEFINES are always applied. |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 68 | if conf.options.debug: |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 69 | extraFlags = conf.flags.getDebugFlags(conf) |
| 70 | if conf.areCustomCxxflagsPresent: |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 71 | 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] | 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 | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 76 | else: |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 77 | extraFlags = conf.flags.getOptimizedFlags(conf) |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 78 | |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -0400 | [diff] [blame] | 79 | if not conf.areCustomCxxflagsPresent: |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 80 | conf.add_supported_cxxflags(extraFlags['CXXFLAGS']) |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 81 | conf.add_supported_linkflags(extraFlags['LINKFLAGS']) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 82 | |
| 83 | conf.env.DEFINES += extraFlags['DEFINES'] |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 84 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 85 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 86 | @Configure.conf |
| 87 | def add_supported_cxxflags(self, cxxflags): |
| 88 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 89 | 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] | 90 | """ |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 91 | if len(cxxflags) == 0: |
| 92 | return |
| 93 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 94 | self.start_msg('Checking supported CXXFLAGS') |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 95 | |
| 96 | supportedFlags = [] |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -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 | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 101 | |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 102 | self.end_msg(' '.join(supportedFlags)) |
Davide Pesavento | 1349d2d | 2016-08-09 06:43:57 +0200 | [diff] [blame] | 103 | self.env.prepend_value('CXXFLAGS', supportedFlags) |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 104 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 105 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 106 | @Configure.conf |
| 107 | def add_supported_linkflags(self, linkflags): |
| 108 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 109 | 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] | 110 | """ |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 111 | if len(linkflags) == 0: |
| 112 | return |
| 113 | |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 114 | self.start_msg('Checking supported LINKFLAGS') |
| 115 | |
| 116 | supportedFlags = [] |
Alexander Afanasyev | b82d8c3 | 2017-09-21 11:35:07 -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 |
Davide Pesavento | dfe9c6b | 2014-08-25 21:17:10 +0200 | [diff] [blame] | 121 | |
| 122 | self.end_msg(' '.join(supportedFlags)) |
Davide Pesavento | 1349d2d | 2016-08-09 06:43:57 +0200 | [diff] [blame] | 123 | self.env.prepend_value('LINKFLAGS', supportedFlags) |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 124 | |
| 125 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 126 | class CompilerFlags: |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 127 | def getCompilerVersion(self, conf): |
| 128 | return tuple(int(i) for i in conf.env.CC_VERSION) |
| 129 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 130 | def getGeneralFlags(self, conf): |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 131 | """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed""" |
Davide Pesavento | 682b2af | 2024-02-23 21:25:41 -0500 | [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 | 2f46d65 | 2023-11-09 23:40:01 -0500 | [diff] [blame] | 136 | return { |
| 137 | 'CXXFLAGS': [], |
| 138 | 'LINKFLAGS': [], |
Davide Pesavento | 51974f6 | 2024-12-21 20:42:45 -0500 | [diff] [blame^] | 139 | 'DEFINES': ['BOOST_ASIO_NO_DEPRECATED'], |
Davide Pesavento | 2f46d65 | 2023-11-09 23:40:01 -0500 | [diff] [blame] | 140 | } |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 142 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 7c02b47 | 2015-10-28 20:50:17 +0100 | [diff] [blame] | 143 | """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] | 144 | return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']} |
| 145 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 146 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 147 | class GccClangCommonFlags(CompilerFlags): |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 148 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 149 | 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] | 150 | """ |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 151 | |
Davide Pesavento | 724d65a | 2017-06-23 17:14:08 -0400 | [diff] [blame] | 152 | def getGeneralFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 153 | flags = super().getGeneralFlags(conf) |
Davide Pesavento | fcd3e44 | 2023-03-10 18:44:11 -0500 | [diff] [blame] | 154 | flags['CXXFLAGS'] += ['-std=c++17'] |
Davide Pesavento | ea5ce49 | 2022-09-30 20:25:25 -0400 | [diff] [blame] | 155 | if Utils.unversioned_sys_platform() != 'darwin': |
Davide Pesavento | 64ae55d | 2018-12-19 00:25:47 -0500 | [diff] [blame] | 156 | flags['LINKFLAGS'] += ['-fuse-ld=lld'] |
Davide Pesavento | 724d65a | 2017-06-23 17:14:08 -0400 | [diff] [blame] | 157 | return flags |
| 158 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -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 | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 171 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -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 | 5fdab13 | 2024-01-14 16:30:06 -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 | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 182 | return flags |
| 183 | |
| 184 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 185 | flags = super().getOptimizedFlags(conf) |
| 186 | flags['CXXFLAGS'] += ['-O2', '-g1'] + self.__cxxFlags |
| 187 | flags['LINKFLAGS'] += self.__linkFlags |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 188 | return flags |
| 189 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 190 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 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 | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 202 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 203 | flags = super().getDebugFlags(conf) |
| 204 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 205 | if platform.machine() == 'armv7l': |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 206 | flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106 |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 207 | return flags |
| 208 | |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 209 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 210 | flags = super().getOptimizedFlags(conf) |
| 211 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 212 | if platform.machine() == 'armv7l': |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 213 | flags['CXXFLAGS'] += ['-Wno-psabi'] # Bug #5106 |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 214 | return flags |
| 215 | |
Davide Pesavento | 12b8aaa | 2023-08-06 19:18:51 -0400 | [diff] [blame] | 216 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 217 | class ClangFlags(GccClangCommonFlags): |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 218 | def getGeneralFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 219 | flags = super().getGeneralFlags(conf) |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 220 | if Utils.unversioned_sys_platform() == 'darwin': |
Alexander Afanasyev | 5560fd4 | 2018-03-07 17:03:03 -0500 | [diff] [blame] | 221 | # Bug #4296 |
Davide Pesavento | f662500 | 2022-07-31 17:15:02 -0400 | [diff] [blame] | 222 | brewdir = '/opt/homebrew' if platform.machine() == 'arm64' else '/usr/local' |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 223 | flags['CXXFLAGS'] += [ |
| 224 | ['-isystem', f'{brewdir}/include'], # for Homebrew |
| 225 | ['-isystem', '/opt/local/include'], # for MacPorts |
| 226 | ] |
Davide Pesavento | 71c622b | 2020-04-24 01:39:01 -0400 | [diff] [blame] | 227 | elif Utils.unversioned_sys_platform() == 'freebsd': |
| 228 | # Bug #4790 |
| 229 | flags['CXXFLAGS'] += [['-isystem', '/usr/local/include']] |
Davide Pesavento | ecfb217 | 2024-01-13 18:26:18 -0500 | [diff] [blame] | 230 | if self.getCompilerVersion(conf) >= (18, 0, 0): |
| 231 | # Bug #5300 |
| 232 | flags['CXXFLAGS'] += ['-Wno-enum-constexpr-conversion'] |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 233 | return flags |
| 234 | |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 235 | __cxxFlags = [ |
| 236 | '-Wundefined-func-template', |
| 237 | '-Wno-unused-local-typedef', # Bugs #2657 and #3209 |
| 238 | ] |
| 239 | |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 240 | def getDebugFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 241 | flags = super().getDebugFlags(conf) |
| 242 | flags['CXXFLAGS'] += self.__cxxFlags |
Davide Pesavento | 5fdab13 | 2024-01-14 16:30:06 -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 | 682b2af | 2024-02-23 21:25:41 -0500 | [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'] |
Davide Pesavento | d06ea05 | 2015-10-02 01:48:24 +0200 | [diff] [blame] | 253 | return flags |
| 254 | |
| 255 | def getOptimizedFlags(self, conf): |
Davide Pesavento | 03fdfb1 | 2023-08-06 19:35:10 -0400 | [diff] [blame] | 256 | flags = super().getOptimizedFlags(conf) |
| 257 | flags['CXXFLAGS'] += self.__cxxFlags |
Alexander Afanasyev | 0151579 | 2014-12-16 14:20:01 -0800 | [diff] [blame] | 258 | return flags |