Build libqpms as shared library.

Former-commit-id: 218d30a8502e5ea5814e4d8e119b750ca93d257f
This commit is contained in:
Marek Nečada 2019-08-12 16:33:54 +03:00
parent 82337ca07f
commit 2e037550b5
5 changed files with 46 additions and 25 deletions

View File

@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.0.2) cmake_minimum_required(VERSION 3.0.2)
include(CMakeAddFortranSubdirectory) include(CMakeAddFortranSubdirectory)
include(version.cmake) include(version.cmake)
include(GNUInstallDirs)
project (QPMS) project (QPMS)

View File

@ -47,20 +47,22 @@ you can [get the source and compile it yourself][GSL].
You also need a fresh enough version of [cmake][]. You also need a fresh enough version of [cmake][].
After GSL is installed, you can install qpms to your local python library using:: After GSL is installed, you can install qpms to your local python library using
```{.sh} ```{.sh}
cmake . cmake -DCMAKE_INSTALL_PREFIX=${YOUR_PREFIX} .
make amos make install
python3 setup.py install --user python3 setup.py install --user
``` ```
Above, replace `${YOUR_PREFIX}` with the path to where you want to install the shared library;
you will also need to make sure that the linker can find it;
on Linux, this means the path `${YOUR_PREFIX}/lib` is included in your
`LIBRARY_PATH` and `LD_LIBRARY_PATH` environment variables. The same applies
to the GSL and OpenBLAS dependencies: they must be installed where the
installation scripts and linker can find them (setting the `C_INCLUDE_PATH` environment
variable might be necessary as well).
If GSL is not installed the standard library path on your system, you might Special care might need to be taken when installing QPMS in cluster environments.
need to pass it to the installation script using the
`LIBRARY_PATH` and `LD_LIBRARY_PATH` environment
variables.
Special care has often be taken when installing QPMS in cluster environments.
Specific installation instructions for Aalto University's Triton cluster Specific installation instructions for Aalto University's Triton cluster
can be found in a [separate document][TRITON-README]. can be found in a [separate document][TRITON-README].

View File

@ -10,7 +10,7 @@ add_definitions(-DQPMS_VECTORS_NICE_TRANSFORMATIONS)
set (DIRS ${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS}) set (DIRS ${GSL_INCLUDE_DIRS} ${GSLCBLAS_INCLUDE_DIRS})
include_directories(${DIRS}) include_directories(${DIRS})
add_library (qpms translations.c tmatrices.c vecprint.c vswf.c wigner.c ewald.c add_library (qpms SHARED translations.c tmatrices.c vecprint.c vswf.c wigner.c ewald.c
ewaldsf.c pointgroups.c latticegens.c ewaldsf.c pointgroups.c latticegens.c
lattices2d.c gaunt.c error.c legendre.c symmetries.c vecprint.c lattices2d.c gaunt.c error.c legendre.c symmetries.c vecprint.c
bessel.c own_zgemm.c parsing.c scatsystem.c materials.c drudeparam_data.c) bessel.c own_zgemm.c parsing.c scatsystem.c materials.c drudeparam_data.c)
@ -25,3 +25,7 @@ target_link_libraries (qpms
amos amos
) )
target_include_directories (qpms PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories (qpms PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install(TARGETS qpms
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

View File

@ -1,7 +1,21 @@
from pkg_resources import get_distribution from pkg_resources import get_distribution
__version__ = get_distribution('qpms').version __version__ = get_distribution('qpms').version
from .qpms_c import PointGroup, FinitePointGroup, FinitePointGroupElement, Particle, scatsystem_set_nthreads, ScatteringSystem, ScatteringMatrix import os as __os
from sys import platform as __platform
import warnings as __warnings
try:
from .qpms_c import PointGroup, FinitePointGroup, FinitePointGroupElement, Particle, scatsystem_set_nthreads, ScatteringSystem, ScatteringMatrix
except ImportError as ex:
if __platform == "linux" or __platform == "linux2":
if 'LD_LIBRARY_PATH' not in __os.environ.keys():
__warnings.warn("Environment variable LD_LIBRARY_PATH has not been set. Make it point to a directory where you installed libqpms and run python again")
else:
__warnings.warn("Does your LD_LIBRARY_PATH include a directory where you installed libqpms? Check and run python again."
'Currently, I see LD_LIBRARY_PATH="%s"' % __os.environ['LD_LIBRARY_PATH'])
raise ex
from .qpms_p import * from .qpms_p import *
from .cyquaternions import CQuat, IRot3 from .cyquaternions import CQuat, IRot3
from .cybspec import VSWFNorm, BaseSpec from .cybspec import VSWFNorm, BaseSpec

View File

@ -84,13 +84,13 @@ libqpms_sources = [
cycommon = Extension('qpms.cycommon', cycommon = Extension('qpms.cycommon',
sources = ['qpms/cycommon.pyx'], sources = ['qpms/cycommon.pyx'],
extra_link_args=['qpms/libqpms.a'], #extra_link_args=['qpms/libqpms.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
cytmatrices = Extension('qpms.cytmatrices', cytmatrices = Extension('qpms.cytmatrices',
sources = ['qpms/cytmatrices.pyx'], sources = ['qpms/cytmatrices.pyx'],
extra_link_args=['qpms/libqpms.a', 'amos/libamos.a'], #extra_link_args=['qpms/libqpms.a', 'amos/libamos.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
cytranslations = Extension('qpms.cytranslations', cytranslations = Extension('qpms.cytranslations',
sources = ['qpms/cytranslations.pyx', sources = ['qpms/cytranslations.pyx',
@ -99,34 +99,34 @@ cytranslations = Extension('qpms.cytranslations',
extra_compile_args=['-std=c99', extra_compile_args=['-std=c99',
'-DQPMS_COMPILE_PYTHON_EXTENSIONS', # This is needed to enable it in translations.h '-DQPMS_COMPILE_PYTHON_EXTENSIONS', # This is needed to enable it in translations.h
], ],
extra_link_args=['qpms/libqpms.a', 'amos/libamos.a'], #extra_link_args=['qpms/libqpms.a', 'amos/libamos.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
cybspec = Extension('qpms.cybspec', cybspec = Extension('qpms.cybspec',
sources = ['qpms/cybspec.pyx'], sources = ['qpms/cybspec.pyx'],
extra_link_args=['qpms/libqpms.a'], #extra_link_args=['qpms/libqpms.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
cymaterials = Extension('qpms.cymaterials', cymaterials = Extension('qpms.cymaterials',
sources = ['qpms/cymaterials.pyx'], sources = ['qpms/cymaterials.pyx'],
extra_link_args=['qpms/libqpms.a'], #extra_link_args=['qpms/libqpms.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
cyquaternions = Extension('qpms.cyquaternions', cyquaternions = Extension('qpms.cyquaternions',
sources = ['qpms/cyquaternions.pyx'], sources = ['qpms/cyquaternions.pyx'],
extra_link_args=['amos/libamos.a', 'qpms/libqpms.a'], #extra_link_args=['amos/libamos.a', 'qpms/libqpms.a'],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',] libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread',]
) )
qpms_c = Extension('qpms.qpms_c', qpms_c = Extension('qpms.qpms_c',
sources = [ sources = [
'qpms/qpms_c.pyx', 'qpms/qpms_c.pyx',
], ],
libraries=['gsl', 'lapacke', 'blas', 'gslcblas', 'pthread', #'omp' libraries=['qpms', 'gsl', 'lapacke', 'blas', 'gslcblas', 'pthread', #'omp'
#('amos', dict(sources=amos_sources) ), #('amos', dict(sources=amos_sources) ),
], ],
include_dirs=['amos', 'qpms'], include_dirs=['amos', 'qpms'],
extra_link_args=[ 'qpms/libqpms.a','amos/libamos.a', ], #extra_link_args=[ 'qpms/libqpms.a','amos/libamos.a', ],
#runtime_library_dirs=os.environ['LD_LIBRARY_PATH'].split(':') if 'LD_LIBRARY_PATH' in os.environ else [], #runtime_library_dirs=os.environ['LD_LIBRARY_PATH'].split(':') if 'LD_LIBRARY_PATH' in os.environ else [],
#extra_objects = ['amos/libamos.a'], # FIXME apparently, I would like to eliminate the need to cmake/make first #extra_objects = ['amos/libamos.a'], # FIXME apparently, I would like to eliminate the need to cmake/make first
) )