Skip to content

Commit

Permalink
build multiple extension; remove bmiheat dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Mar 11, 2024
1 parent b7f33b6 commit ec29a4b
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions babelizer/data/{{cookiecutter.package_name}}/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ project(
version: '{{ cookiecutter.package_version }}',
)

py = import('python').find_installation(pure: false)

{%- if cookiecutter.language == 'c' %}
lang = 'c'
bmilib = 'bmiheatc'
compiler = meson.get_compiler('c')
{%- elif cookiecutter.language == 'c++' %}
lang = 'cpp'
bmilib = 'bmiheatcxx'
compiler = meson.get_compiler('cpp')
{%- elif cookiecutter.language == 'fortran' %}
lang = 'fortran'
bmilib = 'bmiheatf'
compiler = meson.get_compiler('fortran')
{%- endif %}

py = import('python').find_installation(pure: false)

compiler = meson.get_compiler(lang)

# python_inc = py.get_path('data') / 'include'
numpy_inc = run_command(
py,
Expand All @@ -43,26 +38,13 @@ incs = include_directories(
]
)

{% set babelized_class = cookiecutter.components|list|first -%}
# babelized_class = {{ babelized_class }}

{% set dependency_list = cookiecutter.package_requirements.split(',') -%}
deps = [
{%- if cookiecutter.language in ['c', 'c++', 'fortran'] %}
dependency(bmilib, method : 'pkg-config'),
{% endif %}
{%- for dependency in dependency_list if dependency != '' %}
compiler.find_library('{{ dependency }}'),
{%- endfor %}
]

srcs = [
{%- if cookiecutter.language == 'fortran' %}
'{{ cookiecutter.package_name }}/lib/bmi_interoperability.f90',
{%- endif %}
'{{ 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',
Expand All @@ -73,24 +55,31 @@ py.install_sources(
install_pkg_srcs,
subdir: '{{ cookiecutter.package_name }}',
)

install_lib_srcs = [
'{{ cookiecutter.package_name }}/lib/__init__.py',
{%- for babelized_class in cookiecutter.components|list|sort %}
'{{ cookiecutter.package_name }}/lib/{{ babelized_class|lower }}.pyx',
{%- endfor %}
]
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',
)

{%- for babelized_class, component in cookiecutter.components|dictsort %}
py.extension_module(
'{{ babelized_class|lower }}',
srcs,
dependencies: deps,
[
{%- if cookiecutter.language == 'fortran' %}
'{{ cookiecutter.package_name }}/lib/bmi_interoperability.f90',
{%- endif %}
'{{ cookiecutter.package_name }}/lib/{{ babelized_class|lower }}.pyx',
],
dependencies: [
dependency('{{ component.library }}', method : 'pkg-config'),
],
include_directories: incs,
install: true,
subdir: '{{ cookiecutter.package_name }}/lib',
Expand All @@ -99,5 +88,12 @@ py.extension_module(
{%- endif %}
)

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

{%- endfor %}

# This is a temporary fix for editable installs.
run_command('cp', '-r', '{{ cookiecutter.package_name }}/data', 'build')

0 comments on commit ec29a4b

Please sign in to comment.