Add option to enable gcc precompiled header for compiling python bindings
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed, 17 Mar 2010 12:34:52 +0000
changeset 6137 86045031f03a
parent 6136 5f8e7096f34a
child 6138 2fe76502b0ce
Add option to enable gcc precompiled header for compiling python bindings
bindings/python/ns3modulegen.py
bindings/python/pch/_placeholder_
bindings/python/wscript
--- a/bindings/python/ns3modulegen.py	Wed Mar 17 11:20:17 2010 +0000
+++ b/bindings/python/ns3modulegen.py	Wed Mar 17 12:34:52 2010 +0000
@@ -54,7 +54,7 @@
         self.main_file_name = main_file_name
         self.main_sink = FileCodeSink(open(main_file_name, "wt"))
         self.header_name = "ns3module.h"
-        header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
+        header_file_name = os.path.join(os.path.dirname(self.main_file_name), 'pch', self.header_name)
         self.header_sink = FileCodeSink(open(header_file_name, "wt"))
         self.section_sinks = {'__main__': self.main_sink}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bindings/python/pch/_placeholder_	Wed Mar 17 12:34:52 2010 +0000
@@ -0,0 +1,1 @@
+placeholder
--- a/bindings/python/wscript	Wed Mar 17 11:20:17 2010 +0000
+++ b/bindings/python/wscript	Wed Mar 17 12:34:52 2010 +0000
@@ -19,6 +19,26 @@
 REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
 
 
+
+from TaskGen import feature, after
+import Task, ccroot
+
+@feature('pch')
+@after('apply_link')
+def process_pch(self):
+    node = self.path.find_resource(self.pch)
+    assert node
+    tsk = self.create_task('gchx')
+    tsk.set_inputs(node)
+    tsk.set_outputs(node.parent.find_or_declare(node.name + '.gch'))
+
+comp_line = '${CXX} ${CXXFLAGS} ${CPPFLAGS} ${_CXXINCFLAGS} ${_CXXDEFFLAGS} ${SRC} -o ${TGT}'
+cls = Task.simple_task_type('gchx', comp_line, before='cc cxx')
+cls.scan = ccroot.scan
+
+
+
+
 def add_to_python_path(path):
     if os.environ.get('PYTHONPATH', ''):
         os.environ['PYTHONPATH'] = path + os.pathsep + os.environ.get('PYTHONPATH')
@@ -44,9 +64,14 @@
                    help=('Path to an existing pybindgen source tree to use.'),
                    default=None,
                    dest='with_pybindgen', type="string")
+    opt.add_option('--enable-python-pch',
+                   help=("Enable precompiled headers when compiling python bindings, to speed up compilation."),
+                   action="store_true", default=False,
+                   dest='enable_python_pch')
 
 
 def configure(conf):
+    conf.env['ENABLE_PYTHON_PCH'] = Options.options.enable_python_pch
     conf.env['ENABLE_PYTHON_BINDINGS'] = False
     if Options.options.python_disable:
         conf.report_optional_feature("python", "Python Bindings", False,
@@ -246,7 +271,7 @@
 
 
 class gen_everything_h_task(Task.Task):
-    before = 'cc cxx'
+    before = 'cc cxx gchx'
     after = 'ns3header_task'
     color = 'BLUE'
 
@@ -384,7 +409,7 @@
     """Uses gccxml to scan the file 'everything.h' and extract API definitions.
     """
     after = 'gen_everything_h_task'
-    before = 'cc cxx'
+    before = 'cc cxx gchx'
     color = "BLUE"
     def __init__(self, curdirnode, env, bld, target, cflags):
         self.bld = bld
@@ -495,7 +520,7 @@
             ]
         target = [
             'ns3module.cc',
-            'ns3module.h',
+            'pch/ns3module.h',
             ]
         if not debug:
             target.append('ns3modulegen.log')
@@ -526,15 +551,18 @@
         bindgen = bld.new_task_gen('command', source=source, target=target, command=argv)
         bindgen.env['FEATURES'] = ','.join(features)
         bindgen.dep_vars = ['FEATURES']
-        bindgen.before = 'cxx'
+        bindgen.before = 'cxx gchx'
         bindgen.after = 'gen_everything_h_task'
         bindgen.name = "pybindgen-command"
-
-        pymod = bld.new_task_gen('cxx', 'shlib', 'pyext')
-        if sys.platform == 'cygwin':
-            pymod.features.append('implib') # workaround for WAF bug #472
+ 
+        features = 'cxx cshlib pyext'
+        if env['ENABLE_PYTHON_PCH']:
+            features += ' pch'
+        pymod = bld.new_task_gen(features=features)
         pymod.source = ['ns3module.cc', 'ns3module_helpers.cc']
-        pymod.includes = '.'
+        pymod.includes = '. pch'
+        if env['ENABLE_PYTHON_PCH']:
+            pymod.pch = 'pch/ns3module.h'
         for module in scanned_modules:
             pymod.source.append("ns3_module_%s.cc" % module)
         pymod.target = 'ns3/_ns3'