Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,50 @@ jobs:
- name: Run sample demo
run: python3 `which scons` test-clib-demo --debug=time

meson-build:
name: Meson build system test
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v6
name: Checkout the repository
with:
submodules: false
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@v6

Check failure

Code scanning / zizmor

unpinned action reference

unpinned action reference
with:
python-version: '3.13'
architecture: x64
- name: Install Apt dependencies
run: |
sudo apt update

Check failure

Code scanning / zizmor

unpinned action reference

unpinned action reference
sudo apt install -y meson ninja-build libboost-dev libeigen3-dev \
libsundials-dev libhdf5-dev libfmt-dev libyaml-cpp-dev
- name: Configure with Meson
run: meson setup builddir
- name: Compile with Meson
run: meson compile -C builddir
- name: Show build summary
run: |
echo "Meson build completed successfully!"
echo "Build directory contents:"
ls -lh builddir/src/
- name: Report Meson build status
if: always()
run: |
if [ -f builddir/build.ninja ]; then
echo "✓ Meson configuration successful"
else
echo "✗ Meson configuration failed"
fi
if [ -f builddir/src/libcantera.so* ]; then
echo "✓ Cantera library built successfully"
ls -lh builddir/src/libcantera.so*
else
echo "⚠ Cantera library not found (build may be partial)"
fi

macos-multiple-pythons:
name: ${{ matrix.macos-version }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.macos-version }}
Expand Down
133 changes: 133 additions & 0 deletions MESON_BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Meson Build System for Cantera

This directory contains the Meson build configuration for Cantera's C++ library.

## Status

The Meson build system builds the complete C++ library using system-installed dependencies only.

## Quick Start

### Prerequisites

- Meson >= 1.0.0
- Ninja build system
- C++20 compatible compiler (GCC, Clang, or MSVC)
- System dependencies (all required):
- Eigen3 >= 3.4
- Boost >= 1.83
- fmt >= 9.1.0
- yaml-cpp >= 0.6
- SUNDIALS >= 6.0 (cvodes, idas, nvecserial)
- Optional: HDF5, BLAS/LAPACK, HighFive

### Building

1. Configure the build:
```bash
meson setup builddir
```

2. Compile:
```bash
meson compile -C builddir
```

3. Install (optional):
```bash
meson install -C builddir
```

## Dependencies

All dependencies must be installed as system packages. The Meson build does not support fallback to bundled libraries in ext/ submodules.

### Required System Packages

- **Boost** (>= 1.83): Header-only library
- **Eigen3** (>= 3.4): Header-only library for linear algebra
- **fmt** (>= 9.1.0): Formatting library
- **yaml-cpp** (>= 0.6): YAML parser/emitter
- **SUNDIALS** (>= 6.0): ODE/DAE solvers (cvodes, idas, nvecserial components required)

### Optional System Packages

- **HDF5**: For HDF5 data file support
- **BLAS/LAPACK**: For optimized linear algebra (falls back to Eigen if not available)
- **HighFive**: C++ wrapper for HDF5 (required if HDF5 support is desired)

## Configuration Options

- `cantera_datadir`: Directory for Cantera data files (default: `prefix/share/cantera/data`)

Example:
```bash
meson setup builddir -Dcantera_datadir=/opt/cantera/data
```

## Build Features

### Automatic Source Discovery

The Meson build automatically discovers source files using glob patterns, similar to how SCons uses `multi_glob()`:

```meson
# Automatically find all .cpp files in each module directory
base_files = run_command(find, 'base', '-name', '*.cpp', ...)
foreach f : base_files
base_sources += files('base' / f)
endforeach
```

This eliminates the need to manually list individual source files.

### Installation

On Ubuntu/Debian:
```bash
sudo apt install meson ninja-build libboost-dev libeigen3-dev \
libfmt-dev libyaml-cpp-dev libsundials-dev
```

On macOS with Homebrew:
```bash
brew install meson ninja boost eigen fmt yaml-cpp sundials
```

On Fedora/RHEL:
```bash
sudo dnf install meson ninja-build boost-devel eigen3-devel \
fmt-devel yaml-cpp-devel sundials-devel
```

## Known Limitations

1. **No Python bindings**: Only C++ library is currently supported
2. **No Fortran interface**: F90 interface not yet implemented
3. **Limited testing**: Build system needs more testing across platforms
4. **System packages required**: No support for bundled ext/ submodules

## Comparison with SCons

The Meson build aims to eventually replace the SCons build system with these benefits:
- Faster build times with better parallelization
- Better IDE integration
- Standard pkg-config support
- Simpler dependency management (system packages only)
- Cross-compilation support
- **Automatic source discovery** like SCons `multi_glob()`

## Contributing

Contributions are welcome to:
- Add Python bindings support
- Add testing infrastructure
- Port more configuration options from SCons
- Test on more platforms

## Files

- `meson.build`: Root build configuration
- `meson_options.txt`: Build options
- `src/meson.build`: C++ source compilation with automatic file discovery
- `include/cantera/base/config.h.meson.in`: Configuration header template
2 changes: 1 addition & 1 deletion ext/fmt
Submodule fmt updated 210 files
2 changes: 1 addition & 1 deletion ext/yaml-cpp
Submodule yaml-cpp updated 393 files
56 changes: 56 additions & 0 deletions include/cantera/base/config.h.meson.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef CT_CONFIG_H
#define CT_CONFIG_H

//---------------------------- Version Flags ------------------//
// Cantera version -> this will be a double-quoted string value
@CANTERA_VERSION@

// Just the major + minor version (that is, 2.2 instead of 2.2.0)
@CANTERA_SHORT_VERSION@

//------------------------ Fortran settings -------------------//

// define types doublereal, integer, and ftnlen to match the
// corresponding Fortran data types on your system. The defaults
// are OK for most systems

typedef double doublereal; // Fortran double precision
typedef int integer; // Fortran integer
typedef int ftnlen; // Fortran hidden string length type

// Fortran compilers pass character strings in argument lists by
// adding a hidden argument with the length of the string. Some
// compilers add the hidden length argument immediately after the
// CHARACTER variable being passed, while others put all of the hidden
// length arguments at the end of the argument list. Define this if
// the lengths are at the end of the argument list. This is usually the
// case for most unix Fortran compilers, but is (by default) false for
// Visual Fortran under Windows.
#define STRING_LEN_AT_END

// Define this if Fortran adds a trailing underscore to names in object files.
// For linux and most unix systems, this is the case.
@FTN_TRAILING_UNDERSCORE@

//-------- LAPACK / BLAS ---------

@LAPACK_FTN_STRING_LEN_AT_END@
@LAPACK_FTN_TRAILING_UNDERSCORE@
@CT_USE_LAPACK@

@CT_USE_SYSTEM_EIGEN@
@CT_USE_SYSTEM_EIGEN_PREFIXED@
@CT_USE_SYSTEM_FMT@
@CT_USE_SYSTEM_YAMLCPP@

//-------------- Optional Cantera Capabilities ----------------------

// Enable Sundials to use an external BLAS/LAPACK library if it was
// built to use this option
@CT_SUNDIALS_USE_LAPACK@

// Enable export/import of HDF data via C++ HighFive
@CT_USE_HDF5@
@CT_USE_SYSTEM_HIGHFIVE@

#endif
1 change: 1 addition & 0 deletions include/cantera/ext/Eigen
1 change: 1 addition & 0 deletions include/cantera/ext/fmt
1 change: 1 addition & 0 deletions include/cantera/ext/yaml-cpp
Loading
Loading