forked from I2PC/xmipp3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConscript
More file actions
326 lines (260 loc) · 12.1 KB
/
Copy pathSConscript
File metadata and controls
326 lines (260 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/usr/bin/env python
# **************************************************************************
# *
# * Authors: I. Foche Perez (ifoche@cnb.csic.es)
# * J.M. de la Rosa Trevin (jmdelarosa@cnb.csic.es)
# *
# * Unidad de Bioinformatica of Centro Nacional de Biotecnologia, CSIC
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# * 02111-1307 USA
# *
# * All comments concerning this program package may be sent to the
# * e-mail address 'ifoche@cnb.csic.es'
# *
# **************************************************************************
import os
from os.path import join
from glob import glob
from datetime import datetime
Import('env')
AddOption('--no-opencv', dest='opencv', action='store_false', default=True,
help='Avoid compilation of opencv programs')
get = lambda x: os.environ.get(x, '0').lower() in ['true', 'yes', 'y', '1']
gtest = get('GTEST')
cuda = get('CUDA')
debug = get('DEBUG')
matlab = get('MATLAB')
opencv = env.GetOption('opencv') and get('OPENCV')
opencvsupportscuda = get('OPENCVSUPPORTSCUDA')
opencv_3 = get('OPENCV3')
if opencv:
opencvLibs = ['opencv_core',
'opencv_imgproc',
'opencv_video',
'libopencv_calib3d']
if opencvsupportscuda:
if opencv_3:
opencvLibs+=['libopencv_cudaoptflow', 'libopencv_cudaarithm']
else:
opencvLibs+=['libopencv_gpu']
else:
opencvLibs = []
if 'MATLAB' in os.environ:
# Must be removed to avoid problems in Matlab compilation.
del os.environ['MATLAB']
# Yeah, nice
# Read some flags
CYGWIN = env['PLATFORM'] == 'cygwin'
MACOSX = env['PLATFORM'] == 'darwin'
MINGW = env['PLATFORM'] == 'win32'
XMIPP_PATH = Dir('.').abspath
XMIPP_BUNDLE = Dir('..').abspath
# ***********************************************************************
# * Xmipp C++ Libraries *
# ***********************************************************************
def getHdf5Name(libdirs):
for dir in libdirs:
if os.path.exists(os.path.join(dir.strip(),"libhdf5.so")):
return "hdf5"
elif os.path.exists(os.path.join(dir.strip(),"libhdf5_serial.so")):
return "hdf5_serial"
return "hdf5"
ALL_LIBS = {'fftw3', 'fftw3_threads', 'tiff', 'jpeg', 'sqlite3', getHdf5Name(env['EXTERNAL_LIBDIRS']), 'hdf5_cpp','XmippCore'}
# Create a shortcut and customized function
# to add the Xmipp CPP libraries
def addLib(name, **kwargs):
ALL_LIBS.add(name)
# Install all libraries in scipion/software/lib
# COSS kwargs['installDir'] = '#software/lib'
# Add always the xmipp path as -I for include and also xmipp/libraries
incs = kwargs.get('incs', []) + [join(XMIPP_PATH, 'external'),
join(XMIPP_PATH, 'libraries'), join(XMIPP_BUNDLE,'xmippCore')]
kwargs['incs'] = incs
deps = kwargs.get('deps', [])
kwargs['deps'] = deps
# Add libraries in libs as deps if not present
libs = kwargs.get('libs', [])
for lib in libs:
if lib in ALL_LIBS and lib not in deps:
deps.append(lib)
# If pattern not provided use *.cpp as default
patterns = kwargs.get('patterns', '*.cpp')
kwargs['patterns'] = patterns
libpath = kwargs.get('libpath', [])
kwargs['libpath'] = libpath+[join(XMIPP_BUNDLE,'xmippCore','lib'),join(XMIPP_BUNDLE,'xmipp','lib')]
lib = env.AddCppLibrary(name, **kwargs)
env.Alias('xmipp-libs', lib)
return lib
# Add first external libraries (alglib, bilib, condor)
#NOTE: for alglib and condor, the dir can not be where the source
# code is because try to use .h files to make the final .so library
def remove_prefix(text, prefix):
return text[text.startswith(prefix) and len(prefix):]
env['PYTHONINCFLAGS'] = os.environ.get('PYTHONINCFLAGS', '').split()
if len(env["PYTHONINCFLAGS"])>0:
python_incdirs = [remove_prefix(os.path.expandvars(x),"-I") for x in env["PYTHONINCFLAGS"]]
else:
python_incdirs = []
# Basic libraries
dirs = ['external','external','external','libraries','libraries','libraries','libraries','libraries']
patterns=['condor/*.cpp','delaunay/*.cpp','gtest/*.cc','data/*.cpp','reconstruction/*.cpp',
'classification/*.cpp','dimred/*.cpp','interface/*.cpp']
addLib('Xmipp', dirs=dirs, patterns=patterns, incs=python_incdirs, libs=['pthread','python2.7'])
# FRM library
dirs = ['external','external']
patterns=['sh_alignment/*.cpp','sh_alignment/SpharmonicKit27/*.cpp']
addLib('swig_frm', prefix="_", dirs=dirs, patterns=patterns, incs=python_incdirs, libs=['fftw3', 'fftw3_threads'])
# CUDA
if cuda:
addLib('XmippInterfaceCuda', dirs=['libraries'], patterns=['reconstruction_adapt_cuda/*.cpp'], libs=['Xmipp'])
addLib('XmippCuda', dirs=['libraries'], patterns=['reconstruction_cuda/*.cpp'], nvcc=True, suffix=".a")
addLib('XmippParallelCuda', dirs=['libraries'], patterns=['parallel_adapt_cuda/*.cpp'],
libs=['Xmipp','XmippInterfaceCuda','XmippCuda'], mpi=True)
# MPI
dirs = ['libraries']
patterns=['parallel/*.cpp']
addLib('XmippParallel',dirs=dirs,patterns=patterns, libs=['Xmipp'], mpi=True)
# ***********************************************************************
# * Xmipp Programs and Tests *
# ***********************************************************************
XMIPP_LIBS = ['Xmipp']
PROG_DEPS = XMIPP_LIBS
PROG_LIBS = XMIPP_LIBS + [getHdf5Name(env['EXTERNAL_LIBDIRS']),'hdf5_cpp','fftw3','fftw3_threads','jpeg']
# Shortcut function to add the Xmipp programs.
def addProg(progName, **kwargs):
""" Shortcut to add the Xmipp programs easily.
Params:
progName: the name of the program without xmipp_ prefix that will be added.
if 'src' not in kwargs, add: 'applications/programs/progName' by default.
if progName starts with 'mpi_' then mpi will be set to True.
"""
if progName.startswith('test_'):
src = kwargs.get('src', [join('applications', 'tests', 'function_tests', progName+".cpp")])
else:
src = kwargs.get('src', [join('applications', 'programs', progName)])
kwargs['src'] = src
# Add all xmipp libraries just in case
kwargs['libs'] = kwargs.get('libs', []) + PROG_LIBS + ['XmippCore']
kwargs['deps'] = PROG_DEPS
# Add always the xmipp path as -I for include and also xmipp/libraries
incs = kwargs.get('incs', []) + [join(XMIPP_PATH, 'external'),
join(XMIPP_PATH, 'libraries'), join(XMIPP_BUNDLE,'xmippCore')]
kwargs['incs'] = incs
if 'libPaths' in kwargs:
kwargs['libPaths'] +=[join(XMIPP_BUNDLE,'xmippCore','lib'),join(XMIPP_BUNDLE,'xmipp','lib')]
else:
kwargs['libPaths'] =[join(XMIPP_BUNDLE,'xmippCore','lib'),join(XMIPP_BUNDLE,'xmipp','lib')]
if progName.startswith('mpi_'):
kwargs['mpi'] = True
kwargs['libs'] += ['XmippParallel']
if progName.startswith('cuda_'):
kwargs['cuda'] = True
kwargs['libs'] += ['XmippInterfaceCuda','XmippCuda']
if progName.startswith('mpi_cuda_'):
kwargs['cuda'] = True
kwargs['libs'] += ['XmippInterfaceCuda','XmippCuda','XmippParallelCuda']
xmippProgName = 'xmipp_%s' % progName
prog = env.AddProgram(xmippProgName, **kwargs)
# Add some aliases before return
env.Alias(xmippProgName, prog)
env.Alias('xmipp-programs', prog)
return prog
# Define the list of all programs
PROGRAMS_WITH_PYTHON = ['volume_align_prog','mpi_classify_CLTomo_prog']
PROGRAMS_WITH_OPENCV = ['movie_optical_alignment_cpu','mpi_volume_homogenizer']
PROGRAMS_WITH_OPENCV_AND_CUDA = ['movie_optical_alignment_gpu']
for p in glob(os.path.join(XMIPP_PATH,'applications','programs','*')):
pname = os.path.basename(p)
if pname in PROGRAMS_WITH_PYTHON:
addProg(pname,incs=python_incdirs,libs=['python2.7'])
elif pname in PROGRAMS_WITH_OPENCV:
if opencv:
addProg(pname,libs=opencvLibs,deps=['opencv'])
elif pname in PROGRAMS_WITH_OPENCV_AND_CUDA:
if opencv and opencvsupportscuda:
addProg(pname,libs=opencvLibs,deps=['opencv'],cuda=True)
elif 'cuda' in pname:
if cuda:
addProg(pname)
else:
addProg(pname)
for p in glob(os.path.join(XMIPP_PATH,'applications','tests','function_tests','*.cpp')):
pname = os.path.basename(p).replace('.cpp','')
addProg(pname)
addLib('xmippLib.so',
dirs=['bindings'],
patterns=['python/*.cpp'],
incs=python_incdirs,
libs=['python2.7', 'XmippCore', 'Xmipp'],
prefix='', target='xmippLib')
# ***********************************************************************
# * Xmipp Scripts *
# ***********************************************************************
def addBatch(batchName, script, scriptFolder='applications/scripts'):
""" Add a link to xmipp/bin folder prepending xmipp_ prefix.
The script should be located in from xmipp root,
by default in 'applications/scripts/'
"""
xmippBatchName = 'xmipp_%s' % batchName
batchLink = env.SymLink(join(XMIPP_PATH, 'bin', xmippBatchName),
join(XMIPP_PATH, scriptFolder, script))
env.Alias('xmipp-batchs', batchLink)
return batchLink
# Batches (apps)
for scriptName in glob(os.path.join(XMIPP_PATH,'applications','scripts','*','*.[ps]*')):
dirName = os.path.basename(os.path.dirname(scriptName))
addBatch(dirName,scriptName)
# # Python tests
# testPythonInterface = env.SymLink('bin/xmipp_test_pythoninterface', 'applications/tests/test_pythoninterface/batch_test_pythoninterface.py')
# Depends(testPythonInterface, packageDeps)
# AddXmippTest('test_pythoninterface', testPythonInterface, "$SOURCE $TARGET")
#
# testPySqlite = env.SymLink('bin/xmipp_test_pysqlite', 'applications/tests/test_pysqlite/batch_test_pysqlite.py')
# Depends(testPySqlite, packageDeps)
# AddXmippTest('test_pysqlite', testPySqlite, "$SOURCE $TARGET")
#
# testEMX = env.SymLink('bin/xmipp_test_emx', 'applications/tests/test_emx/batch_test_emx.py')
# Depends(testEMX, packageDeps)
# AddXmippTest('test_emx', testEMX, "$SOURCE $TARGET")
def compileMatlabBinding(target, source, env):
matlabDir = join(XMIPP_PATH, 'bindings', 'matlab')
incStr = ' '.join('-I%s' % p for p in [os.path.join(XMIPP_BUNDLE, 'xmippCore'),
os.path.join(XMIPP_BUNDLE, 'xmipp','libraries')]+env['EXTERNAL_INCDIRS'] )
libStr = ' '.join('-L%s' % p for p in [os.path.join(XMIPP_BUNDLE, 'xmippCore','lib'),
os.path.join(XMIPP_BUNDLE, 'xmipp','lib')]+env['EXTERNAL_LIBDIRS'])
libs = ' '.join('-l%s' % lib for lib in ['Xmipp','XmippCore'])
mex = join(env['MATLAB_DIR'], 'bin', 'mex')
command = '%s -O CFLAGS="\$CFLAGS -std=c99 -fpermissive" -outdir %s %s %s %s %s ' % (mex, matlabDir, incStr, libStr, libs, source[0])
print command
os.system(command)
# Matlab programs
def addMatlabBinding(name):
""" Add options to compile xmipp-Matlab bindings. """
matlabDir = join(XMIPP_PATH, 'bindings', 'matlab')
source = join(matlabDir, name)
target = join(matlabDir, name.replace(".cpp",".mexa64"))
cmdTarget = env.Command(target, source, compileMatlabBinding)
env.Alias('xmipp-matlab', cmdTarget)
return cmdTarget
if matlab:
for pname in glob(os.path.join(XMIPP_PATH,'bindings','matlab','*.cpp')):
addMatlabBinding(pname)
env.Default('xmipp-matlab')
env.Alias('xmipp', 'xmipp-matlab')
XmippAlias = env.Alias('xmipp', ['xmipp-libs',
'xmipp-programs',
'xmipp-batchs'])
Return('XmippAlias')