Skip to content

命令行参数 ​

shell
#查看特定命令帮助信息
meson command --help

下面列一些常用的,详细的请去官网查阅文档。

configure ​

txt
meson configure [-h] [--prefix PREFIX] [--bindir BINDIR]
                  [--datadir DATADIR] [--includedir INCLUDEDIR]
                  [--infodir INFODIR] [--libdir LIBDIR]
                  [--libexecdir LIBEXECDIR] [--localedir LOCALEDIR]
                  [--localstatedir LOCALSTATEDIR] [--mandir MANDIR]
                  [--sbindir SBINDIR] [--sharedstatedir SHAREDSTATEDIR]
                  [--sysconfdir SYSCONFDIR]
                  [--auto-features {enabled,disabled,auto}]
                  [--backend {ninja,vs,vs2010,vs2015,vs2017,vs2019,xcode}]
                  [--buildtype {plain,debug,debugoptimized,release,minsize,custom}]
                  [--debug] [--default-library {shared,static,both}]
                  [--errorlogs] [--install-umask INSTALL_UMASK]
                  [--layout {mirror,flat}] [--optimization {0,g,1,2,3,s}]
                  [--stdsplit] [--strip] [--unity {on,off,subprojects}]
                  [--unity-size UNITY_SIZE] [--warnlevel {0,1,2,3}]
                  [--werror]
                  [--wrap-mode {default,nofallback,nodownload,forcefallback,nopromote}]
                  [--force-fallback-for FORCE_FALLBACK_FOR]
                  [--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]
                  [builddir]
positional arguments:
  builddir
optional arguments
-h, --helpshow this help message and exit
--prefix PREFIXInstallation prefix.
--bindir BINDIRExecutable directory.
--datadir DATADIRData file directory.
--includedir INCLUDEDIRHeader file directory.
--infodir INFODIRInfo page directory.
--libdir LIBDIRLibrary directory.
--libexecdir LIBEXECDIRLibrary executable directory.
--localedir LOCALEDIRLocale data directory.
--localstatedir LOCALSTATEDIRLocalstate data directory.
--mandir MANDIRManual page directory.
--sbindir SBINDIRSystem executable directory.
--sharedstatedir SHAREDSTATEDIRArchitecture-independent data directory.
--sysconfdir SYSCONFDIRSysconf data directory.
--auto-featuresOverride value of all 'auto' features(default: auto).
--backendBackend to use (default: ninja).
--buildtypeBuild type to use (default: debug).
--debugDebug
--default-libraryDefault library type (default: shared).
--errorlogsWhether to print the logs from failingtests
--install-umask INSTALL_UMASKDefault umask to apply on permissions of installed files (default: 022).
--layoutBuild directory layout (default:mirror).
--optimizationOptimization level (default: 0).
--stdsplitSplit stdout and stderr in test logs
--stripStrip targets on install
--unityUnity build (default: off).
--unity-size UNITY_SIZEUnity block size (default: (2, None,4)).
--warnlevelCompiler warning level to use (default:1).
--werrorTreat warnings as errors
--wrap-modeWrap mode (default: default).
--force-fallback-for FORCE_FALLBACK_FORforce fallback for those subprojects(default: []).
--pkg-config-path PKG_CONFIG_PATHList of additional paths for pkg-configto search (default: []). (just for host machine)
--build.pkg-config-path BUILD.PKG_CONFIG_PATHList of additional paths for pkg-config to search (default: []). (just for build machine)
--cmake-prefix-path CMAKE_PREFIX_PATHList of additional prefixes for cmake to earch (default: []). (just for host achine)
--build.cmake-prefix-path BUILD.CMAKE_PREFIX_PATHist of additional prefixes for cmake to earch (default: []). (just for build achine)
-D optionSet the value of an option, can be used everal times to set multiple ptions.
--clearcacheClear cached state (e.g. founddependencies)

Examples: ​

shell
#List all available options:
meson configure builddir
#Change value of a single option:
meson configure builddir -Doption=new_value

compile ​

txt
$ meson compile [-h] [--clean] [-C BUILDDIR] [-j JOBS] [-l LOAD_AVERAGE]
                [-v] [--ninja-args NINJA_ARGS] [--vs-args VS_ARGS]
                [--xcode-args XCODE_ARGS]
                [TARGET ...]
optional arguments
-h, --helpshow this help message and exit
--cleanClean the build directory.
-C BUILDDIRThe directory containing build files tobe built.
-j JOBS, --jobs JOBSThe 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_AVERAGEThe system load average to try to maintain (if supported).
-v, --verboseShow more verbose output.
--ninja-args NINJA_ARGSArguments to pass to ninja (applied only on ninja backend).
--vs-args VS_ARGSArguments to pass to msbuild (applied only on vs backend).
--xcode-args XCODE_ARGSArguments to pass to xcodebuild (applied only on xcode backend).

Targets ​

(since 0.55.0)
TARGET has the following syntax [PATH/]NAME[:TYPE], where:

  • NAME: name of the target from meson.build (e.g. foo from executable('foo', ...)).
  • PATH: path to the target relative to the root meson.build file. Note: relative path for a target specified in the root meson.build is ./.
  • TYPE: type of the target. Can be one of the following: 'executable', 'static_library', 'shared_library', 'shared_module', 'custom', 'run', 'jar'.
    PATH and/or TYPE can be omitted if the resulting TARGET can be used to uniquely identify the target in meson.build.

Backend specific arguments ​

(since 0.55.0) BACKEND-args use the following syntax:

shell
#If you only pass a single string, then it is considered to have all values separated by commas. Thus invoking the following command:
$ meson compile --ninja-args=-n,-d,explain
# would add -n, -d and explain arguments to ninja invocation.
#If you need to have commas or spaces in your string values, then you need to pass the value with proper shell quoting like this:
$ meson compile "--ninja-args=['a,b', 'c d']"

Examples ​

shell
#Build the project:
meson compile -C builddir
#Execute a dry run on ninja backend with additional debug info:
meson compile --ninja-args=-n,-d,explain
#Build three targets: two targets that have the same foo name, but different type, and a bar target:
meson compile foo:shared_library foo:static_library bar
#Produce a coverage html report (if available):
meson compile coverage-html

subprojects ​

(since 0.49.0)

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

Manages subprojects of the Meson project.

optional arguments:
  -h, --help                          show this help message and exit

Commands:

command
updateUpdate all subprojects from wrap files
checkoutCheckout a branch (git only)
downloadEnsure 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.
foreachExecute a command in each subproject directory.

test ​

$ meson test [-h] [--repeat REPEAT] [--no-rebuild] [--gdb]
             [--gdb-path GDB_PATH] [--list] [--wrapper WRAPPER] [-C WD]
             [--suite SUITE] [--no-suite SUITE] [--no-stdsplit]
             [--print-errorlogs] [--benchmark] [--logbase LOGBASE]
             [--num-processes NUM_PROCESSES] [-v] [-q]
             [-t TIMEOUT_MULTIPLIER] [--setup SETUP]
             [--test-args TEST_ARGS]
             [args ...]
args
-h, --helpshow this help message and exit
--repeat REPEATNumber of times to run the tests.
--no-rebuildDo not rebuild before running tests.
--gdbRun test under gdb.
--gdb-path GDB_PATHPath to the gdb binary (default: gdb).
--listList available tests.
--wrapper WRAPPERwrapper to run tests with (e.g.Valgrind)
-C WDdirectory to cd into before running
--suite SUITEOnly run tests belonging to the given suite.
--no-suite SUITEDo not run tests belonging to the given suite.
--no-stdsplitDo not split stderr and stdout in test logs.
--print-errorlogsWhether to print failing tests' logs.
--benchmarkRun benchmarks instead of tests.
--logbase LOGBASEBase name for log file.
--num-processes NUM_PROCESSESHow many parallel processes to use.
-v, --verboseDo not redirect stdout and stderr
-q, --quietProduce less output to the terminal.
-t TIMEOUT_MULTIPLIER, --timeout-multiplierTIMEOUT_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 SETUPWhich test setup to use.
--test-args TEST_ARGSArguments to pass to the specified test(s) or all tests

example ​

shell
#启动测试
meson test -C builddir
#启动测试用例1和2
meson test -C builddir specific_test_1 specific_test_2