130 lines
3.9 KiB
Meson
130 lines
3.9 KiB
Meson
# meson build file based on https://numpy.org/doc/stable/f2py/buildtools/meson.html
|
|
# the phagen python module is built using numpy.f2py
|
|
|
|
# note when importing a new phagen version:
|
|
# in the phagen_scf.f file, replace "program phagen" with "subroutine phagen"
|
|
|
|
project('phagen', 'c', 'fortran',
|
|
version : '2.3',
|
|
meson_version: '>= 1.3',
|
|
default_options: [
|
|
'c_std=c99',
|
|
'cpp_std=c++14',
|
|
'fortran_std=legacy',
|
|
'python.install_env=auto',
|
|
'warning_level=2'
|
|
]
|
|
)
|
|
|
|
fs_mod = import('fs')
|
|
py_mod = import('python')
|
|
py3 = py_mod.find_installation('python3')
|
|
py3_dep = py3.dependency()
|
|
message(py3.full_path())
|
|
message(py3.get_install_dir())
|
|
|
|
# silence fortran warnings
|
|
ff = meson.get_compiler('fortran')
|
|
_global_ff_args = ff.get_supported_arguments(
|
|
'-fallow-argument-mismatch',
|
|
'-Wno-argument-mismatch',
|
|
'-Wno-compare-reals',
|
|
'-Wno-conversion',
|
|
'-Wno-do-subscript',
|
|
'-Wno-intrinsic-shadow',
|
|
'-Wno-line-truncation',
|
|
'-Wno-maybe-uninitialized',
|
|
'-Wno-return-type',
|
|
'-Wno-tabs',
|
|
'-Wno-unused-dummy-argument',
|
|
'-Wno-unused-label',
|
|
'-Wno-unused-parameter',
|
|
'-Wno-unused-variable',
|
|
)
|
|
add_project_arguments(_global_ff_args, language : 'fortran')
|
|
|
|
# silence c warnings
|
|
cc = meson.get_compiler('c')
|
|
_global_cc_args = cc.get_supported_arguments(
|
|
'-Wno-cast-function-type',
|
|
'-Wno-dangling-else',
|
|
'-Wno-format-extra-args',
|
|
'-Wno-implicit-function-declaration',
|
|
'-Wno-implicit-int',
|
|
'-Wno-int-in-bool-context',
|
|
'-Wno-maybe-uninitialized',
|
|
'-Wno-misleading-indentation',
|
|
'-Wno-missing-field-initializers',
|
|
'-Wno-return-type',
|
|
'-Wno-unused-result',
|
|
'-Wno-unused-variable',
|
|
'-Wno-unused-function',
|
|
'-Wno-unused-parameter',
|
|
'-Wno-write-strings',
|
|
)
|
|
add_project_arguments(_global_cc_args, language : 'c')
|
|
|
|
# work is in progress in the meson project to simplify dependency detection.
|
|
# as of november 2025, it seems to work for numpy but not for numpy.f2py.
|
|
# np_dep = dependency('numpy')
|
|
# np_dep = dependency('numpy', modules: 'f2py')
|
|
# cf. https://github.com/mesonbuild/meson/issues/9598
|
|
|
|
# the following is adapted from scipy
|
|
# https://github.com/scipy/scipy/blob/beb6b2fbe656eae47b117fa8c416cdd88c27c98e/scipy/meson.build
|
|
|
|
_incdir_numpy_abs = run_command(py3,
|
|
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
|
|
check : true
|
|
).stdout().strip()
|
|
incdir_numpy = fs_mod.relative_to(_incdir_numpy_abs, '.')
|
|
inc_np = include_directories(incdir_numpy)
|
|
numpy_nodepr_api = ['-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION']
|
|
np_dep = declare_dependency(include_directories: inc_np, compile_args: numpy_nodepr_api)
|
|
|
|
incdir_f2py = run_command(py3,
|
|
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
|
|
check : true
|
|
).stdout().strip()
|
|
incdir_f2py = fs_mod.relative_to(incdir_f2py, '.')
|
|
inc_f2py = include_directories(incdir_f2py)
|
|
fortranobject_c = incdir_f2py / 'fortranobject.c'
|
|
|
|
fortranobject_lib = static_library('_fortranobject',
|
|
fortranobject_c,
|
|
c_args: numpy_nodepr_api,
|
|
dependencies: py3_dep,
|
|
include_directories: [inc_np, inc_f2py],
|
|
gnu_symbol_visibility: 'hidden',
|
|
)
|
|
fortranobject_dep = declare_dependency(
|
|
link_with: fortranobject_lib,
|
|
include_directories: [inc_np, inc_f2py],
|
|
)
|
|
|
|
f2py = find_program('f2py')
|
|
|
|
wrapper = custom_target('phagenmodule.c',
|
|
input : ['src/phagen_scf.f'],
|
|
depend_files : ['src/msxas3.inc', 'src/msxasc3.inc'],
|
|
output : ['phagenmodule.c', 'phagen-f2pywrappers.f'],
|
|
command : [py3, '-m', 'numpy.f2py', '@INPUT@', '--verbose', '-m', 'phagen', '--build-dir', '@OUTDIR@', 'only:', 'phagen']
|
|
)
|
|
|
|
source = ['src/phagen_scf.f', wrapper]
|
|
|
|
phagen_lib = py3.extension_module('phagen',
|
|
source,
|
|
include_directories: ['src'],
|
|
dependencies : [py3_dep, np_dep, fortranobject_dep],
|
|
link_language: 'fortran',
|
|
install : true
|
|
)
|
|
|
|
phagen_dep = declare_dependency(
|
|
dependencies : py3_dep,
|
|
link_with : phagen_lib,
|
|
)
|
|
|
|
test('phagen', py3, args : ['-c', 'from phagen import phagen; exit(0)'])
|