Skip to content

Add Meson build system as alternative to CMake#10

Open
munechika-koyo wants to merge 35 commits intoiterorganization:developfrom
munechika-koyo:feature/meson
Open

Add Meson build system as alternative to CMake#10
munechika-koyo wants to merge 35 commits intoiterorganization:developfrom
munechika-koyo:feature/meson

Conversation

@munechika-koyo
Copy link
Contributor

@munechika-koyo munechika-koyo commented Dec 5, 2025

Summary

This pull request introduces Meson as an alternative build system for IMAS-Core, complementing the existing CMake build system. This addition provides developers with a modern, fast, and user-friendly build option while maintaining full backward compatibility with the current CMake workflow.

Motivation

  • Build System Diversity: Offers developers choice between CMake and Meson based on their preferences and requirements
  • Modern Build Experience: Meson provides faster configuration, better dependency management, and more intuitive syntax
  • Cross-Platform Support: Enhanced support for various platforms with Meson's robust cross-compilation features
  • Future-Proofing: Prepares the project for potential future migration while maintaining current stability

Key Features

🔧 Complete Build System Implementation

  • Core Library: Full support for building al-core with all backends (HDF5, UDA, MDSplus)
  • Python Bindings: Native Meson integration with Cython for imas-core Python package
  • Testing: Integration with test executables and test runners
  • Configuration Options: Comprehensive build options matching CMake functionality

📦 Backend Support

  • HDF5 Backend (enabled by default)
  • UDA Backend (enabled by default)
  • 🔄 MDSplus Backend (planned for future implementation)
  • 🔄 MDSplus Models (planned for future implementation)

🐍 Python Integration

  • Version detection via setuptools-scm
  • Cython binding compilation with proper dependency management

Files Added/Modified

New Meson Files

  • meson.build - Main build configuration
  • meson_options.txt - Build options and feature toggles
  • src/meson.build - Core library build configuration
  • include/meson.build - Public Header installation configuration
  • python/meson.build - Python bindings build configuration

Build Options

# Configure with Meson (examples)
meson setup builddir
meson setup builddir -Dal_backend_hdf5=true -Dal_backend_uda=false
meson setup builddir -Dal_core=false -Dpython_bindings=true

# Build
meson compile -C builddir

# Test
meson setup builddir -Dal_dummy_exe=true
meson test -C builddir

Compatibility

  • No Migration Required: CMake remains the primary build system
  • Parallel Support: Both build systems can coexist without conflicts
  • Feature Parity: All CMake options have equivalent Meson counterparts
  • Same Dependencies: Uses identical external dependencies (HDF5, UDA, MDSplus, etc.)

Testing

  • Builds on macOS
  • Builds on Linux
  • Builds on Windows
  • All backends compile correctly (except for MDSplus)
  • Python bindings generate properly
  • Test dummy executable build and run
  • Test al-core executables build and run
  • Test Python bindings imas-core

Development Environment

We used pixi to manage the development environment for testing the Meson build system.
The pixi.toml file has been updated to include Meson and Ninja as build tools, ensuring a consistent and reproducible environment for developers.
Here is the configuration I used:

pixi.toml
[workspace]
channels = ["conda-forge"]
name = "imas-core"
platforms = ["osx-arm64", "osx-64", "linux-64", "win-64"]

[tasks]
setup = { cmd = [
    "meson",
    "setup",
    "builddir",
], description = "Setup the build directory" }

build = { cmd = [
    "meson",
    "compile",
    "-C",
    "builddir",
], description = "Build the project" }

install = { cmd = [
    "meson",
    "install",
    "-C",
    "builddir",
    "--destdir",
    "{{ destdir }}",
], args = [
    { arg = "destdir", default = "build-install" },
], description = "Install the project" }

test = { cmd = [
    "meson",
    "test",
    "-C",
    "builddir",
    "--verbose",
], description = "Run the tests", depends-on = [
    { task = "setup", args = [
        "-Dal_dummy_exe=true",
    ] },
] }


[target.unix.activation.env]
BOOST_INCLUDEDIR = "$CONDA_PREFIX/include"
BOOST_LIBRARYDIR = "$CONDA_PREFIX/lib"

[target.win-64.activation.env]
BOOST_INCLUDEDIR = "%CONDA_PREFIX%/Library/include"
BOOST_LIBRARYDIR = "%CONDA_PREFIX%/Library/lib"

[dependencies]
# Compiler
cxx-compiler = ">=1.11.0,<2"

# Build tools
meson = ">=1.9.1,<2"
ninja = ">=1.13.2,<2"
pkg-config = ">=0.29.2,<0.30"
setuptools-scm = ">=9.2.2,<10"

# Link Libraries
libboost-devel = ">=1.88.0,<2"
hdf5 = ">=1.14.6,<2"
uda-cpp = ">=2.9.3,<3"
libxml2-devel = ">=2.15.1,<3"
zlib = ">=1.3.1,<2"

# Link and Tools for the python wrapper
python = ">=3.14.1,<3.15"
numpy = ">=2.3.5,<3"
cython = ">=3.2.2,<4"

[target.win-64.dependencies]
# Build tools
cmake = ">=4.2.1,<5"

# Link Libraries
dlfcn-win32 = ">=1.4.2,<2"
winpthreads-devel = ">=12.0.0.r4.gg4f2fc60ca,<13"

meson command can be used through pixi run meson ....


Note: This is a non-breaking change that purely adds functionality. All existing CMake-based workflows continue to work unchanged.

munechika-koyo and others added 22 commits December 5, 2025 01:08
- Introduced meson.build files for project setup and library configuration.
- Added options for building internal core library and dummy executable.
- Included source files for HDF5 and UDA backends.
- Configured public headers and installation paths.
add test cases for lowlevel executables and modify dummy executable option
…2 dependency method in Meson build configuration
@munechika-koyo munechika-koyo marked this pull request as ready for review January 22, 2026 15:46
@prasad-sawantdesai
Copy link
Collaborator

@munechika-koyo Could you please check this PR? This fixes numpy issue on SDCC. munechika-koyo#1

Copy link
Collaborator

@prasad-sawantdesai prasad-sawantdesai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this build system @munechika-koyo
It seems faster than normal cmake workflow.

time meson setup --reconfigure builddir --prefix="$HOME/.local"
real    0m20.597s
user    0m3.148s
sys     0m6.954s

time meson compile -C builddir
real    1m19.796s
user    2m2.108s
sys     0m20.637s

# =============================================================================
# Add Optional Backends
# =============================================================================
if get_option('al_backend_hdf5')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to use capital case here or are there any limitations? -DAL_BACKEND_UDA=OFF -DAL_BACKEND_UDAFAT=OFF -DAL_BACKEND_MDSPLUS=OFF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not use capital names in the meson build to follow the style guide.
Additionally, many built-in options are already defined in lowercase, so we should follow that convention to avoid confusion.

# =============================================================================
# Summary
# =============================================================================
if get_option('al_core')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add github workflow for testing meson build?

Copy link
Collaborator

@prasad-sawantdesai prasad-sawantdesai Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add small list of steps in the sphinx documentation? https://github.com/iterorganization/IMAS-Core/blob/develop/docs/source/user_guide/installation.rst somewhere here?

@munechika-koyo
Copy link
Contributor Author

Thanks for adding this build system @munechika-koyo It seems faster than normal cmake workflow.

time meson setup --reconfigure builddir --prefix="$HOME/.local"
real    0m20.597s
user    0m3.148s
sys     0m6.954s

time meson compile -C builddir
real    1m19.796s
user    2m2.108s
sys     0m20.637s

Thank you for measuring the compilation time!
Could you add the cmake-case time for the comparison?

@prasad-sawantdesai
Copy link
Collaborator

Thanks for adding this build system @munechika-koyo It seems faster than normal cmake workflow.

time meson setup --reconfigure builddir --prefix="$HOME/.local"
real    0m20.597s
user    0m3.148s
sys     0m6.954s

time meson compile -C builddir
real    1m19.796s
user    2m2.108s
sys     0m20.637s

Thank you for measuring the compilation time! Could you add the cmake-case time for the comparison?

Yes, it is slower..

time  cmake -Bbuild -S . 

real    0m44.060s
user    0m14.387s
sys     0m6.725s

time cmake --build build 
real    7m28.771s
user    4m35.985s
sys     1m53.904s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants