Meson plugin

Description

The meson plugin is used for setting up, compiling, installing and testing software using the Meson build generator system.

Mandatory settings

Mandatory settings for all modes

mode

Set the mode of the Meson call for the specific command. Default: setup.

Supported modes are:

  • setup: For setting up the build directory based on the Meson configuration in the source. This is often callend the configure or build init step.
  • compile: Compiles (or builds) the generated project
  • test: Run the configured test suite using Meson
  • install: Install the generated project

Optional settings

The configuration of the meson plugin may contain the following additional settings:

Settings for all modes

patterns

A list of patterns to apply on the command line. See Patterns (5).

enviroment

A list of environment variables that should be set before the commands are executed. See Environment (5).

command-line

Additional command line parameters to pass as a list of separate arguments. By default no additional arguments are added.

working-dir

The working directory of the command. Can be an absolute path are a relative one w.r.t. the path to the considered configuration file. Commands that should be executed relative to the current working dir can use the {EH_WORKING_DIR} pattern.

build-dir

The path to the build directory. This is either an absolute path are a path relative to the location of this file. Default: . (the directory of the exec-helper configuration).

Additional settings for the setup mode

source-dir

The directory containing the root meson.build file of the sources. Default: . (the directory of the exec-helper configuration).

build-type

Set the Meson build type explicitly. See the --buildtype parameter of meson setup for more information.

cross-file

Set the Meson cross-file. See the --cross-file parameter of meson setup for more information.

prefix

Set the Meson installation prefix. See the --prefix parameter of meson setup for more information.

options

A map of the options to set for setting up the build. See the -D parameter of :code`meson setup` for more information.

Additional settings for the compile mode

jobs

Fix the number of jobs to use. Default: auto or the number of jobs set on the exec-helper invocation.

Additional settings for the test mode

suites

Set the test suites to run. By default, this parameter is omitted.

targets

Set the targets to run. By default, this parameter is omitted.

Example

Configuration

commands:                       # Define the commands that can be run
    example: Run the meson example
    run: Run the files that were built

patterns:                       # Define the patterns that can be used
    MESON_TARGET:               # Define the MESON_TARGET pattern.
        default-values:         # Only define the default value
            - hello
            - world

example:
    - build                     # Use the meson plugin when running the 'example' command
    - run

build:                          # Subdivide the 'build' command into three consecutive commands
    - generate
    - build-only
    - install

generate: meson                 # Define the subcommands. These commands can be called directly to.
build-only: meson
install: meson

run:
    - command-line-command  # Use the command-line-command plugin for the 'run' command

meson:
    environment:            # Define additional environment variables
        WORLD: "world!"

    prefix: /tmp            # Set the installation prefix
    source-dir: .           # Set the source dir for all meson targets that do not further specialize this
    build-dir: build        # Set the build dir for all meson targets that do not further specialize this

    generate:               # Specific settings for the 'generate' command
        mode: setup         # Set the mode
        options:            # Set some defines
            test: true
        command-line:       # Define additional command line arguments
            - --strip       # An example argument passed to make

    build-only:             # Specific settings for the 'build-only' command
        mode: compile       # Set the mode
        jobs: 1             # Always compile with one thread

    install:                # Specific settings for the 'install' command
        mode: install       # Set the mode

command-line-command:
    run:
        patterns:               # The patterns that are used by the 'run' command
            - MESON_TARGET
        command-line:
            - build/{MESON_TARGET}

Additional files

In order for the above example to work, the following file hierarchy needs to be created in the directory:

meson.build:

project('example', 'cpp',
  version: '0.1.0',
  default_options: [
    'cpp_std=c++17',
  ]
)

hello = executable('hello', ['src/hello.cpp'],
  install : true,
)

world = executable('world', ['src/world.cpp'],
  install : true,
)

hello.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "Hello" << std::endl;
    return EXIT_SUCCESS;
}

world.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "World!" << std::endl;
    return EXIT_SUCCESS;
}

Usage

Save the example to an exec-helper configuration file and execute in the same directory:

eh example

See also

See exec-helper (1) for information about the usage of exec-helper.

See Configuration (5) for information about the configuration file format.

See Plugins (5) for information about the configuration file format.