在使用 Meson 构建系统时,您可以通过在 meson
命令中添加参数来指定构建选项或启用/禁用特性。以下是一些常用的 Meson 参数:
-
指定构建类型:
--buildtype
:设置构建类型,如debug
、release
、minsize
等。meson --buildtype release ..
-
启用或禁用警告:
-Db_sanitize=<sanitizer>
:启用特定的编译器 sanitizer。meson -Db_sanitize=address ..
-
设置 CMake 选项:
-D
:用于设置项目内的选项,如启用或禁用某个特性。meson -Dmy_feature=true ..
-
指定依赖库的路径:
-Ddependency_name=/path/to/dependency
:指定依赖库的路径。meson -Dgstreamer=/path/to/gstreamer ..
-
启用静态链接:
--default-library
:设置默认的库链接类型,static
或shared
。meson --default-library static ..
-
启用调试选项:
-Ddebug=true
:启用调试构建。meson -Ddebug=true ..
-
指定编译器:
-Dcpp=/path/to/compiler
:指定 C++ 编译器的路径。meson -Dcpp=/usr/bin/clang++ ..
-
启用测试:
-Dtests=true
:启用构建测试。meson -Dtests=true ..
-
指定安装前缀:
--prefix
:设置安装前缀,默认为/usr/local
。meson --prefix /path/to/install ..
-
启用优化:
-Doptimization=3
:设置优化级别。meson -Doptimization=3 ..
-
启用或禁用特定插件:
-Dplugin_name=enabled
或-Dplugin_name=disabled
:启用或禁用特定的插件。meson -Dplugin_name=enabled ..
-
查看所有可用选项:
--help
:显示 Meson 命令的帮助信息。meson --help
在使用 Meson 时,您可以根据项目的具体需求和构建指南来调整这些参数。如果您不确定某个项目的特定构建选项,可以查看项目的 meson.build
文件或构建文档,以了解可用的选项和推荐配置。
举例
meson --help
usage: meson [-h] {setup,configure,dist,install,introspect,init,test,wrap,subprojects,rewrite,compile,devenv,env2mfile,format,fmt,help} ...
optional arguments:
-h, --help show this help message and exit
Commands:
If no command is specified it defaults to setup command.
{setup,configure,dist,install,introspect,init,test,wrap,subprojects,rewrite,compile,devenv,env2mfile,format,fmt,help}
setup Configure the project
configure Change project options
dist Generate release archive
install Install the project
introspect Introspect project
init Create a new project
test Run tests
wrap Wrap tools
subprojects Manage subprojects
rewrite Modify the project definition
compile Build the project
devenv Run commands in developer environment
env2mfile Convert current environment to a cross or native file
format (fmt) Format meson source file
help Print help of a subcommand
meson configure --help
usage: meson configure [-h] [--prefix PREFIX] [--bindir BINDIR] [--datadir DATADIR] [--includedir INCLUDEDIR] [--infodir INFODIR] [--libdir LIBDIR] [--licensedir LICENSEDIR] [--libexecdir LIBEXECDIR]
[--localedir LOCALEDIR] [--localstatedir LOCALSTATEDIR] [--mandir MANDIR] [--sbindir SBINDIR] [--sharedstatedir SHAREDSTATEDIR] [--sysconfdir SYSCONFDIR]
[--auto-features {enabled,disabled,auto}] [--backend {ninja,vs,vs2010,vs2012,vs2013,vs2015,vs2017,vs2019,vs2022,xcode,none}] [--genvslite {vs2022}]
[--buildtype {plain,debug,debugoptimized,release,minsize,custom}] [--debug] [--default-library {shared,static,both}] [--errorlogs] [--install-umask INSTALL_UMASK]
[--layout {mirror,flat}] [--optimization {plain,0,g,1,2,3,s}] [--prefer-static] [--stdsplit] [--strip] [--unity {on,off,subprojects}] [--unity-size UNITY_SIZE]
[--warnlevel {0,1,2,3,everything}] [--werror] [--wrap-mode {default,nofallback,nodownload,forcefallback,nopromote}] [--force-fallback-for FORCE_FALLBACK_FOR] [--vsenv]
[--pkgconfig.relocatable] [--python.bytecompile PYTHON.BYTECOMPILE] [--python.install-env {auto,prefix,system,venv}] [--python.platlibdir PYTHON.PLATLIBDIR]
[--python.purelibdir PYTHON.PURELIBDIR] [--python.allow-limited-api] [--pkg-config-path PKG_CONFIG_PATH] [--build.pkg-config-path BUILD.PKG_CONFIG_PATH]
[--cmake-prefix-path CMAKE_PREFIX_PATH] [--build.cmake-prefix-path BUILD.CMAKE_PREFIX_PATH] [-D option] [--clearcache] [--no-pager]
[builddir]
positional arguments:
builddir
optional arguments:
-h, --help show this help message and exit
--prefix PREFIX Installation prefix (default: /usr/local).
--bindir BINDIR Executable directory (default: bin).
--datadir DATADIR Data file directory (default: share).
--includedir INCLUDEDIR Header file directory (default: include).
--infodir INFODIR Info page directory (default: share/info).
--libdir LIBDIR Library directory (default: lib/aarch64-linux-gnu).
--licensedir LICENSEDIR Licenses directory (default: ).
--libexecdir LIBEXECDIR Library executable directory (default: libexec).
--localedir LOCALEDIR Locale data directory (default: share/locale).
--localstatedir LOCALSTATEDIR Localstate data directory (default: var).
--mandir MANDIR Manual page directory (default: share/man).
--sbindir SBINDIR System executable directory (default: sbin).
--sharedstatedir SHAREDSTATEDIR Architecture-independent data directory (default: com).
--sysconfdir SYSCONFDIR Sysconf data directory (default: etc).
--auto-features {enabled,disabled,auto} Override value of all 'auto' features (default: auto).
--backend {ninja,vs,vs2010,vs2012,vs2013,vs2015,vs2017,vs2019,vs2022,xcode,none} Backend to use (default: ninja).
--genvslite {vs2022} Setup multiple buildtype-suffixed ninja-backend build directories, and a [builddir]_vs containing a Visual Studio meta-
backend with multiple configurations that calls into them (default: vs2022).
--buildtype {plain,debug,debugoptimized,release,minsize,custom} Build type to use (default: debug).
--debug Enable debug symbols and other information
--default-library {shared,static,both} Default library type (default: shared).
--errorlogs Whether to print the logs from failing tests
--install-umask INSTALL_UMASK Default umask to apply on permissions of installed files (default: 022).
--layout {mirror,flat} Build directory layout (default: mirror).
--optimization {plain,0,g,1,2,3,s} Optimization level (default: 0).
--prefer-static Whether to try static linking before shared linking
--stdsplit Split stdout and stderr in test logs
--strip Strip targets on install
--unity {on,off,subprojects} Unity build (default: off).
--unity-size UNITY_SIZE Unity block size (default: (2, None, 4)).
--warnlevel {0,1,2,3,everything} Compiler warning level to use (default: 1).
--werror Treat warnings as errors
--wrap-mode {default,nofallback,nodownload,forcefallback,nopromote} Wrap mode (default: default).
--force-fallback-for FORCE_FALLBACK_FOR Force fallback for those subprojects (default: []).
--vsenv Activate Visual Studio environment
--pkgconfig.relocatable Generate pkgconfig files as relocatable
--python.bytecompile PYTHON.BYTECOMPILE Whether to compile bytecode (default: (-1, 2, 0)).
--python.install-env {auto,prefix,system,venv} Which python environment to install to (default: prefix).
--python.platlibdir PYTHON.PLATLIBDIR Directory for site-specific, platform-specific files (default: ).
--python.purelibdir PYTHON.PURELIBDIR Directory for site-specific, non-platform-specific files (default: ).
--python.allow-limited-api Whether to allow use of the Python Limited API
--pkg-config-path PKG_CONFIG_PATH List of additional paths for pkg-config to search (default: []). (just for host machine)
--build.pkg-config-path BUILD.PKG_CONFIG_PATH List of additional paths for pkg-config to search (default: []). (just for build machine)
--cmake-prefix-path CMAKE_PREFIX_PATH List of additional prefixes for cmake to search (default: []). (just for host machine)
--build.cmake-prefix-path BUILD.CMAKE_PREFIX_PATH List of additional prefixes for cmake to search (default: []). (just for build machine)
-D option Set the value of an option, can be used several times to set multiple options.
--clearcache Clear cached state (e.g. found dependencies)
--no-pager Do not redirect output to a pager