Skip to content

Commit acf67a2

Browse files
committed
Added the meson
1 parent 4afd3f4 commit acf67a2

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed

meson.build

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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

meson.options

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# meson.options
2+
option('use_mkl', type: 'boolean', value: false,
3+
description: 'Use Intel Math Kernel Library (MKL) for BLAS/LAPACK')

pyproject.toml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# pyproject.toml
2+
3+
[build-system]
4+
# Declare the build backends and their dependencies that pip needs to build the project.
5+
# 'meson-python' is the backend that translates pip calls to Meson.
6+
# 'meson' is the actual build tool.
7+
# 'ninja' is the low-level build system that Meson uses by default for rapid compilation.
8+
requires = ["meson-python>=0.13.0", "meson>=1.1.0", "ninja>=1.10", "meson-python", "numpy>=1.20.0"]
9+
build-backend = "mesonpy"
10+
11+
[project]
12+
# Project metadata, which was previously in the `setup()` call of setup.py.
13+
name = "tdscha"
14+
version = "1.5.0" # Make sure this version matches meson.build
15+
description = "Time Dependent Self Consistent Harmonic Approximation"
16+
authors = [{name = "Lorenzo Monacelli"}]
17+
readme = "README.md"
18+
requires-python = ">=3.8" # The minimum version of Python supported by your project
19+
license = { text = "GPL" }
20+
21+
keywords = [ # Optional keywords to describe your package
22+
"crystallography",
23+
"phonons",
24+
"materials science",
25+
"quantum espresso",
26+
"ab initio"
27+
]
28+
29+
# Project runtime dependencies.
30+
# These are the dependencies that will be installed when someone runs `pip install cellconstructor`.
31+
dependencies = [
32+
"numpy",
33+
"ase",
34+
"scipy",
35+
"cellconstructor",
36+
"python-sscha"
37+
# If any of your Python extensions had an *additional* dependency
38+
# other than numpy, ase, or scipy (and not a system library like BLAS/LAPACK),
39+
# it would go here.
40+
]
41+
42+
[project.urls]
43+
Homepage = "https://sscha.eu/"
44+
Repository = "https://github.com/SSCHAcode/tdscha" # Puede ser el mismo que Homepage
45+
# Documentation = "https://documentacion.readthedocs.io/"
46+
Issues = "https://github.com/SSCHAcode/tdscha/issues"
47+
48+
49+
# --- Meson-python specific configuration (Optional but useful) ---
50+
[tool.meson-python]
51+
# Here you can pass options to Meson that control the build process.
52+
# For example, to enable debugging or specify a different installation path.
53+
# By default, meson-python takes care of using the virtual environment if it exists.
54+
55+
# build-args = ["-Dbuildtype=debug"] # Uncomment for a debug build
56+
# setup-args = ["--prefix=/opt/cellconstructor"] # For a non-standard installation

0 commit comments

Comments
 (0)