From e1d6e26cafac7199c003000210e74374c4486de1 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Tue, 12 Oct 2021 09:30:36 +0200 Subject: [PATCH] Add support for meson build system --- CMakeLists.txt | 9 ++++++- VERSION | 1 + cmake/install-mod.py | 32 ++++++++++++++++++++++ lib/meson.build | 63 ++++++++++++++++++++++++++++++++++++++++++++ meson.build | 32 ++++++++++++++++++++++ test/meson.build | 22 ++++++++++++++++ 6 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 VERSION create mode 100644 cmake/install-mod.py create mode 100644 lib/meson.build create mode 100644 meson.build create mode 100644 test/meson.build diff --git a/CMakeLists.txt b/CMakeLists.txt index 8de8fc7..13c4c3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..9084fa2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1.0 diff --git a/cmake/install-mod.py b/cmake/install-mod.py new file mode 100644 index 0000000..34f7278 --- /dev/null +++ b/cmake/install-mod.py @@ -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) + diff --git a/lib/meson.build b/lib/meson.build new file mode 100644 index 0000000..db50325 --- /dev/null +++ b/lib/meson.build @@ -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: '@BASENAME@.f90', + ) +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 diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..19d724c --- /dev/null +++ b/meson.build @@ -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') diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..eb813e3 --- /dev/null +++ b/test/meson.build @@ -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_@0@.f90'.format(t)), + dependencies: mpifx_dep, + ) +endforeach