Skip to content

Commit

Permalink
Add support for meson build system
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk committed Oct 12, 2021
1 parent 41ef2c3 commit e1d6e26
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ include(MpiFxUtils)

include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)

project(MpiFx VERSION 1.1 LANGUAGES Fortran)
project(MpiFx LANGUAGES Fortran)

# Get version number from file
file (STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
list(GET VERSION_LIST 0 PROJECT_VERSION_MAJOR)
list(GET VERSION_LIST 1 PROJECT_VERSION_MINOR)
list(GET VERSION_LIST 2 PROJECT_VERSION_PATCH)

setup_build_type()

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.0
32 changes: 32 additions & 0 deletions cmake/install-mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# SPDX-Identifier: BSD-2-Clause

from os import environ, listdir, makedirs
from os.path import join, isdir, exists
from sys import argv
from shutil import copy

if "MESON_INSTALL_DESTDIR_PREFIX" in environ:
install_dir = environ["MESON_INSTALL_DESTDIR_PREFIX"]
else:
install_dir = environ["MESON_INSTALL_PREFIX"]

include_dir = argv[1] if len(argv) > 1 else "include"
build_dir = argv[2] if len(argv) > 2 else environ["MESON_BUILD_ROOT"]
module_dir = join(install_dir, include_dir)

modules = []
for d in listdir(build_dir):
bd = join(build_dir, d)
if isdir(bd):
for f in listdir(bd):
if f.endswith(".mod"):
modules.append(join(bd, f))

if not exists(module_dir):
makedirs(module_dir)

for mod in modules:
print("Installing", mod, "to", module_dir)
copy(mod, module_dir)

63 changes: 63 additions & 0 deletions lib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# SPDX-Identifier: BSD-2-Clause

sources_fpp = files(
'module.fpp',
'mpifx_abort.fpp',
'mpifx_allgather.fpp',
'mpifx_allgatherv.fpp',
'mpifx_allreduce.fpp',
'mpifx_barrier.fpp',
'mpifx_bcast.fpp',
'mpifx_comm.fpp',
'mpifx_common.fpp',
'mpifx_constants.fpp',
'mpifx_finalize.fpp',
'mpifx_gather.fpp',
'mpifx_gatherv.fpp',
'mpifx_get_processor_name.fpp',
'mpifx_helper.fpp',
'mpifx_init.fpp',
'mpifx_recv.fpp',
'mpifx_reduce.fpp',
'mpifx_scatter.fpp',
'mpifx_scatterv.fpp',
'mpifx_send.fpp',
)
sources_f90 = []
foreach src : sources_fpp
sources_f90 += configure_file(
command: ['fypp', '@INPUT@', '@OUTPUT@'],
input: src,
output: '@[email protected]',
)
endforeach

mpifx_lib = library(
meson.project_name(),
sources: sources_f90,
dependencies: mpi_dep,
install: install,
)

mpifx_inc = mpifx_lib.private_dir_include()
mpifx_dep = declare_dependency(
link_with: mpifx_lib,
include_directories: mpifx_inc,
dependencies: mpi_dep,
)

if install
module_id = meson.project_name()
meson.add_install_script(
'../cmake/install-mod.py',
get_option('includedir') / module_id,
meson.current_build_dir(),
)

pkg = import('pkgconfig')
pkg.generate(
mpifx_lib,
description: 'Modern Fortran Interface for MPI',
subdirs: ['', module_id],
)
endif
32 changes: 32 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-Identifier: BSD-2-Clause

project(
'mpifx',
'Fortran',
version: files('VERSION'),
license: 'BSD-2-Clause',
meson_version: '>=0.57.2',
default_options: [
'buildtype=debugoptimized',
'default_library=both',
],
)
install = not (meson.is_subproject() and get_option('default_library') == 'static')

# Prerequisites
mpi_dep = dependency('mpi', language: 'fortran')
fypp = find_program('fypp')

# Build instructions
subdir('lib')

mpifx_lic = files('LICENSE')

if install
install_data(
mpifx_lic,
install_dir: get_option('datadir')/'licenses'/meson.project_name()
)
endif

subdir('test')
22 changes: 22 additions & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-Identifier: BSD-2-Clause

tests = [
'allgather',
'allgatherv',
'allreduce',
'bcast',
'comm_split',
'gather',
'gatherv',
'reduce',
'scatter',
'scatterv',
]

foreach t : tests
executable(
'test_@0@'.format(t),
sources: files('test_@[email protected]'.format(t)),
dependencies: mpifx_dep,
)
endforeach

0 comments on commit e1d6e26

Please sign in to comment.