-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from peter-urban/add_meson_build
add a meson.build file, tests and update the README.MD
- Loading branch information
Showing
8 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: pre-commit | |
on: | ||
pull_request: | ||
push: | ||
branches: [master] | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: test meson wrapper | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
run: | ||
name: lib${{ matrix.library }} ${{ matrix.compiler }} ${{ matrix.os }} ${{ matrix.force_cpp }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
library: ["static", "shared"] | ||
compiler: ["gcc", "clang", "cl", "clang-cl"] | ||
force_cpp: [-Dforce-cpp=enabled, ""] | ||
os: [windows-latest, ubuntu-latest, macos-latest] | ||
exclude: | ||
- os: windows-latest | ||
compiler: "clang" | ||
- os: windows-latest | ||
compiler: "gcc" | ||
- os: windows-latest | ||
force_cpp: "-Dforce-cpp=enabled" | ||
- os: ubuntu-latest | ||
compiler: "cl" | ||
- os: ubuntu-latest | ||
compiler: "clang-cl" | ||
- os: macos-latest | ||
compiler: "cl" | ||
- os: macos-latest | ||
compiler: "clang-cl" | ||
|
||
fail-fast: false | ||
|
||
env: | ||
CC: ${{matrix.compiler}} | ||
CXX: ${{matrix.compiler}} | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ilammy/msvc-dev-cmd@v1 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.x | ||
|
||
- name: install dependencies | ||
run: python -m pip install meson ninja | ||
|
||
- name: Compile | ||
run: | | ||
meson setup builddir -Ddefault_library=${{matrix.library}} ${{matrix.force_cpp}} | ||
meson compile -C builddir | ||
- name: Test | ||
run: | | ||
meson test -C builddir --print-errorlogs -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
|
||
# SPDX-FileCopyrightText: 2024 Peter Urban | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
# 'TEOS-10 V3.06.16-0 GSW Oceanographic Toolbox in C' | ||
# 'http://teos-10.org' | ||
|
||
# --- Project --- | ||
# Define project meta data | ||
project( | ||
'gswteos-10', | ||
['c', 'cpp'], #language is c on linux/mac and cpp on windows | ||
license: 'BSD-3-Clause', | ||
|
||
version: 'v3.06.16-0', | ||
default_options: ['warning_level=2', 'buildtype=release'], | ||
meson_version: '>=1.5.1' #latest tested version,,,, | ||
) | ||
|
||
project_name = 'gswteos-10' | ||
description = 'TEOS-10 V3.06.16-0 GSW Oceanographic Toolbox in C' | ||
url = 'http://teos-10.org' | ||
|
||
# --- dependencies --- | ||
# libm (math library) | ||
# Required is set to false because libm is only necessary and available if | ||
# it is not already included in the compiler (e.g. gcc/linux) | ||
cc = meson.get_compiler('c') | ||
m_dep = cc.find_library('m', required: false) | ||
|
||
# --- compile options --- | ||
c_compile_args = [] | ||
cpp_compile_args = [] | ||
|
||
# Force compile language to be c++ on windows (cl and clang-cl) (or if force-cpp option is enabled) | ||
link_language = 'c' | ||
if cc.get_id() == 'cl' or cc.get_id() == 'msvc' or cc.get_id() == 'clang-cl' | ||
message('Setting /Tp flag to interpret c files as c++ files on windows') | ||
cpp_compile_args += ['/TP'] #interpret c files as c++ files on windows | ||
c_compile_args += ['/TP'] #interpret c files as c++ files on windows | ||
link_language = 'cpp' | ||
elif get_option('force-cpp').enabled() | ||
if cc.get_id() == 'gcc' or cc.get_id() == 'clang' | ||
c_compile_args += ['-xc++'] | ||
else | ||
error('Unhandled compiler id: ' + cc.get_id() + '! Cannot enable option force-cpp') | ||
endif | ||
endif | ||
|
||
# --- sources --- | ||
program_sources = ['gsw_check_functions.c'] | ||
|
||
library_sources = [ | ||
'gsw_oceanographic_toolbox.c', | ||
'gsw_saar.c', | ||
] | ||
|
||
export_headers = ['gswteos-10.h'] | ||
|
||
# --- define library and dependencies --- | ||
gswteos_10_lib = library( | ||
project_name, | ||
library_sources, | ||
c_args: c_compile_args, | ||
cpp_args: cpp_compile_args, | ||
dependencies: [m_dep], | ||
link_language: link_language, | ||
install: true, | ||
) | ||
|
||
gswteos_10_dep = declare_dependency( | ||
dependencies: [m_dep], | ||
link_with: [gswteos_10_lib], | ||
include_directories: include_directories('.'), | ||
) | ||
|
||
# --- Installation --- | ||
# install headers | ||
install_headers(export_headers) | ||
|
||
# pkgconfig file | ||
pkg = import('pkgconfig') | ||
pkg.generate( | ||
description: description, | ||
url: url, | ||
version: meson.project_version(), | ||
name: project_name, | ||
libraries: gswteos_10_lib, | ||
) | ||
|
||
# --- define tests --- | ||
gswteos_10_exe = executable( | ||
'gsw_check', | ||
sources: [program_sources], | ||
dependencies: [gswteos_10_dep], | ||
c_args: c_compile_args, | ||
cpp_args: cpp_compile_args, | ||
link_language: link_language, | ||
) | ||
|
||
test('run_gsw_check', gswteos_10_exe) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
option('force-cpp', type: 'feature', value: 'disabled', description: 'If enabled, C files will be compiled as C++') |