build all of mussagl as a python extension
[mussa.git] / setup.py
1 from setuptools import setup, Extension
2 import distutils.command.build_ext
3 from distutils.dep_util import newer
4 import py2app
5
6 import os
7
8 def replace_suffix(path, new_suffix):
9   return os.path.splitext(path)[0]+new_suffix
10
11 class build_ext(distutils.command.build_ext.build_ext):
12   description="also compile qt moc files"
13
14   def swig_sources(self, sources, extensions=None):
15     if self.extensions is None:
16       return
17   
18     # filter out sources
19     qrc_sources = []
20     moc_sources = []
21     other_sources = []
22     for src in sources:
23       base,ext= os.path.splitext(src)
24       if ext == '.qrc':
25         qrc_sources.append(src)
26       elif ext in ('.hpp', '.hxx', '.h'):
27         moc_sources.append(src)
28       else:
29         other_sources.append(src)
30
31     build_sources = other_sources
32     # create qresource
33     build_sources.extend(self.compile_qrcs(qrc_sources))
34     # create moc files 
35     build_sources.extend(self.compile_mocs(moc_sources))
36     return build_sources 
37
38   def compile_qrcs(self, qrc_files):
39     targets = []
40     for qrc in qrc_files:
41       if os.path.exists(qrc):
42         source = qrc
43         name = os.path.splitext(os.path.split(qrc)[1])[0]
44         target = "qrc_"+name+".cpp"
45         if newer(source, target) or self.force:
46           self.compile_qrc(name, source, target)
47         targets.append(target)
48     return targets
49
50   def compile_qrc(self, name, source, target):
51     """compile qt resource file"""
52     os.system("rcc -name %s -o %s %s" %(name, target, source))
53
54   def compile_mocs(self, moc_headers):
55     targets = []
56    
57     for moc_hpp in moc_headers:
58       if os.path.exists(moc_hpp):
59         source = moc_hpp
60         target = "moc_"+replace_suffix(os.path.split(moc_hpp)[1],'.cpp')
61         if newer(source, target) or self.force:
62           self.compile_moc(source, target)
63         targets.append(target)
64     return targets
65   
66   def compile_moc(self, source, target):
67     os.system("moc -o%s %s" %(target, source))
68
69 boost_py = ["py/conserved_path.cpp",
70            "py/glsequence.cpp",
71            "py/module.cpp",
72            "py/mussa.cpp",
73            "py/MussaWindow.cpp",
74            "py/nway_paths.cpp",
75            "py/sequence.cpp",]
76
77 core_alg = ["alg/annotation_colors.cpp",
78             "alg/color.cpp",
79             "alg/conserved_path.cpp",
80             "alg/flp.cpp",
81             "alg/flp_seqcomp.cpp",
82             "alg/glseqbrowser.cpp",
83             "alg/glsequence.cpp",
84             "alg/mussa.cpp",
85             "alg/nway_entropy.cpp",
86             "alg/nway_other.cpp",
87             "alg/nway_paths.cpp",
88             #"alg/nway_refine",
89             #"alg/parse_options.cpp",
90             "alg/sequence.cpp",]
91
92 moc_headers = ['qui/ImageSaveDialog.hpp',
93                'qui/ImageScaler.hpp',
94                'qui/IntAction.hpp',
95                'qui/MussaAlignedWindow.hpp',
96                'qui/MussaWindow.hpp',
97                'qui/ThresholdWidget.hpp',
98                'qui/ZoomWidget.hpp',
99                'qui/motif_editor/MotifDetail.hpp',
100                'qui/motif_editor/MotifEditor.hpp',
101                'qui/mussa_setup_dialog/IsFileValidator.hpp',
102                'qui/mussa_setup_dialog/MussaSetupDialog.hpp',
103                'qui/mussa_setup_dialog/MussaSetupWidget.hpp',
104                'qui/mussa_setup_dialog/SequenceSetupFrame.hpp',
105                'qui/mussa_setup_dialog/SequenceSetupWidget.hpp',
106                'qui/mussa_setup_dialog/SetupInfo.hpp',
107                'qui/seqbrowser/ScrollableSequenceBrowser.hpp',
108                'qui/seqbrowser/SequenceBrowser.hpp',
109                'qui/seqbrowser/SequenceBrowserSidebar.hpp',
110                'qui/seqbrowser/SequenceBrowserWidget.hpp',
111                'qui/seqbrowser/SequenceDescription.hpp',]
112
113 qui_sources = ['qui/ImageSaveDialog.cpp',
114                'qui/ImageScaler.cpp',
115                'qui/IntAction.cpp',        
116                'qui/MussaAlignedWindow.cpp',
117                'qui/MussaWindow.cpp',
118                'qui/ThresholdWidget.cpp',
119                'qui/ZoomWidget.cpp',
120                'qui/motif_editor/MotifDetail.cpp',
121                'qui/motif_editor/MotifEditor.cpp',
122                'qui/mussa_setup_dialog/IsFileValidator.cpp',
123                'qui/mussa_setup_dialog/MussaSetupDialog.cpp',
124                'qui/mussa_setup_dialog/MussaSetupWidget.cpp',
125                'qui/mussa_setup_dialog/SequenceSetupFrame.cpp',
126                'qui/mussa_setup_dialog/SequenceSetupWidget.cpp',
127                'qui/mussa_setup_dialog/SetupInfo.cpp',
128                'qui/seqbrowser/ScrollableSequenceBrowser.cpp',
129                'qui/seqbrowser/SequenceBrowser.cpp',
130                'qui/seqbrowser/SequenceBrowserSidebar.cpp',
131                'qui/seqbrowser/SequenceBrowserWidget.cpp',
132                'qui/seqbrowser/SequenceDescription.cpp',
133               ]
134
135 qrc_sources = ['icons.qrc']
136
137 sources = boost_py+core_alg+moc_headers+qui_sources+qrc_sources
138
139 mussa_ext = Extension("_mussa", 
140                       sources,
141                       include_dirs=[
142                         '/usr/include/boost',
143                         '/usr/local/qt/4.1.2/include/',
144                         '/usr/local/qt/4.1.2/include/QtCore',
145                         '/usr/local/qt/4.1.2/include/QtGui',
146                         '/usr/local/qt/4.1.2/include/QtOpenGL',
147                         '.'
148                       ],
149                       library_dirs=[
150                         '/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib/',
151                         '/usr/local/qt/4.1.2/lib',
152                       ],
153                       libraries=[
154                         'boost_python', 
155                         'boost_filesystem',
156                         'GL',
157                       ],
158                       extra_link_args = [
159                         '-F/usr/local/qt/4.1.2/lib',
160                         '-framework', 'QtCore',
161                         '-framework', 'QtGui',
162                         '-framework', 'QtOpenGL',
163                       ]
164             )
165 setup(app=['mussa.py'],
166       name='mussa',
167       version='0.0',
168       ext_modules=[mussa_ext],
169       cmdclass={'build_ext': build_ext})
170
171