Skip to content

Commit

Permalink
Add a Meson build system
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Oct 14, 2023
1 parent 650c283 commit e6bd561
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 50 deletions.
30 changes: 30 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
task:
matrix:
- name: FreeBSD
freebsd_instance:
image: freebsd-13-2-release-amd64
- name: MacOS M1
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-base:latest
dependencies_script: |
echo $(uname)
if [ "$(uname)" = "FreeBSD" ]; then
pkg install -y py39-pip meson bash gcc12
else
brew install python meson gcc
fi
configure_script: |
if [ "$(uname -s)" = "FreeBSD" ]; then
FC=gfortran12 CC=gcc12 CXX=g++12 meson setup builddir
else
FC=gfortran-12 CC=gcc-12 CXX=g++-12 meson setup builddir
fi
build_script: |
meson compile -C builddir
install_script: |
meson install -C builddir
test_script: |
meson test -C builddir
on_failure:
log_artifacts:
path: builddir/meson-logs/*log.txt
83 changes: 83 additions & 0 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Meson
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: SIFDecode/${{ matrix.os }}/${{ matrix.fc_cmd }}/${{ matrix.compiler_version }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
compiler_version: [12]
include:
- compiler: gnu
fc_cmd: gfortran
runs-on: ${{ matrix.os }}
steps:
- name: Check out SIFDecode
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Meson and Ninja
run: pip install meson ninja

- name: Install GNU compilers
if: matrix.compiler == 'gnu'
uses: awvwgk/setup-fortran@main
with:
compiler: gcc
version: ${{ matrix.compiler_version }}

- name: Install classic Intel compilers
if: matrix.compiler == 'intel'
uses: awvwgk/setup-fortran@main
with:
compiler: intel-classic
version: ${{ matrix.compiler_version }}

- name: Install nextgen Intel compilers
if: matrix.compiler == 'intel-llvm'
uses: awvwgk/setup-fortran@main
with:
compiler: intel
version: ${{ matrix.compiler_version }}

# Uncomment this section to obtain ssh access to VM
# - name: Setup tmate session
# if: matrix.os == 'windows-latest'
# uses: mxschmitt/action-tmate@v3

- name: Setup SIFDecode
shell: bash
run: |
meson setup builddir --prefix=$GITHUB_WORKSPACE/../meson
env:
FC: ${{ matrix.fc_cmd }}

- name: Build SIFDecode
shell: bash
run: |
meson compile -C builddir
- uses: actions/upload-artifact@v3
if: failure()
with:
name: ${{ matrix.os }}_${{ matrix.fc_cmd }}_${{ matrix.compiler_version }}_meson-log.txt
path: builddir/meson-logs/meson-log.txt

- name: Install SIFDecode
shell: bash
run: |
meson install -C builddir
- uses: actions/upload-artifact@v3
if: failure()
with:
name: ${{ matrix.os }}_${{ matrix.fc_cmd }}_${{ matrix.compiler_version }}_install-log.txt
path: builddir/meson-logs/install-log.txt
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
objects/*
modules/*
versions/*
makefiles/*
bin/sys/*
50 changes: 0 additions & 50 deletions .travis.yml

This file was deleted.

27 changes: 27 additions & 0 deletions install_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
# Initially proposed by Sebastian Ehlert (@awvwgk)
from os import environ, listdir, makedirs, walk
from os.path import join, isdir, exists
from sys import argv
from shutil import copy

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

include_dir = "modules"
module_dir = join(install_dir, include_dir)

modules = []
# finds $build_dir/**/*.mod and $build_dir/**/*.smod
for root, dirs, files in walk(build_dir):
modules += [join(root, f) for f in files if f.endswith(".mod") or f.endswith(".smod")]

if not exists(module_dir):
makedirs(module_dir)

for mod in modules:
print("Installing", mod, "to", module_dir)
copy(mod, module_dir)
39 changes: 39 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
project(
'SIFDecode',
'fortran',
version: '2023.10.13',
meson_version: '>= 0.63.0',
default_options: [
'buildtype=release',
'libdir=lib',
'default_library=shared',
'warning_level=0',
],
)

libsifdecode_src = []
sifdecode_binaries = []

# Sources
subdir('src/check')
subdir('src/decode')
subdir('src/select')

# Library
libsifdecode = library('sifdecode',
sources : libsifdecode_src,
install : true)

# Binaries
foreach binary: sifdecode_binaries
binname = binary[0]
binfile = binary[1]
executable(binname,
sources : binfile,
link_with : libsifdecode,
install : true)
endforeach

# Fortran modules
script_modules = files('install_modules.py')
meson.add_install_script(script_modules)
2 changes: 2 additions & 0 deletions src/check/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
libsifdecode_src += files('check_derivs.f90', 'random.f90')
# sifdecode_binaries += [['check_derivs_main', files('check_derivs_main.f90')]]
2 changes: 2 additions & 0 deletions src/decode/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
libsifdecode_src += files('sifdecode.f90')
sifdecode_binaries += [['sifdecode_main', files('sifdecode_main.f90')]]
2 changes: 2 additions & 0 deletions src/select/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sifdecode_binaries += [['clsf', files('clsf.f')],
['slct', files('slct.f')]]

0 comments on commit e6bd561

Please sign in to comment.