Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3bd747

Browse files
committed
Thomas Heller: added --swig-cpp option and fixed silly typos in SWIG support.
Also supposedly made some change to where .lib files wind up under MSVC++, but I don't understand how to code is doing what Thomas says it's doing.
1 parent 27199e8 commit f3bd747

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

Lib/distutils/command/build_ext.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class build_ext (Command):
7777
"forcibly build everything (ignore file timestamps)"),
7878
('compiler=', 'c',
7979
"specify the compiler type"),
80+
('swig-cpp', None,
81+
"make SWIG create C++ files (default is C)"),
8082
]
8183

8284
help_options = [
@@ -101,6 +103,7 @@ def initialize_options (self):
101103
self.debug = None
102104
self.force = None
103105
self.compiler = None
106+
self.swig_cpp = None
104107

105108

106109
def finalize_options (self):
@@ -443,15 +446,20 @@ def swig_sources (self, sources):
443446
swig_sources = []
444447
swig_targets = {}
445448

446-
# XXX this drops generated C files into the source tree, which
449+
# XXX this drops generated C/C++ files into the source tree, which
447450
# is fine for developers who want to distribute the generated
448451
# source -- but there should be an option to put SWIG output in
449452
# the temp dir.
450453

454+
if self.swig_cpp:
455+
target_ext = '.cpp'
456+
else:
457+
target_ext = '.c'
458+
451459
for source in sources:
452460
(base, ext) = os.path.splitext(source)
453461
if ext == ".i": # SWIG interface file
454-
new_sources.append(base + ".c") # umm, what if it's C++?
462+
new_sources.append(base + target_ext)
455463
swig_sources.append(source)
456464
swig_targets[source] = new_sources[-1]
457465
else:
@@ -461,11 +469,14 @@ def swig_sources (self, sources):
461469
return new_sources
462470

463471
swig = self.find_swig()
464-
swig_cmd = [swig, "-python", "-dnone", "-ISWIG"] # again, C++?!?
472+
swig_cmd = [swig, "-python", "-dnone", "-ISWIG"]
473+
if self.swig_cpp:
474+
swig_cmd.append ("-c++")
465475

466476
for source in swig_sources:
467-
self.announce ("swigging %s to %s" % (src, obj))
468-
self.spawn(swig_cmd + ["-o", swig_targets[source], source])
477+
target = swig_targets[source]
478+
self.announce ("swigging %s to %s" % (source, target))
479+
self.spawn(swig_cmd + ["-o", target, source])
469480

470481
return new_sources
471482

@@ -528,10 +539,11 @@ def msvc_prelink_hack (self, sources, ext, extra_args):
528539
modname = string.split (ext.name, '.')[-1]
529540
extra_args.append('/export:init%s' % modname)
530541

531-
# The MSVC linker generates unneeded .lib and .exp files,
532-
# which cannot be suppressed by any linker switches. So
533-
# make sure they are generated in the temporary build
534-
# directory.
542+
# The MSVC linker generates .lib and .exp files, which cannot be
543+
# suppressed by any linker switches. The .lib files may even be
544+
# needed! Make sure they are generated in the temporary build
545+
# directory. Since they have different names for debug and release
546+
# builds, they can go into the same directory.
535547
implib_file = os.path.join (
536548
self.build_temp,
537549
self.get_ext_libname (ext.name))

0 commit comments

Comments
 (0)