|
| 1 | +project('tdscha', |
| 2 | + ['c'], |
| 3 | + version: '1.5.0', |
| 4 | + license: 'GPL', |
| 5 | + meson_version: '>= 1.1.0', # <- set min version of meson. |
| 6 | + default_options : [ |
| 7 | + 'warning_level=1', |
| 8 | + 'buildtype=release', |
| 9 | + 'c_args=-O2' |
| 10 | + ] |
| 11 | + ) |
| 12 | + |
| 13 | +# --- Compilation options --- |
| 14 | +use_mkl = get_option('use_mkl') |
| 15 | + |
| 16 | +# --- System and Python Dependencies --- |
| 17 | +# Find the necessary installations |
| 18 | +py = import('python').find_installation(pure: false) |
| 19 | +py_dep = py.dependency() |
| 20 | +cc = meson.get_compiler('c') |
| 21 | + |
| 22 | +# Additional dependencies |
| 23 | + |
| 24 | +# The LAPACK and BLAS libraries are essential for Fortran matrix operations. |
| 25 | +#lapack_dep = dependency('lapack') |
| 26 | +#blas_dep = dependency('blas') |
| 27 | +openblas_dep = dependency('openblas', required: false) |
| 28 | +if use_mkl |
| 29 | + mkl_dep = dependency('mkl', required: true) |
| 30 | + blas_dep = mkl_dep |
| 31 | + lapack_dep = mkl_dep |
| 32 | +else |
| 33 | + lapack_dep = dependency('lapack', required: true) |
| 34 | + blas_dep = dependency('blas', required: true) |
| 35 | +endif |
| 36 | + |
| 37 | +# The openmp dependency is necessary |
| 38 | +openmp_dep = dependency('openmp', required: true) |
| 39 | + |
| 40 | +# --- MPI Detection --- |
| 41 | +# This overrides the logic in os.environ["MPICC"] and os.popen("%s -show" % mpicc). |
| 42 | +# Meson has a built-in MPI module. |
| 43 | +mpi_args = [] |
| 44 | +mpi_link_args = [] |
| 45 | +mpi_compile_args = [] |
| 46 | +has_mpi = false |
| 47 | + |
| 48 | +# Attempts to find the MPI dependency. |
| 49 | +# You can specify a specific MPI compiler with the 'mpi_compiler' parameter |
| 50 | +# or, if you want, a specific Fortran compiler with 'mpi_fortran_compiler'. |
| 51 | +# For OpenMPI, IntelMPI, MPICH, etc., Meson usually finds it automatically. |
| 52 | +#mpi_dep = dependency('mpi', required: false, language: ['c', 'fortran']) |
| 53 | +mpi_dep = dependency('mpi', required: false) |
| 54 | + |
| 55 | +if mpi_dep.found() |
| 56 | + message('MPI environment detected correctly.') |
| 57 | + has_mpi = true |
| 58 | + # Meson handles adding appropriate flags. We just add the define. |
| 59 | + # If you need specific MPI flags beyond what Meson adds automatically, |
| 60 | + # you can get them via mpi_dep.get_compile_args() and mpi_dep.get_link_args() |
| 61 | + # and add them to extra_compile_args/extra_link_args. |
| 62 | + mpi_compile_args += ['-D_MPI'] |
| 63 | +else |
| 64 | + # Here you can add warning logic if MPI is not found. |
| 65 | + # Meson prints a warning if required: true and it is not found. |
| 66 | + # For required: false, you can print your own warning. |
| 67 | + warning('No MPI compiler found, please ensure MPI is installed and configured.') |
| 68 | + warning('If you wish to activate MPI acceleration, consider setting MPICC environment variable or providing Meson with appropriate flags.') |
| 69 | +endif |
| 70 | + |
| 71 | +# --- NUMPY CONFIGURATION --- |
| 72 | +# Gets the path to the NumPy and f2py header directories using the Python command |
| 73 | +incdir_numpy = run_command(py, |
| 74 | + ['-c', 'import numpy; print(numpy.get_include())'], |
| 75 | + check : true |
| 76 | +).stdout().strip() |
| 77 | + |
| 78 | +# f2py also requires the fortranobject.h header |
| 79 | +incdir_f2py = run_command(py, |
| 80 | + ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], |
| 81 | + check : true |
| 82 | +).stdout().strip() |
| 83 | + |
| 84 | +inc_np = include_directories(incdir_numpy, incdir_f2py) |
| 85 | +np_dep = declare_dependency(include_directories: inc_np) |
| 86 | + |
| 87 | +# --- END OF NUMPY CONFIGURATION --- |
| 88 | +if openblas_dep.found() |
| 89 | + message('openblas environment detected correctly.') |
| 90 | + list_dep = [py_dep, mpi_dep, openblas_dep, lapack_dep, blas_dep] |
| 91 | +else |
| 92 | + warning('No openblas found.') |
| 93 | + list_dep = [py_dep, mpi_dep, lapack_dep, blas_dep] |
| 94 | +endif |
| 95 | +# --- Definition of each Python extension (Fortran) --- |
| 96 | + |
| 97 | +# 'symph' extension |
| 98 | + |
| 99 | +# Compilation of the Fortran module: symph |
| 100 | +sources_cfiles = ['CModules/odd_corr_module.c', 'CModules/LanczosFunctions.c'] |
| 101 | + |
| 102 | +py.extension_module('sscha_HP_odd', |
| 103 | + sources_cfiles, |
| 104 | + include_directories: inc_np, |
| 105 | + dependencies: list_dep, |
| 106 | +# link_args: ['-L' + py.get_install_dir() / 'numpy' / 'f2py' / 'src' / 'fortranobject.c', '-lfortranobject'], |
| 107 | + install: true |
| 108 | +) |
| 109 | + |
| 110 | +# --- Installation of the 'cellconstructor' Python package --- |
| 111 | +#install_data( |
| 112 | +# 'cellconstructor/__init__.py', 'cellconstructor/AnharmonicForceFields.py', 'cellconstructor/calculators.py', |
| 113 | +# 'cellconstructor/Methods.py', 'cellconstructor/Phonons.py', 'cellconstructor/Spectral.py', |
| 114 | +# 'cellconstructor/ThermalConductivity.py', 'cellconstructor/Units.py', 'cellconstructor/Bands.py', |
| 115 | +# 'cellconstructor/ForceTensor.py', 'cellconstructor/Manipulate.py', 'cellconstructor/Moro_object.py', |
| 116 | +# 'cellconstructor/Settings.py', 'cellconstructor/Structure.py', 'cellconstructor/symmetries.py', |
| 117 | +# 'cellconstructor/Timer.py', |
| 118 | +# install_dir: py.get_install_dir() / 'cellconstructor', |
| 119 | +#) |
| 120 | +py.install_sources( |
| 121 | + [ |
| 122 | + 'Modules/__init__.py', |
| 123 | + 'Modules/DynamicalLanczos.py', |
| 124 | + 'Modules/Dynamical.py', |
| 125 | + 'Modules/Parallel.py', |
| 126 | + 'Modules/Perturbations.py', |
| 127 | + 'Modules/StaticHessian.py', |
| 128 | + 'Modules/tdscha_core.jl', |
| 129 | + 'Modules/Tools.py' |
| 130 | + ], |
| 131 | + subdir: 'tdscha' |
| 132 | +) |
| 133 | + |
| 134 | +install_data( |
| 135 | + 'Modules/tdscha_core.jl', |
| 136 | + install_dir: py.get_install_dir() / 'Modules' |
| 137 | +) |
| 138 | + |
| 139 | +# --- Installation of executable scripts --- |
| 140 | +py.install_sources([ |
| 141 | + 'scripts/plot_hessian_convergence.py', |
| 142 | + 'scripts/tdscha-convergence-analysis.py', |
| 143 | + 'scripts/tdscha-output2abc.py', |
| 144 | + 'scripts/tdscha-plot.py' |
| 145 | +]) |
| 146 | + |
| 147 | +# Set the tests by pytest. |
| 148 | +pytest_exe = find_program('pytest', required: false) |
| 149 | + |
| 150 | +if pytest_exe.found() |
| 151 | + test('pytest', pytest_exe, |
| 152 | + args : ['-v'], |
| 153 | + workdir : meson.project_source_root() |
| 154 | + ) |
| 155 | +else |
| 156 | + message('pytest not found; pytest tests are skipped.') |
| 157 | +endif |
0 commit comments