
##############################################################################
#
# Copyright (c) 2003-2020 by The University of Queensland
# http://www.uq.edu.au
#
# Primary Business: Queensland, Australia
# Licensed under the Apache License, version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Development until 2012 by Earth Systems Science Computational Center (ESSCC)
# Development 2012-2013 by School of Earth Sciences
# Development from 2014 by Centre for Geoscience Computing (GeoComp)
# Development from 2019 by School of Earth and Environmental Sciences
#
##############################################################################

Import('*')

module_name = 'speckley'

sources = """
    AbstractAssembler.cpp
    Brick.cpp
    BrickGradients.cpp
    BrickIntegrals.cpp
    BrickReductions.cpp
    DefaultAssembler2D.cpp
    DefaultAssembler3D.cpp
    domainhelpers.cpp
    Rectangle.cpp
    RectangleGradients.cpp
    RectangleIntegrals.cpp
    RectangleReductions.cpp
    SpeckleyDomain.cpp
    WaveAssembler2D.cpp
    WaveAssembler3D.cpp
""".split()

headers = """
    AbstractAssembler.h
    Brick.h
    DefaultAssembler2D.h
    DefaultAssembler3D.h
    domainhelpers.h
    lagrange_functions.h
    Rectangle.h
    Speckley.h
    SpeckleyDomain.h
    SpeckleyException.h
    system_dep.h
    WaveAssembler2D.h
    WaveAssembler3D.h
""".split()

local_env = env.Clone()

if IS_WINDOWS:
    local_env.Append(CPPDEFINES = ['Speckley_EXPORTS'])

# collect dependencies for other modules
speckleylibs = []
speckleylibs += env['escript_libs']
if 'ripley' in env['domains']:
    local_env.Append(CPPDEFINES = ['USE_RIPLEY'])
    speckleylibs += env['ripley_libs']
    sources += ['CrossDomainCoupler.cpp']
    headers += ['CrossDomainCoupler.h']

if env['compressed_files']:
    speckleylibs += env['compression_libs']
if env['silo']:
    speckleylibs += env['silo_libs']

local_env.PrependUnique(LIBS = speckleylibs)

env['speckley_libs'] = [module_name] + speckleylibs

include_path = Dir(module_name, local_env['incinstall'])
hdr_inst = local_env.Install(include_path, headers)

lib = local_env.SharedLibrary(module_name, sources)
lib_inst = local_env.Install(local_env['libinstall'], lib)

### Python wrapper ###
py_env = local_env.Clone()
py_env.Prepend(LIBS = [module_name])
py_lib_name = module_name + 'cpp'
py_lib = py_env.PythonModule(py_lib_name, 'speckleycpp.cpp')

mod_path = Dir(module_name, local_env['pyinstall'])
mod_inst = py_env.Install(mod_path, py_lib)

build = env.Alias('build_speckley', [hdr_inst, lib, py_lib])
env.Alias('install_speckley', [build, lib_inst, mod_inst])

