From 3a838018fcb854d006a511bcc66cd8e1e837d0b0 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 6 Sep 2012 19:55:34 +0000 Subject: [PATCH] Use SCons to generate a customized setup.py for the new Python module --- SConstruct | 1 + interfaces/cython/setup.py.in | 20 ++++++++++---------- src/python/SConscript | 32 +++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/SConstruct b/SConstruct index c84cd091f..de176f194 100644 --- a/SConstruct +++ b/SConstruct @@ -1116,6 +1116,7 @@ if not env['single_library']: # Add lapack and blas to the link line if env['blas_lapack_libs']: linkLibs.extend(env['blas_lapack_libs']) + linkSharedLibs.extend(env['blas_lapack_libs']) elif not env['single_library']: linkLibs.extend(('ctlapack', 'ctblas')) linkSharedLibs.extend(('ctlapack_shared', 'ctblas_shared')) diff --git a/interfaces/cython/setup.py.in b/interfaces/cython/setup.py.in index 394f271c4..668bb21e0 100644 --- a/interfaces/cython/setup.py.in +++ b/interfaces/cython/setup.py.in @@ -9,22 +9,22 @@ if os.name == 'nt': else: dataFiles.append('libcantera_shared.so') -canteraExtensions = [] +exts = [] def addExtension(name): - canteraExtensions.append(Extension("cantera.%s" % name, - ["cantera/%s.pyx" % name], - include_dirs=[".", "../../include"], - language="c++", - libraries=['cantera_shared','sundials_cvodes','sundials_idas','sundials_nvecserial','lapack','blas'], - library_dirs=['../../build/lib'], - extra_link_args=['-Wl,-rpath=$ORIGIN'])) + exts.append(Extension("cantera.%s" % name, + ["cantera/%s.pyx" % name], + include_dirs=@py_include_dirs@, + language="c++", + libraries=@py_cantera_libs@, + library_dirs=@py_libdirs@, + extra_link_args=@py_extra_link_args@)) addExtension('solution') addExtension('utils') setup(name="Cantera", - version="2.1a1", + version="@cantera_version@", description="The Cantera Python Interface", long_description=""" """, @@ -33,5 +33,5 @@ setup(name="Cantera", url="http://code.google.com/p/cantera", packages = ["cantera"], cmdclass = {'build_ext': build_ext}, - ext_modules = canteraExtensions, + ext_modules = exts, package_data = {'cantera': dataFiles}) diff --git a/src/python/SConscript b/src/python/SConscript index 9bb4bad3c..621dcd32a 100644 --- a/src/python/SConscript +++ b/src/python/SConscript @@ -3,10 +3,14 @@ import distutils.sysconfig Import('env', 'build', 'install') -localenv = env.Clone() - gcv = distutils.sysconfig.get_config_var +#################################### +### Old Python Module: Raw C API ### +#################################### + +localenv = env.Clone() + localenv.Append(CPPPATH=[gcv('INCLUDEPY'), env['python_array_include']], CPPFLAGS=((gcv('BASECFLAGS') or '').split() + (gcv('OPT') or '').split()), @@ -25,7 +29,6 @@ for var in ('VS80COMNTOOLS', 'VS90COMNTOOLS', 'VS100COMNTOOLS'): if var in os.environ: localenv['ENV'][var] = os.environ[var] -localenv['spam_source'] = repr(File('#src/python/spam.c').abspath) make_setup = localenv.SubstFile('#interfaces/python/setup.py', '#interfaces/python/setup.py.in') @@ -102,3 +105,26 @@ elif localenv['PYTHON_INSTALLER'] == 'binary': if localenv['python_package'] == 'full': install(localenv.RecursiveInstall, pjoin('$inst_sampledir', 'python'), '#samples/python') + +################################# +### New Python Module: Cython ### +################################# + +localenv = env.Clone() +incDirs = (".", "../../include", localenv['python_array_include'], + localenv['sundials_include'], localenv['boost_inc_dir']) +libDirs = ('../../build/lib', localenv['sundials_libdir'], + localenv['boost_lib_dir']) + +localenv['py_include_dirs'] = repr([x for x in incDirs if x]) +localenv['py_cantera_libs'] = repr(localenv['cantera_shared_libs']) +localenv['py_libdirs'] = repr([x for x in libDirs if x]) + +if localenv['CC'] == 'cl': + localenv['py_extra_link_args'] = repr([]) +else: + localenv['py_extra_link_args'] = repr(['-Wl,-rpath=$$ORIGIN']) + +make_setup = localenv.SubstFile('#interfaces/cython/setup.py', + '#interfaces/cython/setup.py.in') +build(make_setup)