@@ -66,6 +66,15 @@ def has_flag(self, flagname):
6666 return True
6767
6868
69+ # Wrapper for distutils.ccompiler.CCompiler._compile to remove C++-specific
70+ # flags when compiling C files.
71+ def compile_wrapper (compiler , obj , src , ext , cc_args , extra_postargs , pp_opts ):
72+ if src .lower ().endswith (".c" ):
73+ extra_postargs = list (filter (lambda x : x [1 :4 ] != "std" ,
74+ extra_postargs ))
75+ compiler ._compile_old (obj , src , ext , cc_args , extra_postargs , pp_opts )
76+
77+
6978class BuildExtraLibraries (setuptools .command .build_ext .build_ext ):
7079 def finalize_options (self ):
7180 self .distribution .ext_modules [:] = [
@@ -184,9 +193,20 @@ def build_extension(self, ext):
184193 orig_build_temp = self .build_temp
185194 self .build_temp = os .path .join (self .build_temp , ext .name )
186195 try :
196+ if ext .name == "matplotlib._qhull" :
197+ # For qhull extension some C++ flags must be removed before
198+ # compiling C files.
199+ from distutils .ccompiler import CCompiler
200+ self .compiler ._compile_old = self .compiler ._compile
201+ self .compiler ._compile = compile_wrapper .__get__ (
202+ self .compiler , CCompiler )
187203 super ().build_extension (ext )
188204 finally :
189205 self .build_temp = orig_build_temp
206+ if ext .name == "matplotlib._qhull" and hasattr (
207+ self .compiler , "_compile_old" ):
208+ self .compiler ._compile = self .compiler ._compile_old
209+ delattr (self .compiler , "_compile_old" )
190210
191211
192212def update_matplotlibrc (path ):
0 commit comments