meson - a high productivity build system
Contents
Description
Meson is a build system designed to optimize programmer productivity. It aims to do this by providing
simple, out-of-the-box support for modern software development tools and practices, such as unit tests,
coverage reports, Valgrind, Ccache and the like.
The main Meson executable provides many subcommands to access all the functionality.
Exit Status
0 Successful.
1 Usage error, or an error parsing or executing meson.build.
2 Internal error.
125mesontest could not rebuild the required targets.
SEEALSOhttp://mesonbuild.com/
https://wrapdb.mesonbuild.com/
meson 1.7.0 January 2025 MESON(1)
Name
meson - a high productivity build system
The Compile Command
mesoncompile builds the project.
mesoncompile[options][TARGET...]positionalarguments:TARGET Targets to build. Target has the following format:
[PATH_TO_TARGET/]TARGET_NAME.TARGET_SUFFIX[:TARGET_TYPE].
options:-h,--help
show this help message and exit
--clean
Clean the build directory.
-CWD directory to cd into before running
-jJOBS,--jobsJOBS
The number of worker jobs to run (if supported). If the value is less than 1 the build program
will guess.
-lLOAD_AVERAGE,--load-averageLOAD_AVERAGE
The system load average to try to maintain (if supported).
-v,--verbose
Show more verbose output.
--ninja-argsNINJA_ARGS
Arguments to pass to `ninja` (applied only on `ninja` backend).
--vs-argsVS_ARGS
Arguments to pass to `msbuild` (applied only on `vs` backend).
--xcode-argsXCODE_ARGS
Arguments to pass to `xcodebuild` (applied only on `xcode` backend).
The Configure Command
mesonconfigure provides a way to configure a Meson project from the command line. Its usage is simple:
mesonconfigure[builddirectory][optionstoset]
If build directory is omitted, the current directory is used instead.
If no parameters are set, mesonconfigure will print the value of all build options to the console.
To set values, use the -D command line argument like this.
mesonconfigure-Dopt1=value1-Dopt2=value2The Devenv Command
mesondevenv runs commands in the developer environment.
mesondevenv[options][command]positionalarguments:command
Command to run in developer environment (default: interactive shell)
options:-h,--help
show this help message and exit
-CBUILDDIR
Path to build directory
--workdirWORKDIR,-wWORKDIR
Directory to cd into before running (default: builddir, Since 1.0.0)
--dump[DUMP]
Only print required environment (Since 0.62.0) Takes an optional file path (Since 1.1.0)
--dump-format{sh,export,vscode}
Format used with --dump (Since 1.1.0)
The Dist Command
mesondist generates a release archive.
mesondist[options]options:-h,--help
show this help message and exit
-CWD directory to cd into before running
--allow-dirty
Allow even when repository contains uncommitted changes.
--formatsFORMATS
Comma separated list of archive types to create. Supports xztar (default), gztar, and zip.
--include-subprojects
Include source code of subprojects that have been used for the build.
--no-tests
Do not build and test generated packages.
The Env2Mfile Command
mesonenv2mfile converts the current environment to a cross or native file.
mesonenv2mfile[options]options:-h,--help
show this help message and exit
--debarchDEBARCH
The dpkg architecture to generate.
--gccsuffixGCCSUFFIX
A particular gcc version suffix if necessary.
-oOUTFILE
The output file.
--cross
Generate a cross compilation file.
--native
Generate a native compilation file.
--systemSYSTEM
Define system for cross compilation.
--subsystemSUBSYSTEM
Define subsystem for cross compilation.
--kernelKERNEL
Define kernel for cross compilation.
--cpuCPU
Define cpu for cross compilation.
--cpu-familyCPU_FAMILY
Define cpu family for cross compilation.
--endian{big,little}
Define endianness for cross compilation.
The Format Command
mesonformat formats a meson source file.
mesonformat[options][sources...]positionalarguments:sources...
meson source files
options:-h,--help
show this help message and exit
-q,--check-only
exit with 1 if files would be modified by meson format
-i,--inplace
format files in-place
-r,--recursive
recurse subdirs (requires --check-only or --inplace option)
-cmeson.format,--configurationmeson.format
read configuration from meson.format
-e,--editor-config
try to read configuration from .editorconfig
-oOUTPUT,--outputOUTPUT
output file (implies having exactly one input)
The Init Command
mesoninit creates a new project
mesoninit[options][sourcefile...]positionalarguments:
sourcefile...
source files. default: all recognized files in current directory
options:-h,--help
show this help message and exit
-CWD directory to cd into before running
-nNAME,--nameNAME
project name. default: name of current directory
-eEXECUTABLE,--executableEXECUTABLE
executable name. default: project name
-dDEPS,--depsDEPS
dependencies, comma-separated
-l{c,cpp,cs,cuda,d,fortran,java,objc,objcpp,rust,vala},--language{c,cpp,cs,cuda,d,fortran,java,objc,objcpp,rust,vala}
project language. default: autodetected based on source files
-b,--build
build after generation
--builddirBUILDDIR
directory for build
-f,--force
force overwrite of existing files and directories.
--type{executable,library}
project type. default: executable based project
--versionVERSION
project version. default: 0.1
The Install Command
mesoninstall installs the project.
mesoninstall[options]options:-h,--help
show this help message and exit
-CWD directory to cd into before running
--no-rebuild
Do not rebuild before installing.
--only-changed
Only overwrite files that are older than the copied file.
--quiet
Do not print every file that was installed.
--destdirDESTDIR
Sets or overrides DESTDIR environment. (Since 0.57.0)
--dry-run,-n
Doesn't actually install, but print logs. (Since 0.57.0)
--skip-subprojects[SKIP_SUBPROJECTS]
Do not install files from given subprojects. (Since 0.58.0)
--tagsTAGS
Install only targets having one of the given tags. (Since 0.60.0)
--strip
Strip targets even if strip option was not set during configure. (Since 0.62.0)
The Introspect Command
Meson introspect is a command designed to make it simple to integrate with other tools, such as IDEs.
The output of this command is in JSON.
mesonintrospect[builddirectory][option]
If build directory is omitted, the current directory is used instead.
options:--targets
print all top level targets (executables, libraries, etc)
--target-files
print the source files of the given target
--buildsystem-files
print all files that make up the build system (meson.build, meson.options, meson_options.txt etc)
--tests
print all unit tests
--help print command line help
The Rewrite Command
mesonrewrite modifies the project definition.
mesonrewrite[options][command]options:-h,--help
show this help message and exit
-sSRCDIR,--sourcedirSRCDIR
Path to source directory.
-V,--verbose
Enable verbose output
-S,--skip-errors
Skip errors instead of aborting
commands:target(tgt)
Modify a target
kwargs Modify keyword arguments
default-options(def)
Modify the project default options
command(cmd)
Execute a JSON array of commands
The Setup Command
Using Meson is simple and follows the common two-phase process of most build systems. First you run Meson
to configure your build:
mesonsetup[options][builddirectory][sourcedirectory]
Note that the build directory must be different from the source directory. Meson does not support
building inside the source directory and attempting to do that leads to an error.
After a successful configuration step you can build the source by running the actual build command in the
build directory. The default backend of Meson is Ninja, which can be invoked like this.
ninja[target]
You only need to run the Meson command once: when you first configure your build dir. After that you just
run the build command. Meson will autodetect changes in your source tree and regenerate all files needed
to build the project.
The setup command is the default operation. If no actual command is specified, Meson will assume you
meant to do a setup. That means that you can set up a build directory without the setup command like
this:
meson[options][builddirectory][sourcedirectory]options:--version
print version number
--help print command line help
The Subprojects Command
mesonsubprojects is used to manage subprojects.
mesonsubprojects[options][command]options:-h,--help
show this help message and exit
commands:update Update all subprojects from wrap files
checkout
Checkout a branch (git only)
download
Ensure subprojects are fetched, even if not in use. Already downloaded subprojects are not
modified. This can be used to pre-fetch all subprojects and avoid downloads during configure.
foreach
Execute a command in each subproject directory.
purge Remove all wrap-based subproject artifacts
packagefiles
Manage the packagefiles overlay
The Test Command
mesontest is a helper tool for running test suites of projects using Meson. The default way of running
tests is to invoke the default build command:
ninja[test]mesontest provides a richer set of tools for invoking tests.
mesontest automatically rebuilds the necessary targets to run tests when used with the Ninja backend.
Upon build failure, mesontest will return an exit code of 125. This return code tells gitbisectrun to
skip the current commit. Thus bisecting using git can be done conveniently like this.
gitbisectrunmesontest-Cbuild_diroptions:--repeat
run tests as many times as specified
--gdb run tests under gdb
--list list all available tests
--wrapper
invoke all tests via the given wrapper (e.g. valgrind)
-C Change into the given directory before running tests (must be root of build directory).
--suite
run tests in this suite
--no-suite
do not run tests in this suite
--no-stdsplit
do not split stderr and stdout in test logs
--benchmark
run benchmarks instead of tests
--logbase
base of file name to use for writing test logs
--num-processes
how many parallel processes to use to run tests
--verbose
do not redirect stdout and stderr
-t a multiplier to use for test timeout values (usually something like 100 for Valgrind)
--setup
use the specified test setup
The Wrap Command
Wraptool is a helper utility to manage source dependencies using the online wrapdb service.
mesonwrap<command>[options]
You should run this command in the top level source directory of your project.
Commands:list list all available projects
search search projects by name
install
install a project with the given name
update update the specified project to latest available version
info show available versions of the specified project
status show installed and available versions of currently used subprojects
