Page MenuHomec4science

SConscript
No OneTemporary

File Metadata

Created
Wed, May 1, 15:47

SConscript

from __future__ import print_function
from os.path import abspath, basename
from distutils.version import StrictVersion
from subprocess import check_output, STDOUT
import re
Import('main_env')
env_swig = main_env.Clone(
tools=['swig'],
SHLIBPREFIX='',
)
if env_swig['SWIGVERSION'] is None:
print("Could not find swig version")
Exit(1)
if StrictVersion(env_swig['SWIGVERSION']) < StrictVersion("3.0"):
print("Swig version {} is not supported by tamaas".format(env_swig['SWIGVERSION']))
Exit(1)
# Check user's prefered version
version_out = check_output([main_env['py_exec'], "--version"], stderr=STDOUT, universal_newlines=True).split(' ')
# Matching version
version_re = re.compile(r"^\d(\.\d+)*")
version_string = version_re.match(version_out[-1]).group()
# Verifying version
version = StrictVersion(version_string)
python3 = version >= StrictVersion("3.0")
print("Building wrapper for python version {}".format(version))
# Run code below to get versions from user preference and not scons
versions_script = """
from __future__ import print_function
import distutils.sysconfig as dsys
from numpy.distutils.misc_util import get_numpy_include_dirs as numpy_dirs
print(dsys.get_python_inc())
for d in numpy_dirs():
print(d)"""
includes = check_output([main_env['py_exec'], "-c", versions_script],
universal_newlines=True).split('\n')
env_swig.AppendUnique(CPPPATH=includes)
env_swig.AppendUnique(SWIGPATH=['$CPPPATH'])
env_swig.AppendUnique(SWIGFLAGS=['-python', '-c++'])
if python3:
env_swig.AppendUnique(SWIGFLAGS=['-py3'])
verbose = main_env['verbose']
if not verbose:
env_swig.AppendUnique(SWIGFLAGS=['-w325', '-w315'])
if basename(env_swig['CXX']) != "clang++": # for some warning in wrapper code
env_swig.AppendUnique(CXXFLAGS=['-Wno-maybe-uninitialized'])
else:
env_swig.AppendUnique(CXXFLAGS=['-Wno-uninitialized',
'-Wno-dynamic-class-memaccess'])
# env_swig.SharedLibrary(
# target='_tamaas.so',
# source=['tamaas.i'],
# LIBS=['Tamaas'],
# RPATH=[abspath('../src')]
# )
# Pybind11 wrapper
env_pybind = main_env.Clone(SHLIBPREFIX='')
includes += [Dir('#third-party/pybind11/include')]
extension = check_output([main_env['py_exec'] + '-config', "--extension-suffix"],
universal_newlines=True).split('\n')[0]
env_pybind.AppendUnique(CPPPATH=includes)
pybind_sources = Split("""
tamaas_module.cpp
wrap/core.cpp
wrap/percolation.cpp
wrap/surface.cpp
""")
env_pybind.SharedLibrary(
target='tamaas' + extension,
source=pybind_sources,
LIBS=['Tamaas'],
RPATH=[abspath('../src')]
)

Event Timeline