命令列指令

有兩種不同的方式可以調用 Meson。首先,您可以使用命令 /path/to/source/meson.py 從原始碼樹中直接執行它。Meson 也可能已安裝,在這種情況下,命令很簡單,就是 meson。在本手冊中,為了簡潔起見,我們只使用後者格式。

Meson 的調用語法如下:meson [COMMAND] [COMMAND_OPTIONS]

本節描述所有可用的命令及其一些可選參數。最常見的工作流程是執行 setup,然後執行 compile,最後執行 install

如需取得特定命令的所有可用選項的完整清單,請使用以下語法:meson COMMAND --help

configure

$ 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}]
                  [--default-both-libraries {shared,static,auto}]
                  [--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]

變更已設定的 meson 專案的選項。

positional arguments:
  builddir

options:
  -h, --help                            show this help message and exit
  --prefix PREFIX                       Installation prefix.
  --bindir BINDIR                       Executable directory.
  --datadir DATADIR                     Data file directory.
  --includedir INCLUDEDIR               Header file directory.
  --infodir INFODIR                     Info page directory.
  --libdir LIBDIR                       Library directory.
  --licensedir LICENSEDIR               Licenses directory (default: ).
  --libexecdir LIBEXECDIR               Library executable directory.
  --localedir LOCALEDIR                 Locale data directory.
  --localstatedir LOCALSTATEDIR         Localstate data directory.
  --mandir MANDIR                       Manual page directory.
  --sbindir SBINDIR                     System executable directory.
  --sharedstatedir SHAREDSTATEDIR       Architecture-independent data directory.
  --sysconfdir SYSCONFDIR               Sysconf data directory.
  --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).
  --default-both-libraries {shared,static,auto}
                                        Default library type for both_libraries
                                        (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

大多數引數與 setup 中的引數相同。

注意:重新設定專案不會將選項重設為其預設值(即使它們在 meson.build 中已變更)。

範例

列出所有可用的選項

meson configure builddir

變更單一選項的值

meson configure builddir -Doption=new_value

compile

(自 0.54.0 起)

$ meson compile [-h] [--clean] [-C WD] [-j JOBS] [-l LOAD_AVERAGE] [-v]
                [--ninja-args NINJA_ARGS] [--vs-args VS_ARGS]
                [--xcode-args XCODE_ARGS]
                [TARGET ...]

建構已設定的 Meson 專案的預設或指定目標。

positional arguments:
  TARGET                                Targets to build. Target has the
                                        following format: [PATH_TO_TARGET/]TARGE
                                        T_NAME.TARGET_SUFFIX[:TARGET_TYPE].

options:
  -h, --help                            show this help message and exit
  --clean                               Clean the build directory.
  -C WD                                 directory to cd into before running
  -j JOBS, --jobs JOBS                  The number of worker jobs to run (if
                                        supported). If the value is less than 1
                                        the build program will guess.
  -l LOAD_AVERAGE, --load-average LOAD_AVERAGE
                                        The system load average to try to
                                        maintain (if supported).
  -v, --verbose                         Show more verbose output.
  --ninja-args NINJA_ARGS               Arguments to pass to `ninja` (applied
                                        only on `ninja` backend).
  --vs-args VS_ARGS                     Arguments to pass to `msbuild` (applied
                                        only on `vs` backend).
  --xcode-args XCODE_ARGS               Arguments to pass to `xcodebuild`
                                        (applied only on `xcode` backend).

--verbose 引數自 0.55.0 起可用。

目標

(自 0.55.0 起)

TARGET 具有以下語法 [PATH/]NAME.SUFFIX[:TYPE],其中

  • NAMEmeson.build 中目標的名稱(例如,executable('foo', ...) 中的 foo)。
  • SUFFIXmeson.build 中目標的後綴名稱(例如,executable('foo', suffix: 'exe', ...) 中的 exe)。
  • PATH:目標相對於根 meson.build 檔案的路徑。注意:在根 meson.build 中指定的目標的相對路徑為 ./
  • TYPE:目標的類型。可以是下列其中之一:'executable'、'static_library'、'shared_library'、'shared_module'、'custom'、'alias'、'run'、'jar'。

如果產生的 TARGET 可用於唯一識別 meson.build 中的目標,則可以省略 PATHSUFFIXTYPE

請注意,SUFFIX 在 1.3.0 之前不存在。

後端特定引數

(自 0.55.0 起)

BACKEND-args 使用以下語法

如果您只傳遞單一字串,則會將其視為所有值以逗號分隔。因此,調用以下命令

$ meson compile --ninja-args=-n,-d,explain

會將 -n-dexplain 引數新增至 ninja 調用。

如果您需要在字串值中使用逗號或空格,則需要使用適當的 shell 引號傳遞該值,如下所示

$ meson compile "--ninja-args=['a,b', 'c d']"

範例

建構專案

meson compile -C builddir

在 ninja 後端執行試執行,並包含額外的除錯資訊

meson compile --ninja-args=-n,-d,explain

建構三個目標:兩個名稱相同為 foo 但類型不同的目標,以及一個 bar 目標

meson compile foo:shared_library foo:static_library bar

產生覆蓋率 HTML 報告(如果可用)

ninja coverage-html

dist

(自 0.52.0 起)

$ meson dist [-h] [-C WD] [--allow-dirty] [--formats FORMATS]
             [--include-subprojects] [--no-tests]

從目前的原始碼樹產生發行封存。

options:
  -h, --help             show this help message and exit
  -C WD                  directory to cd into before running
  --allow-dirty          Allow even when repository contains uncommitted
                         changes.
  --formats FORMATS      Comma separated list of archive types to create.
                         Supports xztar (default), bztar, 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.

如需更多資訊,請參閱關於建立發行的注意事項

範例

建立發行封存

meson dist -C builddir

init

(自 0.45.0 起)

$ meson init [-h] [-C WD] [-n NAME] [-e EXECUTABLE] [-d DEPS]
             [-l {c,cpp,cs,cuda,d,fortran,java,objc,objcpp,rust,vala}] [-b]
             [--builddir BUILDDIR] [-f] [--type {executable,library}]
             [--version VERSION]
             [sourcefile ...]

根據範本建立一組基本的建構檔案。

positional arguments:
  sourcefile                            source files. default: all recognized
                                        files in current directory

options:
  -h, --help                            show this help message and exit
  -C WD                                 directory to cd into before running
  -n NAME, --name NAME                  project name. default: name of current
                                        directory
  -e EXECUTABLE, --executable EXECUTABLE
                                        executable name. default: project name
  -d DEPS, --deps DEPS                  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
  --builddir BUILDDIR                   directory for build
  -f, --force                           force overwrite of existing files and
                                        directories.
  --type {executable,library}           project type. default: executable based
                                        project
  --version VERSION                     project version. default: 0.1

範例

sourcedir 中建立專案

meson init -C sourcedir

env2mfile

此命令為實驗性命令,可能會變更。

{自 0.62.0 起}

$ meson env2mfile [-h] [--debarch DEBARCH] [--gccsuffix GCCSUFFIX] -o
                  OUTFILE [--cross] [--native] [--system SYSTEM]
                  [--subsystem SUBSYSTEM] [--kernel KERNEL] [--cpu CPU]
                  [--cpu-family CPU_FAMILY] [--endian {big,little}]

從目前的環境建立原生和交叉編譯檔案,通常是透過嗅探環境變數,例如 CCCFLAGS

options:
  -h, --help               show this help message and exit
  --debarch DEBARCH        The dpkg architecture to generate.
  --gccsuffix GCCSUFFIX    A particular gcc version suffix if necessary.
  -o OUTFILE               The output file.
  --cross                  Generate a cross compilation file.
  --native                 Generate a native compilation file.
  --system SYSTEM          Define system for cross compilation.
  --subsystem SUBSYSTEM    Define subsystem for cross compilation.
  --kernel KERNEL          Define kernel for cross compilation.
  --cpu CPU                Define cpu for cross compilation.
  --cpu-family CPU_FAMILY  Define cpu family for cross compilation.
  --endian {big,little}    Define endianness for cross compilation.

範例

自動偵測目前的交叉建構環境

meson env2mfile --cross -o current_cross.txt --cpu=arm7a --cpu-family=arm --system=linux

使用 Debian 系統資訊產生交叉建構

meson env2mfile --cross --debarch=armhf -o deb_arm_cross.txt

introspect

$ meson introspect [-h] [--ast] [--benchmarks] [--buildoptions]
                   [--buildsystem-files] [--compilers] [--dependencies]
                   [--scan-dependencies] [--installed] [--install-plan]
                   [--machines] [--projectinfo] [--targets] [--tests]
                   [--backend {ninja,none,vs,vs2010,vs2012,vs2013,vs2015,vs2017,vs2019,vs2022,xcode}]
                   [-a] [-i] [-f]
                   [builddir]

顯示有關已設定的 Meson 專案的資訊。

positional arguments:
  builddir                              The build directory

options:
  -h, --help                            show this help message and exit
  --ast                                 Dump the AST of the meson file.
  --benchmarks                          List all benchmarks.
  --buildoptions                        List all build options.
  --buildsystem-files                   List files that make up the build
                                        system.
  --compilers                           List used compilers.
  --dependencies                        List external dependencies.
  --scan-dependencies                   Scan for dependencies used in the
                                        meson.build file.
  --installed                           List all installed files and
                                        directories.
  --install-plan                        List all installed files and directories
                                        with their details.
  --machines                            Information about host, build, and
                                        target machines.
  --projectinfo                         Information about projects.
  --targets                             List top level targets.
  --tests                               List all unit tests.
  --backend {ninja,none,vs,vs2010,vs2012,vs2013,vs2015,vs2017,vs2019,vs2022,xcode}
                                        The backend to use for the
                                        --buildoptions introspection.
  -a, --all                             Print all available information.
  -i, --indent                          Enable pretty printed JSON.
  -f, --force-object-output             Always use the new JSON format for
                                        multiple entries (even for 0 and 1
                                        introspection commands)

範例

顯示關於 builddir 中已設定專案的基本資訊

meson introspect builddir --projectinfo

install

(自 0.47.0 起)

$ meson install [-h] [-C WD] [--no-rebuild] [--only-changed] [--quiet]
                [--destdir DESTDIR] [--dry-run]
                [--skip-subprojects [SKIP_SUBPROJECTS]] [--tags TAGS]
                [--strip]

將專案安裝至 setup 中指定的前置詞。

options:
  -h, --help                            show this help message and exit
  -C WD                                 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.
  --destdir DESTDIR                     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)
  --tags TAGS                           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)

如需更多資訊,請參閱安裝文件

範例

將專案安裝至 prefix

meson install -C builddir

將專案安裝至 $DESTDIR/prefix

DESTDIR=/path/to/staging/area meson install -C builddir

0.60.0 起,DESTDIR--destdir 可以是相對於建構目錄的路徑。執行指令碼時,將會在環境中設定絕對路徑。

reprotest

(自 1.6.0 起)

$ meson reprotest [-h] [--intermediaries] [mesonargs ...]

簡單的重現建構測試器,會將專案編譯兩次,並檢查最終結果是否相同。

此命令必須在您要測試的專案的原始碼根目錄中執行。

positional arguments:
  mesonargs         Arguments to pass to "meson setup".

options:
  -h, --help        show this help message and exit
  --intermediaries  Check intermediate files.

範例

meson reprotest

使用預設設定建構目前的專案。

meson reprotest --intermediaries -- --buildtype=debugoptimized

建構目標,並檢查所有中繼檔案(例如物件檔案)是否也相同。-- 之後的所有命令列引數都會直接傳遞至底層的 meson 調用。只使用選項引數,也就是以破折號開頭的引數,Meson 會自動設定目錄引數。

rewrite

(自 0.50.0 起)

$ meson rewrite [-h] [-s SRCDIR] [-V] [-S]
                {target,tgt,kwargs,default-options,def,command,cmd} ...

修改 Meson 專案。

options:
  -h, --help                            show this help message and exit
  -s SRCDIR, --sourcedir SRCDIR         Path to source directory.
  -V, --verbose                         Enable verbose output
  -S, --skip-errors                     Skip errors instead of aborting

Rewriter commands:
  Rewrite command to execute

  {target,tgt,kwargs,default-options,def,command,cmd}
    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

如需更多資訊,請參閱Meson 檔案重寫器文件

setup

$ meson setup [-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}]
              [--default-both-libraries {shared,static,auto}] [--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] [--native-file NATIVE_FILE]
              [--cross-file CROSS_FILE] [-v] [--fatal-meson-warnings]
              [--reconfigure] [--wipe] [--clearcache]
              [builddir] [sourcedir]

為 Meson 專案設定建構目錄。

自 0.64.0 起已棄用:這是預設的 Meson 命令(如果未提供 COMMAND,則會調用)。但是,提供命令是必要的,以避免與未來新增的命令發生衝突,因此應該明確使用 "setup"。

自 1.1.0 起,即使建構目錄不存在,也允許使用 --reconfigure,在這種情況下會忽略該引數。

自 1.3.0 起,如果建構目錄已存在,則會使用命令列中給定的新值 (-Dopt=value) 更新選項。除非也指定了 --reconfigure,否則這不會立即重新設定。這具有與 meson configure <builddir> -Dopt=value 相同的行為。

自 1.3.0 起,可以使用單一命令 meson setup --clearcache --reconfigure <builddir> 清除快取並重新設定。

positional arguments:
  builddir
  sourcedir

options:
  -h, --help                            show this help message and exit
  --prefix PREFIX                       Installation prefix.
  --bindir BINDIR                       Executable directory.
  --datadir DATADIR                     Data file directory.
  --includedir INCLUDEDIR               Header file directory.
  --infodir INFODIR                     Info page directory.
  --libdir LIBDIR                       Library directory.
  --licensedir LICENSEDIR               Licenses directory (default: ).
  --libexecdir LIBEXECDIR               Library executable directory.
  --localedir LOCALEDIR                 Locale data directory.
  --localstatedir LOCALSTATEDIR         Localstate data directory.
  --mandir MANDIR                       Manual page directory.
  --sbindir SBINDIR                     System executable directory.
  --sharedstatedir SHAREDSTATEDIR       Architecture-independent data directory.
  --sysconfdir SYSCONFDIR               Sysconf data directory.
  --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).
  --default-both-libraries {shared,static,auto}
                                        Default library type for both_libraries
                                        (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.
  --native-file NATIVE_FILE             File containing overrides for native
                                        compilation environment.
  --cross-file CROSS_FILE               File describing cross compilation
                                        environment.
  -v, --version                         show program's version number and exit
  --fatal-meson-warnings                Make all Meson warnings fatal
  --reconfigure                         Set options and reconfigure the project.
                                        Useful when new options have been added
                                        to the project and the default value is
                                        not working.
  --wipe                                Wipe build directory and reconfigure
                                        using previous command line options.
                                        Useful when build directory got
                                        corrupted, or when rebuilding with a
                                        newer version of meson.
  --clearcache                          Clear cached state (e.g. found
                                        dependencies). Since 1.3.0.

如需更多資訊,請參閱Meson 簡介頁面

範例

使用預設值設定 builddir

meson setup builddir

subprojects

(自 0.49.0 起)

$ meson subprojects [-h]
                    {update,checkout,download,foreach,purge,packagefiles}
                    ...

管理 Meson 專案的子專案。自 0.59.0 起,預設會並行在多個子專案上執行命令,如果不希望如此,請使用 --num-processes=1

0.64.0 起,update 子命令將不再從 WrapDB 下載新的 wrap 檔案。請改用 meson wrap update 命令。

options:
  -h, --help                            show this help message and exit

Commands:
  {update,checkout,download,foreach,purge,packagefiles}
    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

test

$ meson test [-h] [--maxfail MAXFAIL] [--repeat REPEAT] [--no-rebuild]
             [--gdb] [--gdb-path GDB_PATH] [-i] [--list]
             [--wrapper WRAPPER] [-C WD] [--suite SUITE] [--no-suite SUITE]
             [--no-stdsplit] [--print-errorlogs] [--benchmark]
             [--logbase LOGBASE] [-j NUM_PROCESSES] [-v] [-q]
             [-t TIMEOUT_MULTIPLIER] [--setup SETUP]
             [--test-args TEST_ARGS] [--max-lines MAX_LINES]
             [args ...]

執行已設定的 Meson 專案的測試。

positional arguments:
  args                                  Optional list of test names to run.
                                        "testname" to run all tests with that
                                        name, "subprojname:testname" to
                                        specifically run "testname" from
                                        "subprojname", "subprojname:" to run all
                                        tests defined by "subprojname".

options:
  -h, --help                            show this help message and exit
  --maxfail MAXFAIL                     Number of failing tests before aborting
                                        the test run. (default: 0, to disable
                                        aborting on failure)
  --repeat REPEAT                       Number of times to run the tests.
  --no-rebuild                          Do not rebuild before running tests.
  --gdb                                 Run test under gdb.
  --gdb-path GDB_PATH                   Path to the gdb binary (default: gdb).
  -i, --interactive                     Run tests with interactive input/output.
  --list                                List available tests.
  --wrapper WRAPPER                     wrapper to run tests with (e.g.
                                        Valgrind)
  -C WD                                 directory to cd into before running
  --suite SUITE                         Only run tests belonging to the given
                                        suite.
  --no-suite SUITE                      Do not run tests belonging to the given
                                        suite.
  --no-stdsplit                         Do not split stderr and stdout in test
                                        logs.
  --print-errorlogs                     Whether to print failing tests' logs.
  --benchmark                           Run benchmarks instead of tests.
  --logbase LOGBASE                     Base name for log file.
  -j NUM_PROCESSES, --num-processes NUM_PROCESSES
                                        How many parallel processes to use.
  -v, --verbose                         Do not redirect stdout and stderr
  -q, --quiet                           Produce less output to the terminal.
  -t TIMEOUT_MULTIPLIER, --timeout-multiplier TIMEOUT_MULTIPLIER
                                        Define a multiplier for test timeout,
                                        for example when running tests in
                                        particular conditions they might take
                                        more time to execute. (<= 0 to disable
                                        timeout)
  --setup SETUP                         Which test setup to use.
  --test-args TEST_ARGS                 Arguments to pass to the specified
                                        test(s) or all tests
  --max-lines MAX_LINES                 Maximum number of lines to show from a
                                        long test log. Since 1.5.0.

如需更多資訊,請參閱單元測試文件

1.2.0 起,您可以在測試名稱的 args 中使用萬用字元。例如,"bas*" 將符合所有名稱以 "bas" 開頭的測試。

1.2.0 起,如果提供的測試名稱或萬用字元不符合任何測試,則會發生錯誤。

範例

執行專案的測試

meson test -C builddir

僅執行 specific_test_1specific_test_2

meson test -C builddir specific_test_1 specific_test_2

wrap

$ meson wrap [-h]
             {list,search,install,update,info,status,promote,update-db} ...

用於管理 WrapDB 相依性的公用程式。

options:
  -h, --help                            show this help message and exit

Commands:
  {list,search,install,update,info,status,promote,update-db}
    list                                show all available projects
    search                              search the db by name
    install                             install the specified project
    update                              Update wrap files from WrapDB (Since
                                        0.63.0)
    info                                show available versions of a project
    status                              show installed and available versions of
                                        your projects
    promote                             bring a subsubproject up to the master
                                        project
    update-db                           Update list of projects available in
                                        WrapDB (Since 0.61.0)

如需更多資訊,請參閱WrapDB 工具文件

devenv

(自 0.58.0 起)

$ meson devenv [-h] [-C BUILDDIR] [--workdir WORKDIR] [--dump [DUMP]]
               [--dump-format {sh,export,vscode}]
               ...

執行命令,如果未提供命令,則開啟互動式 shell,並設定環境以從建構目錄執行專案,而無需安裝。

我們會自動處理 bash 並據此設定 $PS1。如果不希望自動覆寫 $PS1(可能您有精美的自訂提示),請設定 $MESON_DISABLE_PS1_OVERRIDE 環境變數,並在設定自訂提示時使用 $MESON_PROJECT_NAME,例如使用如下程式碼片段

...
if [[ -n "${MESON_PROJECT_NAME-}" ]];
then
  PS1+="[ ${MESON_PROJECT_NAME} ]"
fi
...

除了使用meson.add_devenv()設定的變數之外,還會在環境中設定這些變數。

  • MESON_DEVENV 定義為 '1'
  • MESON_PROJECT_NAME 定義為主要專案的名稱。
  • PKG_CONFIG_PATH 包括 Meson 產生 -uninstalled.pc 檔案的目錄。
  • PATH 包括每個目錄,其中包含將安裝到 bindir 的可執行檔。在 Windows 上,它也包括每個目錄,其中包含執行這些可執行檔所需的 DLL。
  • LD_LIBRARY_PATH 包括每個目錄,其中包含將安裝到 libdir 的共用程式庫。這允許使用某些程式庫的自訂建構來執行系統應用程式。例如,在從 git 建構 GTK 時執行系統 GEdit。在 OSX 上,環境變數為 DYLD_LIBRARY_PATH,而在 Windows 上則為 PATH
  • GI_TYPELIB_PATH 包括建構 GObject Introspection 型別程式庫的每個目錄。使用 gnome.generate_gir() 時會自動設定。
  • GSETTINGS_SCHEMA_DIR 自 0.59.0 起,包括編譯 GSettings 結構描述的每個目錄。使用 gnome.compile_schemas() 時會自動設定。請注意,當在多個目錄中使用 gnome.compile_schemas() 時,這需要 GLib >= 2.64。
  • 當交叉編譯並定義該屬性時,自 1.0.0 起 QEMU_LD_PREFIX 會設定為交叉編譯檔案中的 sys_root 值。

自 0.62.0 起,如果正在安裝 bash 補全指令碼且 shell 為 bash,則會自動載入它們。

自 0.62.0 版起,當 GDB 輔助腳本 (*-gdb.py、*-gdb.gdb 和 *-gdb.csm) 安裝時,若其程式庫名稱與正在建置的名稱相符,Meson 會將所需的自動載入命令加入 <builddir>/.gdbinit 檔案中。從頂層建置目錄執行 gdb 時,該檔案會被 gdb 自動載入。如果 Python 腳本需要載入其他 Python 模組,則可能需要使用 meson.add_devenv() 修改 PYTHONPATH

自 0.63.0 版起,當為 Windows 進行交叉編譯時,會使用 WINEPATH 而非 PATH,這允許使用 wine 執行 Windows 可執行檔。請注意,由於 WINEPATH 的大小目前限制為 1024 個字元,因此會使用相對於建置目錄根目錄的路徑。這表示執行 wine 時,目前的工作目錄必須是建置目錄的根目錄。

自 1.1.0 版起meson devenv --dump [<filename>] 命令接受一個可選的檔案名稱參數,以將環境寫入檔案,而不是列印到標準輸出。

自 1.1.0 版起,新增了 --dump-format 參數來選擇應使用的 Shell 格式。目前支援 3 種格式:

  • sh:行的格式為 VAR=/prepend:$VAR:/append
  • export:與 sh 相同,但額外包含 export VAR 行。
  • vscode:與 sh 相同,但不包含 $VAR 替換,因為 vscode 似乎不正確地支援它們。
positional arguments:
  command                           Command to run in developer environment
                                    (default: interactive shell)

options:
  -h, --help                        show this help message and exit
  -C BUILDDIR                       Path to build directory
  --workdir WORKDIR, -w WORKDIR     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)

格式

(自 1.5.0 版起)

$ meson format [-h] [-q | -i] [-r] [-c meson.format] [-e] [-o OUTPUT]
               [sources ...]

指定 meson.build 文件的格式。為了與 muon 相容,fmtformat 的別名。

positional arguments:
  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)
  -c meson.format, --configuration meson.format
                                        read configuration from meson.format
  -e, --editor-config                   try to read configuration from
                                        .editorconfig
  -o OUTPUT, --output OUTPUT            output file (implies having exactly one
                                        input)

設定檔是 .ini 檔案。如果要在分析的提供之建置檔案旁邊存在 meson.format 檔案,且命令列上未提供設定檔,則會自動使用 meson.format 檔案。

如果命令列上未提供任何建置檔案,則會分析目前目錄中的 meson.build 檔案。

以下選項會被識別:

  • max_line_length (int):當陣列、字典、函式或方法的長度超過此值時,會將其格式化為每個引數一行 (預設值為 80)。
  • indent_by (str):要使用的縮排 (預設值為四個空格 ' ')。
  • space_array (bool):是否在 [] 和陣列引數之間新增空格 (預設值為 false)。
  • kwargs_force_multiline (bool):如果為 true,只要有關鍵字引數,就會將引數格式化為每個引數一行 (預設值為 false)。
  • wide_colon (bool):如果為 true,會在字典和關鍵字引數中的冒號之前放置一個空格 (預設值為 false)。
  • no_single_comma_function (bool):如果為 true,即使使用多行引數,如果只有一個引數,也不會將逗號附加到函式引數 (預設值為 false)。
  • end_of_line ('cr'、'lf'、'crlf'、'native'):要使用的行尾符號(在使用 --output--inline 引數時套用)(預設值為 'native')。
  • indent_before_comments (str):在內嵌註解之前要使用的縮排 (預設值為兩個空格 ' ')。
  • simplify_string_literals (bool):如果為 true,如果多行字串不包含換行符號,則會將其轉換為單行字串。如果格式化字串不包含替代,則會將其轉換為一般字串 (預設值為 true)。
  • insert_final_newline (bool):如果為 true,強制 meson.build 檔案以換行符號結尾 (預設值為 true)。
  • tab_width (int):Tab 停駐點的寬度,用於在 indent_by 使用 Tab 字元時計算行長度 (預設值為 4)。
  • sort_files (bool):如果為 true,files() 函式的引數會按字母順序排序 (預設值為 false)。
  • group_arg_value (bool):如果為 true,具有 -- 前綴的字串引數,後面接著不帶 -- 前綴的字串引數,會在多行引數中分組在同一行 (預設值為 false)。
  • use_editor_config (bool):如果為 true,也會使用來自 .editorconfig 的設定。

前六個選項與 muon fmt 命令相同。

也可以透過在命令列上提供 --editor-config 選項,或使用設定檔中的 use_editor_config 選項來使用 .editorconfig 檔案。

當指定 --recursive 選項時,也會分析來自 subdirmeson.build 檔案(必須與 --inplace--check-only 選項一起使用)。

muon fmt 的差異

meson format 命令應與 muon fmt 命令相容。但是,它具有更多功能和一些差異:

  • 依預設,meson format 會在內嵌註解之前放置兩個空格,而 muon fmt 只會放置一個。
  • muon fmt 可能會混合 crlf 和 lf 行尾符號,因為它無法識別它們。meson format 在其產生的輸出中將始終保持一致。
  • muon fmt 只會識別來自 .editorconfig 檔案的 indent_by 選項。meson format 還會識別 max_line_lengthend_of_lineinsert_final_newlinetab_width 選項。
  • meson format 有許多額外的格式規則 (請參閱上面的選項清單)。

搜尋結果是: