33import platform
44from waflib import Configure ,Logs ,Utils
55
6+
67def options (opt ):
78opt .add_option ('--debug' ,'--with-debug' ,action = 'store_true' ,default = False ,
89help = 'Compile in debugging mode with minimal optimizations (-Og)' )
910
11+
1012def configure (conf ):
1113conf .start_msg ('Checking C++ compiler version' )
1214
@@ -48,14 +50,15 @@ def configure(conf):
4850else :
4951conf .end_msg (ccverstr )
5052
51- conf .areCustomCxxflagsPresent = ( len (conf .env .CXXFLAGS )> 0 )
53+ conf .areCustomCxxflagsPresent = len (conf .env .CXXFLAGS )> 0
5254
5355# General flags are always applied (e.g., selecting C++ language standard)
5456generalFlags = conf .flags .getGeneralFlags (conf )
5557conf .add_supported_cxxflags (generalFlags ['CXXFLAGS' ])
5658conf .add_supported_linkflags (generalFlags ['LINKFLAGS' ])
5759conf .env .DEFINES += generalFlags ['DEFINES' ]
5860
61+
5962@Configure .conf
6063def check_compiler_flags (conf ):
6164# Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
@@ -78,10 +81,11 @@ def check_compiler_flags(conf):
7881
7982conf .env .DEFINES += extraFlags ['DEFINES' ]
8083
84+
8185@Configure .conf
8286def add_supported_cxxflags (self ,cxxflags ):
8387"""
84- Check which cxxflags are supported by compiler and add them to env.CXXFLAGS variable
88+ Check which cxxflags are supported bythe active compiler and add them to env.CXXFLAGS variable.
8589 """
8690if len (cxxflags )== 0 :
8791return
@@ -97,10 +101,11 @@ def add_supported_cxxflags(self, cxxflags):
97101self .end_msg (' ' .join (supportedFlags ))
98102self .env .prepend_value ('CXXFLAGS' ,supportedFlags )
99103
104+
100105@Configure .conf
101106def add_supported_linkflags (self ,linkflags ):
102107"""
103- Check which linkflags are supported by compiler and add them to env.LINKFLAGS variable
108+ Check which linkflags are supported bythe active compiler and add them to env.LINKFLAGS variable.
104109 """
105110if len (linkflags )== 0 :
106111return
@@ -117,7 +122,7 @@ def add_supported_linkflags(self, linkflags):
117122self .env .prepend_value ('LINKFLAGS' ,supportedFlags )
118123
119124
120- class CompilerFlags ( object ) :
125+ class CompilerFlags :
121126def getCompilerVersion (self ,conf ):
122127return tuple (int (i )for i in conf .env .CC_VERSION )
123128
@@ -133,94 +138,100 @@ def getOptimizedFlags(self, conf):
133138"""Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are needed only in optimized mode"""
134139return {'CXXFLAGS' : [],'LINKFLAGS' : [],'DEFINES' : ['NDEBUG' ]}
135140
136- class GccBasicFlags (CompilerFlags ):
141+
142+ class GccClangCommonFlags (CompilerFlags ):
137143"""
138- This class definesbasic flags that work for both gcc and clang compilers
144+ This class definescommon flags that work for both gcc and clang compilers.
139145 """
146+
140147def getGeneralFlags (self ,conf ):
141- flags = super (GccBasicFlags , self ).getGeneralFlags (conf )
148+ flags = super ().getGeneralFlags (conf )
142149flags ['CXXFLAGS' ]+= ['-std=c++17' ]
143150if Utils .unversioned_sys_platform ()!= 'darwin' :
144151flags ['LINKFLAGS' ]+= ['-fuse-ld=lld' ]
145152return flags
146153
154+ __cxxFlags = [
155+ '-fdiagnostics-color' ,
156+ '-Wall' ,
157+ '-Wextra' ,
158+ '-Wpedantic' ,
159+ '-Wenum-conversion' ,
160+ '-Wextra-semi' ,
161+ '-Wnon-virtual-dtor' ,
162+ '-Wno-unused-parameter' ,
163+ ]
164+ __linkFlags = ['-Wl,-O1' ]
165+
147166def getDebugFlags (self ,conf ):
148- flags = super (GccBasicFlags ,self ).getDebugFlags (conf )
149- flags ['CXXFLAGS' ]+= ['-Og' ,
150- '-g3' ,
151- '-Wall' ,
152- '-Wextra' ,
153- '-Wpedantic' ,
154- '-Werror' ,
155- '-Wcatch-value=2' ,
156- '-Wextra-semi' ,
157- '-Wnon-virtual-dtor' ,
158- '-Wno-error=deprecated-declarations' ,# Bug #3795
159- '-Wno-error=maybe-uninitialized' ,# Bug #1615
160- '-Wno-unused-parameter' ,
161- ]
162- flags ['LINKFLAGS' ]+= ['-Wl,-O1' ]
167+ flags = super ().getDebugFlags (conf )
168+ flags ['CXXFLAGS' ]+= ['-Og' ,'-g' ]+ self .__cxxFlags + [
169+ '-Werror' ,
170+ '-Wno-error=deprecated-declarations' ,# Bug #3795
171+ '-Wno-error=maybe-uninitialized' ,# Bug #1615
172+ ]
173+ flags ['LINKFLAGS' ]+= self .__linkFlags
163174return flags
164175
165176def getOptimizedFlags (self ,conf ):
166- flags = super (GccBasicFlags ,self ).getOptimizedFlags (conf )
167- flags ['CXXFLAGS' ]+= ['-O2' ,
168- '-g' ,
169- '-Wall' ,
170- '-Wextra' ,
171- '-Wpedantic' ,
172- '-Wcatch-value=2' ,
173- '-Wextra-semi' ,
174- '-Wnon-virtual-dtor' ,
175- '-Wno-unused-parameter' ,
176- ]
177- flags ['LINKFLAGS' ]+= ['-Wl,-O1' ]
177+ flags = super ().getOptimizedFlags (conf )
178+ flags ['CXXFLAGS' ]+= ['-O2' ,'-g1' ]+ self .__cxxFlags
179+ flags ['LINKFLAGS' ]+= self .__linkFlags
178180return flags
179181
180- class GccFlags (GccBasicFlags ):
182+
183+ class GccFlags (GccClangCommonFlags ):
184+ __cxxFlags = [
185+ '-Wcatch-value=2' ,
186+ '-Wcomma-subscript' ,# enabled by default in C++20
187+ '-Wduplicated-branches' ,
188+ '-Wduplicated-cond' ,
189+ '-Wlogical-op' ,
190+ '-Wredundant-tags' ,
191+ '-Wvolatile' ,# enabled by default in C++20
192+ ]
193+
181194def getDebugFlags (self ,conf ):
182- flags = super (GccFlags ,self ).getDebugFlags (conf )
183- flags ['CXXFLAGS' ]+= ['-fdiagnostics-color' ,
184- '-Wredundant-tags' ,
185- ]
195+ flags = super ().getDebugFlags (conf )
196+ flags ['CXXFLAGS' ]+= self .__cxxFlags
186197if platform .machine ()== 'armv7l' :
187198flags ['CXXFLAGS' ]+= ['-Wno-psabi' ]# Bug #5106
188199return flags
189200
190201def getOptimizedFlags (self ,conf ):
191- flags = super (GccFlags ,self ).getOptimizedFlags (conf )
192- flags ['CXXFLAGS' ]+= ['-fdiagnostics-color' ,
193- '-Wredundant-tags' ,
194- ]
202+ flags = super ().getOptimizedFlags (conf )
203+ flags ['CXXFLAGS' ]+= self .__cxxFlags
195204if platform .machine ()== 'armv7l' :
196205flags ['CXXFLAGS' ]+= ['-Wno-psabi' ]# Bug #5106
197206return flags
198207
199- class ClangFlags (GccBasicFlags ):
208+
209+ class ClangFlags (GccClangCommonFlags ):
200210def getGeneralFlags (self ,conf ):
201- flags = super (ClangFlags , self ).getGeneralFlags (conf )
211+ flags = super ().getGeneralFlags (conf )
202212if Utils .unversioned_sys_platform ()== 'darwin' :
203213# Bug #4296
204214brewdir = '/opt/homebrew' if platform .machine ()== 'arm64' else '/usr/local'
205- flags ['CXXFLAGS' ]+= [['-isystem' ,f'{ brewdir } /include' ],# for Homebrew
206- ['-isystem' ,'/opt/local/include' ]]# for MacPorts
215+ flags ['CXXFLAGS' ]+= [
216+ ['-isystem' ,f'{ brewdir } /include' ],# for Homebrew
217+ ['-isystem' ,'/opt/local/include' ],# for MacPorts
218+ ]
207219elif Utils .unversioned_sys_platform ()== 'freebsd' :
208220# Bug #4790
209221flags ['CXXFLAGS' ]+= [['-isystem' ,'/usr/local/include' ]]
210222return flags
211223
224+ __cxxFlags = [
225+ '-Wundefined-func-template' ,
226+ '-Wno-unused-local-typedef' ,# Bugs #2657 and #3209
227+ ]
228+
212229def getDebugFlags (self ,conf ):
213- flags = super (ClangFlags ,self ).getDebugFlags (conf )
214- flags ['CXXFLAGS' ]+= ['-fcolor-diagnostics' ,
215- '-Wundefined-func-template' ,
216- '-Wno-unused-local-typedef' ,# Bugs #2657 and #3209
217- ]
230+ flags = super ().getDebugFlags (conf )
231+ flags ['CXXFLAGS' ]+= self .__cxxFlags
218232return flags
219233
220234def getOptimizedFlags (self ,conf ):
221- flags = super (ClangFlags ,self ).getOptimizedFlags (conf )
222- flags ['CXXFLAGS' ]+= ['-fcolor-diagnostics' ,
223- '-Wundefined-func-template' ,
224- '-Wno-unused-local-typedef' ,# Bugs #2657 and #3209
225- ]
235+ flags = super ().getOptimizedFlags (conf )
236+ flags ['CXXFLAGS' ]+= self .__cxxFlags
226237return flags