Skip to content

Commit

Permalink
Add a Meson build system (#8)
Browse files Browse the repository at this point in the history
* Add a Meson build system

* Remove obsolete files

* [CirrusCI] Install SIFDecode in a local folder

* [CI] Add the Intel compilers

* Only test Intel compilers on Mac and Linux

* Allow an older version of Meson

* [Meson] Update the version number

* Release 2.1.0

* Update the version number in the main meson.build
  • Loading branch information
amontoison committed Feb 12, 2024
1 parent daaecf5 commit d88115c
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 5,204 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 --prefix=${CIRRUS_WORKING_DIR}/../meson
else
FC=gfortran-12 CC=gcc-12 CXX=g++-12 meson setup builddir --prefix=${CIRRUS_WORKING_DIR}/../meson
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,3 @@ jobs:
$SIFDECODE/bin/sifdecoder -A ${{ matrix.arch }} ROSENBR.SIF
# check that all output files exist (EXTER.f may not exist)
[[ -s "OUTSDIF.d" && -s "AUTOMAT.d" && -s "RANGE.f" && -s "ELFUN.f" && -s "GROUP.f" ]] || exit 1
95 changes: 95 additions & 0 deletions .github/workflows/meson.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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
- os: ubuntu-latest
compiler: intel
compiler_version: 2021.9.0
fc_cmd: ifort
- os: macos-latest
compiler: intel
compiler_version: 2021.9.0
fc_cmd: ifort
- os: ubuntu-latest
compiler: intel-llvm
compiler_version: 2023.2.0
fc_cmd: ifx
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/*
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: '2024.2.11',
meson_version: '>= 0.61.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')]]
Loading

0 comments on commit d88115c

Please sign in to comment.