Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / setup.py
index 17d630409258e15a5668f3759ea274d9b75636d6..60558721cb34406f54a1f051e8574468927baeda 100644 (file)
--- a/setup.py
+++ b/setup.py
 from setuptools import setup, Extension
+import distutils.command.build_ext
+from distutils.dep_util import newer
 
 import os
-mussa_ext = Extension("mussa", ["py/conserved_path.cpp",
-                                "py/glsequence.cpp",
-                                "py/module.cpp",
-                                "py/mussa.cpp",
-                                #"py/MussaWindow.cpp",
-                                "py/nway_paths.cpp",
-                                "py/sequence.cpp",
-                                "alg/annotation_colors.cpp",
-                                "alg/color.cpp",
-                                "alg/conserved_path.cpp",
-                                "alg/flp.cpp",
-                                "alg/flp_seqcomp.cpp",
-                                "alg/glseqbrowser.cpp",
-                                "alg/glsequence.cpp",
-                                "alg/mussa.cpp",
-                                "alg/nway_entropy.cpp",
-                                "alg/nway_other.cpp",
-                                "alg/nway_paths.cpp",
-                                #"alg/nway_refine",
-                                #"alg/parse_options.cpp",
-                                "alg/sequence.cpp"],
-                      include_dirs=['/usr/include/boost',
-                                    '.'
-                                   #os.getcwd()
-                                   ],
-                      libraries=['boost_python', 
-                                 'boost_filesystem',
-                                 'GL',
-                                 ])
-
-setup(name='mussa',
+import sys
+
+def replace_suffix(path, new_suffix):
+  return os.path.splitext(path)[0]+new_suffix
+
+class build_ext(distutils.command.build_ext.build_ext):
+  description="also compile qt moc files"
+
+  def __init__(self, *args, **kwargs):
+    if sys.platform == 'linux2':
+      self.moc_binary = 'moc'
+      self.rcc_binary = 'rcc'
+
+      if os.path.exists('/usr/bin/moc-qt4'):
+        self.moc_binary = '/usr/bin/moc-qt4'
+      if os.path.exists('/usr/bin/rcc-qt4'):  
+        self.rcc_binary = '/usr/bin/rcc-qt4'
+
+    distutils.command.build_ext.build_ext.__init__(self, *args, **kwargs)
+
+  def swig_sources(self, sources, extensions=None):
+    if self.extensions is None:
+      return
+  
+    # filter out sources
+    qrc_sources = []
+    moc_sources = []
+    other_sources = []
+    for src in sources:
+      base,ext= os.path.splitext(src)
+      if ext == '.qrc':
+        qrc_sources.append(src)
+      elif ext in ('.hpp', '.hxx', '.h'):
+        moc_sources.append(src)
+      else:
+        other_sources.append(src)
+
+    build_sources = other_sources
+    # create qresource
+    build_sources.extend(self.compile_qrcs(qrc_sources))
+    # create moc files 
+    build_sources.extend(self.compile_mocs(moc_sources))
+    return build_sources 
+
+  def compile_qrcs(self, qrc_files):
+    targets = []
+    for qrc in qrc_files:
+      if os.path.exists(qrc):
+        source = qrc
+        name = os.path.splitext(os.path.split(qrc)[1])[0]
+        target = "qrc_"+name+".cpp"
+        if newer(source, target) or self.force:
+          self.compile_qrc(name, source, target)
+        targets.append(target)
+    return targets
+
+  def compile_qrc(self, name, source, target):
+    """compile qt resource file"""
+    os.system("%s -name %s -o %s %s" %(self.rcc_binary, name, target, source))
+
+  def compile_mocs(self, moc_headers):
+    targets = []
+   
+    for moc_hpp in moc_headers:
+      if os.path.exists(moc_hpp):
+        source = moc_hpp
+        target = "moc_"+replace_suffix(os.path.split(moc_hpp)[1],'.cpp')
+        if newer(source, target) or self.force:
+          self.compile_moc(source, target)
+        targets.append(target)
+    return targets
+  
+  def compile_moc(self, source, target):
+    os.system("%s -o%s %s" %(self.moc_binary, target, source))
+
+boost_py = ["py/conserved_path.cpp",
+           "py/glsequence.cpp",
+           "py/module.cpp",
+           "py/mussa.cpp",
+           "py/MussaWindow.cpp",
+           "py/nway_paths.cpp",
+           "py/sequence.cpp",]
+
+core_alg = ["alg/annotation_colors.cpp",
+            "alg/color.cpp",
+            "alg/conserved_path.cpp",
+            "alg/flp.cpp",
+            "alg/flp_seqcomp.cpp",
+            "alg/glseqbrowser.cpp",
+            "alg/glsequence.cpp",
+            "alg/mussa.cpp",
+            "alg/nway_entropy.cpp",
+            "alg/nway_other.cpp",
+            "alg/nway_paths.cpp",
+            #"alg/nway_refine",
+            #"alg/parse_options.cpp",
+            "alg/sequence.cpp",]
+
+moc_headers = ['qui/ImageSaveDialog.hpp',
+               'qui/ImageScaler.hpp',
+               'qui/IntAction.hpp',
+               'qui/MussaAlignedWindow.hpp',
+               'qui/MussaWindow.hpp',
+               'qui/ThresholdWidget.hpp',
+               'qui/ZoomWidget.hpp',
+               'qui/motif_editor/MotifDetail.hpp',
+               'qui/motif_editor/MotifEditor.hpp',
+               'qui/mussa_setup_dialog/IsFileValidator.hpp',
+               'qui/mussa_setup_dialog/MussaSetupDialog.hpp',
+               'qui/mussa_setup_dialog/MussaSetupWidget.hpp',
+               'qui/mussa_setup_dialog/SequenceSetupFrame.hpp',
+               'qui/mussa_setup_dialog/SequenceSetupWidget.hpp',
+               'qui/mussa_setup_dialog/SetupInfo.hpp',
+               'qui/seqbrowser/ScrollableSequenceBrowser.hpp',
+               'qui/seqbrowser/SequenceBrowser.hpp',
+               'qui/seqbrowser/SequenceBrowserSidebar.hpp',
+               'qui/seqbrowser/SequenceBrowserWidget.hpp',
+               'qui/seqbrowser/SequenceDescription.hpp',]
+
+qui_sources = ['qui/ImageSaveDialog.cpp',
+               'qui/ImageScaler.cpp',
+               'qui/IntAction.cpp',        
+               'qui/MussaAlignedWindow.cpp',
+               'qui/MussaWindow.cpp',
+               'qui/ThresholdWidget.cpp',
+               'qui/ZoomWidget.cpp',
+               'qui/motif_editor/MotifDetail.cpp',
+               'qui/motif_editor/MotifEditor.cpp',
+               'qui/mussa_setup_dialog/IsFileValidator.cpp',
+               'qui/mussa_setup_dialog/MussaSetupDialog.cpp',
+               'qui/mussa_setup_dialog/MussaSetupWidget.cpp',
+               'qui/mussa_setup_dialog/SequenceSetupFrame.cpp',
+               'qui/mussa_setup_dialog/SequenceSetupWidget.cpp',
+               'qui/mussa_setup_dialog/SetupInfo.cpp',
+               'qui/seqbrowser/ScrollableSequenceBrowser.cpp',
+               'qui/seqbrowser/SequenceBrowser.cpp',
+               'qui/seqbrowser/SequenceBrowserSidebar.cpp',
+               'qui/seqbrowser/SequenceBrowserWidget.cpp',
+               'qui/seqbrowser/SequenceDescription.cpp',
+              ]
+
+qrc_sources = ['icons.qrc']
+
+sources = boost_py+core_alg+moc_headers+qui_sources+qrc_sources
+
+
+extra_link_args = []
+libraries = ['boost_python', 
+             'boost_filesystem']
+include_dirs = ['.']
+
+if sys.platform == 'darwin':
+  import py2app
+  qtroot = '/usr/local/qt/4.1.2'
+  qtincludes.os.path.join(qtroot, 'include')
+  extra_link_args.extend([
+    '-F%s/lib' % (qtroot),
+    '-framework', 'QtCore',
+    '-framework', 'QtGui',
+    '-framework', 'QtOpenGL',
+    '-framework', 'OpenGL',
+                      ])
+else:
+  qtroot = '/usr'
+  qtinclude = os.path.join(qtroot, 'include', 'qt4')
+  libraries += ['QtCore']
+  libraries += ['QtGui']
+  libraries += ['QtOpenGL']
+
+for qtdir in ['','QtCore','QtGui','QtOpenGL']:
+  include_dirs.append(os.path.join(qtinclude, qtdir))
+
+mussa_ext = Extension("_mussa", 
+                      sources,
+                      include_dirs=include_dirs,
+                      library_dirs=[
+                        #'/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/',
+                        '/usr/local/qt/4.1.2/lib',
+                      ],
+                      libraries=libraries,
+                      extra_link_args = extra_link_args
+            )
+setup(app=['mussa.py'],
+      name='mussa',
       version='0.0',
-      ext_modules=[mussa_ext])
+      ext_modules=[mussa_ext],
+      cmdclass={'build_ext': build_ext})
+