Newer
Older
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
setup.py file for @PYPACKAGE_NAME@
"""
from numpy.distutils.core import setup, Extension
from numpy.distutils.misc_util import Configuration
Jean-Matthieu Etancelin
committed
import os
Jean-Baptiste Keck
committed
import fnmatch
# tools to deal with fortran dependencies.
import sys
sys.path.append('@CMAKE_SOURCE_DIR@/')
import sort_f90
Jean-Baptiste Keck
committed
def parseCmakeVar(var):
if var != "":
return var.split(';')
else:
return None
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
def create_fortran_extension(name, pyf_file=None, src_dirs=None, sources=None,
libdir=None, libs=None, debug_mode=0):
"""Create a new f2py module from fortran files
"""
if sources is None:
sources = []
assert src_dirs is not None
for sdir in src_dirs:
sources += glob.glob(os.path.join(sdir, '*.f95'))
sources += glob.glob(os.path.join(sdir, '*.f90'))
f2py_options = ['--no-lower', '--no-wrap-functions']
options = []
# Reorder source list with fortran modules
# dependencies. It seems that this is not taken into
# account in f2py or distutils.
if pyf_file is not None:
sources.append(pyf_file)
sources = sort_f90.sort(sources)
if debug_mode == 0:
options.append(('F2PY_REPORT_ON_ARRAY_COPY', '1'))
if os.uname()[0] == 'Linux':
options.append(('F2PY_REPORT_ATEXIT', '1'))
inc_dir = '@MPI_Fortran_INCLUDE_PATH@'.split(';')
# To avoid -I -I in compiler call, which results in a bug:
while inc_dir.count('') > 0:
inc_dir.remove('')
inc_dir.append('@CMAKE_BINARY_DIR@/Modules')
fortran_flags = ['@Fortran_FLAGS@']
ext_fort = Extension(name=name,
sources=sources,
f2py_options=f2py_options,
include_dirs=inc_dir,
define_macros=options,
library_dirs=libdir,
libraries=libs,
extra_f90_compile_args=fortran_flags
)
return ext_fort
Jean-Baptiste Keck
committed
def create_swig_extension(name, inc_dirs, src_dirs=None, sources=None):
"""Create a python module from C++ files, using swig
"""
Jean-Baptiste Keck
committed
swig_dir = os.path.join('@CMAKE_SOURCE_DIR@', 'swig')
swig_config_file = os.path.join(swig_dir, name+'.i')
include_dirs = set(inc_dirs)
if sources is None:
sources = []
Jean-Baptiste Keck
committed
if(src_dirs == None):
assert(inc_dirs != None)
for idir in inc_dirs:
#sources += glob.glob(os.path.join(idir, '**/*.cpp'), recursive=True)
for root, dirnames, filenames in os.walk(idir):
for filename in fnmatch.filter(filenames, '*.cpp'):
sources.append(os.path.join(root, filename))
else:
for sdir in src_dirs:
sources += glob.glob(os.path.join(sdir, '*.cpp'))
Jean-Baptiste Keck
committed
#else:
#for f in sources:
#include_dirs.add(os.path.dirname(f))
Jean-Baptiste Keck
committed
sources.insert(0,swig_config_file)
include_dirs = list(include_dirs)
name = 'hysop._' + name
swig_opts = ['-I' + swig_dir,
'-c++', '-modern']
#-outdir', '/Users/Franck/toto',
extern_includes = parseCmakeVar("@CXX_EXT_INCLUDES@")
if(extern_includes != None):
for exti in extern_includes:
include_dirs.append(exti)
libraries = parseCmakeVar("@CXX_EXT_LIBS@")
library_dirs = parseCmakeVar("@CXX_EXT_LIB_DIRS@")
extra_compile_args = parseCmakeVar("@CXX_FLAGS@")
extra_link_args = parseCmakeVar("@CXX_LINKER_FLAGS@")
define_macros = parseCmakeVar("@CXX_EXTRA_DEFINES@")
#print "INCLUDE_DIRS=",include_dirs
#print "LIBRARIES=",libraries
#print "LIBRARY_DIRS=",library_dirs
#print "EXTRA_COMPILE_ARGS=",extra_compile_args
#print "EXTRA_LINK_ARGS=",extra_link_args
#print "DEFINE_MACROS=",define_macros
# To avoid -I -I in compiler call, which results in a bug:
#while inc_dir.count('') > 0:
# inc_dir.remove('')
#inc_dir.append('@CMAKE_BINARY_DIR@/Modules')
Jean-Baptiste Keck
committed
swig_ext = Extension(name, sources=sources, language='c++',
swig_opts=swig_opts,
Jean-Baptiste Keck
committed
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
# ------------ Set list of packages required to build the module -------------
# Full package name
name = '@PYPACKAGE_NAME@'
# List of modules (directories) to be included
packages = ['hysop',
'hysop.domain',
'hysop.fields',
'hysop.operator',
'hysop.operator.discrete',
'hysop.problem',
'hysop.tools',
'hysop.numerics',
'hysop.numerics.integrators',
Franck Pérignon
committed
]
packages_for_tests = ['hysop.domain.tests',
'hysop.fields.tests',
'hysop.operator.tests',
'hysop.numerics.tests',
'hysop.tools.tests',
'hysop.problem.tests',
'hysop.numerics.tests',
if "@USE_MPI@" is "ON":
packages.append('hysop.mpi')
packages_for_tests.append('hysop.mpi.tests')
if "@WITH_GPU@" is "ON":
packages.append('hysop.gpu')
packages_for_tests.append('hysop.gpu.tests')
if "@WITH_TESTS@" is "ON":
packages = packages + packages_for_tests
Jean-Matthieu Etancelin
committed
DISTUTILS_DEBUG = 1
# ------------ Extensions (f2py, cython, ...) setup ------------
ext_modules = []
# Check if fortran interface is enabled
enable_fortran = "@WITH_LIB_FORTRAN@"
if enable_fortran is "ON":
fortran_root = \
'@CMAKE_SOURCE_DIR@/hysop'
hysop_libdir = ['@CMAKE_BINARY_DIR@/src']
hysoplib = ['@HYSOP_LIBRARY_NAME@']
f2py_options = ['--no-lower']
fortran_src = set([])
# -- fftw fortran sources --
withfftw = "@WITH_FFTW@"
if withfftw is "ON":
fortran_src.add('f2py/parameters.f90')
fortran_src.add('f2py/fftw2py.f90')
fftwdir = '@FFTWLIB@'
hysoplib.append('fftw3')
hysoplib.append('fftw3_mpi')
Franck Pérignon
committed
else:
packages.append('hysop.fakef2py')
packages.append('hysop.fakef2py.fftw2py')
withscales = '@WITH_SCALES@'
if withscales is "ON":
fortran_src.add('f2py/parameters.f90')
fortran_src.add('f2py/scales2py.f90')
Franck Pérignon
committed
else:
packages.append('hysop.fakef2py')
packages.append('hysop.fakef2py.scales2py')
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
# -- set full path to fortran sources --
fortran_src = list(fortran_src)
for i in xrange(len(fortran_src)):
fortran_src[i] = os.path.join(fortran_root, fortran_src[i])
# === Draft for future implementation of fortran interface ===
# -- f2py signature file --
pyf_file = os.path.join(fortran_root, 'f2hysop.pyf')
# -- list of directories which contains fortran sources --
# those dirs must be in hysop package directory
subdirs = ['fortran',
]
num_dirs = []
for sd in subdirs:
num_dirs.append(os.path.join(fortran_root, sd))
# create python interface to fortran sources
# For the moment, it includes the 'old' interface
# to scales and fftw (in sources) and the new
# interface, in src_dirs
ext['f2hysop'] = create_fortran_extension(
name='hysop.f2hysop',
sources=fortran_src,
libdir=hysop_libdir,
libs=hysoplib,
pyf_file=pyf_file,
src_dirs=num_dirs)
for ex in ext:
ext_modules.append(ext[ex])
packages.append('hysop.fakef2py')
packages.append('hysop.fakef2py.scales2py')
packages.append('hysop.fakef2py.fftw2py')
Jean-Matthieu Etancelin
committed
# --- C++ files and swig interface --
Jean-Baptiste Keck
committed
enable_cpp = "@WITH_LIB_CXX@"
if enable_cpp:
# path to .i files
swig_include_dirs = [os.path.join('@CMAKE_SOURCE_DIR@','swig')]
cpp_include_dirs = ['src/fftw','src/hysop++/src']
for id in cpp_include_dirs:
swig_include_dirs.append(os.path.join('@CMAKE_SOURCE_DIR@', id))
cpp2hysop = "@CPP_2_HYSOP@"
ext[cpp2hysop] = create_swig_extension(name=cpp2hysop, inc_dirs=swig_include_dirs)
for ex in ext:
ext_modules.append(ext[ex])
if "@WITH_GPU@" is "ON":
cl_src_dirs = ["cl_src", "cl_src/kernels",
"cl_src/advection", "cl_src/remeshing"]
for cl_dir in cl_src_dirs:
data_files.append(
('./hysop/gpu/' + cl_dir,
['@CMAKE_SOURCE_DIR@/hysop/gpu/' + cl_dir + '/'
+ cl_file
for cl_file in os.listdir(
'@CMAKE_SOURCE_DIR@/hysop/gpu/' + cl_dir + '/')
if cl_file[0] != '.' and cl_file[0] != '#' and cl_file[-3:] == '.cl']))
descr = 'Hybrid Computation with Particles.'
Jean-Baptiste Keck
committed
authors = 'G.H Cottet, J.M Etancelin, J.B Keck, C.Mimeau, F.Pérignon, C. Picard'
# authors = 'HySoP development team'
config = Configuration(
name=name,
version='@PYPACKAGE_VERSION@',
description=descr,
author=authors,
author_email='hysop-members@lists.forge.imag.fr',
url='https://forge.imag.fr/projects/hysop/',
license='GNU public license',
package_dir={'': '@CMAKE_SOURCE_DIR@'},
ext_modules=ext_modules,
packages=packages,
data_files=data_files,
setup(**config.todict())