Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,56 @@
- 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: recursive
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: Initialize submodules for bundled dependencies
run: |
# Initialize fmt and yaml-cpp in case system versions are too old
git submodule update --init --depth=1 ext/fmt ext/yaml-cpp
# Create compatibility symlink for fmt
cd ext/fmt/include/fmt && ln -sf ranges.h join.h
- 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
128 changes: 128 additions & 0 deletions MESON_BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Meson Build System for Cantera

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

## Status

The Meson build system is under development and currently builds most of the C++ library (~60% of targets). The build is blocked by the SUNDIALS dependency which needs to be added as a subproject or installed system-wide.

## Quick Start

### Prerequisites

- Meson >= 1.0.0
- Ninja build system
- C++20 compatible compiler (GCC, Clang, or MSVC)
- System dependencies:
- Eigen3 >= 3.4 (or will use ext/eigen submodule)
- Boost >= 1.83 (required, must be system-installed)
- Optional: HDF5, BLAS/LAPACK

### Building

1. Initialize required submodules:
```bash
git submodule update --init ext/fmt ext/yaml-cpp
```

2. Create a compatibility symlink for fmt (required for older fmt references):
```bash
cd ext/fmt/include/fmt && ln -s ranges.h join.h
```

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

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

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

## Dependencies

### Required
- **Boost** (>= 1.83): Header-only, must be system-installed
- **Eigen3** (>= 3.4): Uses system if available, otherwise ext/eigen submodule
- **fmt** (>= 9.1.0): Uses system if available, otherwise ext/fmt (header-only mode)
- **yaml-cpp** (>= 0.6): Uses system if available, otherwise auto-discovers and builds from ext/yaml-cpp

### For Full Build (including numerics module)
- **SUNDIALS** (>= 6.0): Required for ODE/DAE integration. Currently requires system installation (e.g., `libsundials-dev` on Ubuntu). Without SUNDIALS, builds ~60% of C++ library (all modules except numerics).

### Optional
- **HDF5**: For HDF5 data file support
- **BLAS/LAPACK**: For optimized linear algebra (falls back to Eigen)
- **HighFive**: C++ wrapper for HDF5

## 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.

### Dependency Management

Dependencies are tried in order:
1. **System packages** (via pkg-config/CMake)
2. **Bundled sources** (from ext/ submodules with automatic file discovery)

For yaml-cpp, Meson automatically discovers all source files from `ext/yaml-cpp/src` instead of using the CMake build (which has issues with symlinked subprojects).

## Known Limitations

1. **SUNDIALS not yet supported**: The SUNDIALS dependency needs to be implemented as a Meson subproject or made available system-wide
2. **No Python bindings**: Only C++ library is currently supported
3. **No Fortran interface**: F90 interface not yet implemented
4. **Limited testing**: Build system needs more testing across platforms

## 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
- Cross-compilation support
- **Automatic source discovery** like SCons `multi_glob()`

## Contributing

This is initial work to replace the SCons build system. Contributions are welcome to:
- Add SUNDIALS subproject support
- Improve dependency detection
- Add testing infrastructure
- Port more configuration options from SCons

## 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
- `include/cantera/ext/`: Symlinks to submodule headers (fmt, yaml-cpp, Eigen)
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