Skip to content

Commit

Permalink
Set up Meson build for a single Fortran component
Browse files Browse the repository at this point in the history
This is WIP, but the project files are in the right place.
  • Loading branch information
mdpiper committed Mar 5, 2024
1 parent 08170fa commit 78aaec3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
70 changes: 70 additions & 0 deletions babelizer/data/{{cookiecutter.package_name}}/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
project('{{ cookiecutter.package_name }}', '{{ cookiecutter.language }}', 'cython', version: '{{ cookiecutter.package_version }}')

py = import('python').find_installation(pure: false)
fc = meson.get_compiler('fortran')

python_inc = py.get_path('data') / 'include'
numpy_inc = run_command(
py,
[
'-c',
'import numpy; print(numpy.get_include())'
],
check: true
).stdout().strip()
incs = include_directories(
[
'{{ cookiecutter.package_name }}/lib',
python_inc,
numpy_inc,
]
)

deps = [
fc.find_library('bmif'),
fc.find_library('heatf'),
fc.find_library('bmiheatf'),
]

{# This is temporary until I figure out how to do multiple components. #}
{%- set babelized_class = 'HeatModelF' -%}

srcs = [
'{{ cookiecutter.package_name }}/lib/bmi_interoperability.f90',
'{{ cookiecutter.package_name }}/lib/{{ babelized_class|lower }}.pyx',
]

# Files get copied to <python directory>/site-packages/<subdir>
install_pkg_srcs = [
'{{ cookiecutter.package_name }}/__init__.py',
'{{ cookiecutter.package_name }}/_bmi.py',
]
py.install_sources(
install_pkg_srcs,
subdir: '{{ cookiecutter.package_name }}',
)
install_lib_srcs = [
'{{ cookiecutter.package_name }}/lib/__init__.py',
'{{ cookiecutter.package_name }}/lib/{{ babelized_class|lower }}.pyx',
]
py.install_sources(
install_lib_srcs,
subdir: '{{ cookiecutter.package_name }}/lib',
)

install_subdir(
'meta/{{ babelized_class }}',
install_dir: py.get_install_dir() / '{{ cookiecutter.package_name }}/data',
)

py.extension_module(
'{{ babelized_class|lower }}',
srcs,
dependencies: deps,
include_directories: incs,
install: true,
subdir: '{{ cookiecutter.package_name }}/lib',
)

# This is a temporary fix for editable installs.
run_command('cp', '-r', '{{ cookiecutter.package_name }}/data', 'build')
6 changes: 5 additions & 1 deletion babelizer/data/{{cookiecutter.package_name}}/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-system]
requires = ["cython", "numpy", "setuptools", "wheel"]
build-backend = "mesonpy"
requires = ["cython", "numpy", "meson-python", "wheel"]

[project]
name = "{{cookiecutter.package_name}}"
Expand Down Expand Up @@ -39,6 +40,9 @@ homepage = "https://github.com/{{ cookiecutter.info.github_username }}/{{ cookie

[project.optional-dependencies]
dev = [
"meson",
"meson-python",
"ninja",
"nox",
]
docs = [
Expand Down

0 comments on commit 78aaec3

Please sign in to comment.