Skip to content

Commit 2c93711

Browse files
sciyoshijaraco
authored andcommitted
1 parent f60cd62 commit 2c93711

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

distutils/cygwinccompiler.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,19 @@ def __init__(self, verbose=0, dry_run=0, force=0):
101101
self.cxx = os.environ.get('CXX', 'g++')
102102

103103
self.linker_dll = self.cc
104+
self.linker_dll_cxx = self.cxx
104105
shared_option = "-shared"
105106

106107
self.set_executables(
107108
compiler='%s -mcygwin -O -Wall' % self.cc,
108109
compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc,
109110
compiler_cxx='%s -mcygwin -O -Wall' % self.cxx,
111+
compiler_so_cxx='%s -mcygwin -mdll -O -Wall' % self.cxx,
110112
linker_exe='%s -mcygwin' % self.cc,
111113
linker_so=('{} -mcygwin {}'.format(self.linker_dll, shared_option)),
114+
linker_exe_cxx='%s -mcygwin' % self.cxx,
115+
linker_so_cxx=('%s -mcygwin %s' %
116+
(self.linker_dll_cxx, shared_option)),
112117
)
113118

114119
# Include the appropriate MSVC runtime library if Python was built
@@ -140,9 +145,12 @@ def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
140145
raise CompileError(msg)
141146
else: # for other files use the C-compiler
142147
try:
143-
self.spawn(
144-
self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs
145-
)
148+
if self.detect_language(src) == 'c++':
149+
self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
150+
extra_postargs)
151+
else:
152+
self.spawn(
153+
self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
146154
except DistutilsExecError as msg:
147155
raise CompileError(msg)
148156

@@ -278,9 +286,12 @@ def __init__(self, verbose=0, dry_run=0, force=0):
278286
self.set_executables(
279287
compiler='%s -O -Wall' % self.cc,
280288
compiler_so='%s -mdll -O -Wall' % self.cc,
289+
compiler_so_cxx='%s -mdll -O -Wall' % self.cxx,
281290
compiler_cxx='%s -O -Wall' % self.cxx,
282291
linker_exe='%s' % self.cc,
283292
linker_so='{} {}'.format(self.linker_dll, shared_option),
293+
linker_exe_cxx='%s' % self.cxx,
294+
linker_so_cxx='%s %s' % (self.linker_dll_cxx, shared_option)
284295
)
285296

286297
def runtime_library_dir_option(self, dir):

distutils/sysconfig.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def customize_compiler(compiler): # noqa: C901
300300
cflags,
301301
ccshared,
302302
ldshared,
303+
ldcxxshared,
303304
shlib_suffix,
304305
ar,
305306
ar_flags,
@@ -309,11 +310,14 @@ def customize_compiler(compiler): # noqa: C901
309310
'CFLAGS',
310311
'CCSHARED',
311312
'LDSHARED',
313+
'LDCXXSHARED',
312314
'SHLIB_SUFFIX',
313315
'AR',
314316
'ARFLAGS',
315317
)
316318

319+
cxxflags = cflags
320+
317321
if 'CC' in os.environ:
318322
newcc = os.environ['CC']
319323
if 'LDSHARED' not in os.environ and ldshared.startswith(cc):
@@ -325,19 +329,27 @@ def customize_compiler(compiler): # noqa: C901
325329
cxx = os.environ['CXX']
326330
if 'LDSHARED' in os.environ:
327331
ldshared = os.environ['LDSHARED']
332+
if 'LDCXXSHARED' in os.environ:
333+
ldcxxshared = os.environ['LDCXXSHARED']
328334
if 'CPP' in os.environ:
329335
cpp = os.environ['CPP']
330336
else:
331337
cpp = cc + " -E" # not always
332338
if 'LDFLAGS' in os.environ:
333339
ldshared = ldshared + ' ' + os.environ['LDFLAGS']
340+
ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
334341
if 'CFLAGS' in os.environ:
335-
cflags = cflags + ' ' + os.environ['CFLAGS']
342+
cflags = os.environ['CFLAGS']
336343
ldshared = ldshared + ' ' + os.environ['CFLAGS']
344+
if 'CXXFLAGS' in os.environ:
345+
cxxflags = os.environ['CXXFLAGS']
346+
ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
337347
if 'CPPFLAGS' in os.environ:
338348
cpp = cpp + ' ' + os.environ['CPPFLAGS']
339349
cflags = cflags + ' ' + os.environ['CPPFLAGS']
350+
cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
340351
ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
352+
ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
341353
if 'AR' in os.environ:
342354
ar = os.environ['AR']
343355
if 'ARFLAGS' in os.environ:
@@ -346,13 +358,17 @@ def customize_compiler(compiler): # noqa: C901
346358
archiver = ar + ' ' + ar_flags
347359

348360
cc_cmd = cc + ' ' + cflags
361+
cxx_cmd = cxx + ' ' + cxxflags
349362
compiler.set_executables(
350363
preprocessor=cpp,
351364
compiler=cc_cmd,
352365
compiler_so=cc_cmd + ' ' + ccshared,
353-
compiler_cxx=cxx,
366+
compiler_cxx=cxx_cmd,
367+
compiler_so_cxx=cxx_cmd + ' ' + ccshared,
354368
linker_so=ldshared,
369+
linker_so_cxx=ldcxxshared,
355370
linker_exe=cc,
371+
linker_exe_cxx=cxx,
356372
archiver=archiver,
357373
)
358374

distutils/unixccompiler.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ class UnixCCompiler(CCompiler):
115115
'preprocessor': None,
116116
'compiler': ["cc"],
117117
'compiler_so': ["cc"],
118-
'compiler_cxx': ["cc"],
118+
'compiler_cxx': ["c++"],
119+
'compiler_so_cxx': ["c++"],
119120
'linker_so': ["cc", "-shared"],
121+
'linker_so_cxx': ["c++", "-shared"],
120122
'linker_exe': ["cc"],
123+
'linker_exe_cxx': ["c++", "-shared"],
121124
'archiver': ["ar", "-cr"],
122125
'ranlib': None,
123126
}
@@ -181,8 +184,13 @@ def preprocess(
181184

182185
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
183186
compiler_so = compiler_fixup(self.compiler_so, cc_args + extra_postargs)
187+
compiler_so_cxx = compiler_fixup(self.compiler_so_cxx, cc_args + extra_postargs)
184188
try:
185-
self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
189+
if self.detect_language(src) == 'c++':
190+
self.spawn(compiler_so_cxx + cc_args + [ src, '-o', obj] +
191+
extra_postargs)
192+
else:
193+
self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
186194
except DistutilsExecError as msg:
187195
raise CompileError(msg)
188196

@@ -250,7 +258,8 @@ def link(
250258
# building an executable or linker_so (with shared options)
251259
# when building a shared library.
252260
building_exe = target_desc == CCompiler.EXECUTABLE
253-
linker = (self.linker_exe if building_exe else self.linker_so)[:]
261+
linker = (self.linker_exe if building_exe else (self.linker_so_cxx if
262+
target_lang == "c++" else self.linker_so))[:]
254263

255264
if target_lang == "c++" and self.compiler_cxx:
256265
env, linker_ne = _split_env(linker)

0 commit comments

Comments
 (0)