Linux command
meson 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Setup build directory
meson setup [builddir]
Configure with options
meson setup [builddir] -D[option=value]
Compile project
meson compile -C [builddir]
Run tests
meson test -C [builddir]
Install project
meson install -C [builddir]
Reconfigure
meson configure [builddir] -D[option=value]
Wipe and reconfigure build directory
meson setup --wipe [builddir]
Create a release build
meson setup [builddir] --buildtype=release
说明
meson is a build system designed to be fast and user-friendly. It reads meson.build project definitions and generates backend build files (ninja by default) for actual compilation. Meson supports C, C++, Rust, Java, Fortran, and other languages. It features automatic dependency detection, cross-compilation support, and built-in unit test and coverage infrastructure. Used by projects like GNOME, systemd, X.Org, and Mesa.
参数
- init
- Create a minimal meson.build for a new project in the current directory.
- setup _DIR_
- Configure a build directory (the canonical first step).
- compile -C _DIR_
- Build the project.
- test -C _DIR_
- Run the project's test suite.
- install -C _DIR_
- Install the built project into the configured prefix.
- configure _DIR_
- Change build options on an existing build directory without wiping it.
- dist
- Create a signed source distribution tarball.
- introspect
- Print a JSON-formatted description of targets, tests, options, etc.
- subprojects, wrap
- Manage meson subprojects and .wrap dependency files.
- devenv
- Spawn a shell with the build environment (e.g. PATH, PKG_CONFIG_PATH) pre-set.
- rewrite
- Programmatically modify meson.build files.
- env2mfile
- Generate a cross- or native-file from current environment variables.
- format
- Auto-format meson.build files (alias fmt).
- -D _OPT=VAL_
- Set a build option (e.g. -Dbuildtype=release, -Dprefix=/usr).
- --buildtype _TYPE_
- Build type: plain, debug, debugoptimized, release, minsize, custom.
- --prefix _PATH_
- Installation prefix (default /usr/local).
- --backend _BACKEND_
- Backend to generate: ninja (default), vs, vs2017, xcode, etc.
- --default-library _TYPE_
- Default library type: static, shared, or both.
- --cross-file _FILE_
- Use a cross-compilation definition file.
- --native-file _FILE_
- Override native compiler/tool selection on the host.
- --reconfigure
- Re-run configuration using the stored options without wiping the build directory.
- --wipe
- Wipe and reconfigure an existing build directory.
- --werror, --warnlevel _N_
- Treat warnings as errors, or set compiler warning level (0-3/everything).
- --optimization _LEVEL_
- Optimization level (0, g, 1, 2, 3, s).
FAQ
What is the meson command used for?
meson is a build system designed to be fast and user-friendly. It reads meson.build project definitions and generates backend build files (ninja by default) for actual compilation. Meson supports C, C++, Rust, Java, Fortran, and other languages. It features automatic dependency detection, cross-compilation support, and built-in unit test and coverage infrastructure. Used by projects like GNOME, systemd, X.Org, and Mesa.
How do I run a basic meson example?
Run `meson setup [builddir]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does init do in meson?
Create a minimal meson.build for a new project in the current directory.