Functions

This document lists all functions available in meson.build files. See the root manual document for an overview of all features.

add_global_arguments()

Adds global arguments to the compiler command line.

Signature

# Adds global arguments to the compiler command line
void add_global_arguments(
  str Compiler argument...,  # The compiler arguments to add

  # Keyword arguments:
  language : list[str]  [required]  # Specifies the language(s) that the arguments should be
  native   : bool                   # A boolean specifying whether the arguments should be
)
Note:

Usually you should use add_project_arguments() instead, because that works even when you project is used as a subproject.

Note:

You must pass always arguments individually arg1, arg2, ... rather than as a string 'arg1 arg2', ...

Arguments

The function accepts between 0 and infinity variadic arguments (Compiler argument...) of type str.

The compiler arguments to add

The function add_global_arguments() accepts the following keyword arguments:

Name Type Description Tags
language list[str]

Specifies the language(s) that the arguments should be applied to. If a list of languages is given, the arguments are added to each of the corresponding compiler command lines. Note that there is no way to remove an argument set in this way. If you have an argument that is only used in a subset of targets, you have to specify it in per-target flags.

native bool

A boolean specifying whether the arguments should be applied to the native or cross compilation. If true the arguments will only be used for native compilations. If false the arguments will only be used in cross compilations. If omitted, the flags are added to native compilations if compiling natively and cross compilations (only) when cross compiling.

(since 0.48.0)

default = false


Adds global arguments to the linker command line.

Like add_global_arguments() but the arguments are passed to the linker.

Signature

# Adds global arguments to the linker command line
void add_global_link_arguments(
  str Linker argument...,  # The linker arguments to add

  # Keyword arguments:
  language : list[str]  [required]  # Specifies the language(s) that the arguments should be
  native   : bool                   # A boolean specifying whether the arguments should be
)
Note:

Usually you should use add_project_link_arguments() instead, because that works even when you project is used as a subproject.

Note:

You must pass always arguments individually arg1, arg2, ... rather than as a string 'arg1 arg2', ...

Arguments

The function accepts between 0 and infinity variadic arguments (Linker argument...) of type str.

The linker arguments to add

The function add_global_link_arguments() accepts the following keyword arguments:

Name Type Description Tags


add_languages()

Add programming languages used by the project.

This is equivalent to having them in the project declaration. This function is usually used to add languages that are only used under some conditions.

Returns true if all languages specified were found and false otherwise.

If native is omitted, the languages may be used for either build or host machine, but are never required for the build machine. (i.e. it is equivalent to add_languages(*langs*, native: false, required: *required*) and add_languages(*langs*, native: true, required: false). This default behaviour may change to native: false in a future Meson version.

Signature

# Add programming languages used by the project
bool add_languages(
  str Language...,  # The languages to add

  # Keyword arguments:
  native   : bool            # If set to `true`, the language will be used to compile for the build
  required : bool | feature  # If set to `true`, Meson will halt if any of the languages
)

Example

project('foobar', 'c')

if compiling_for_osx
  add_languages('objc')
endif
if add_languages('cpp', required : false)
  executable('cpp-app', 'main.cpp')
endif

# More code...

Arguments

The function accepts between 0 and infinity variadic arguments (Language...) of type str.

The languages to add

The function add_languages() accepts the following keyword arguments:

Name Type Description Tags
native bool

If set to true, the language will be used to compile for the build machine, if false, for the host machine.

(since 0.54.0)

required bool | feature

If set to true, Meson will halt if any of the languages specified are not found. (since 0.47.0) The value of a feature option can also be passed.

default = true


add_project_arguments()

Adds project specific arguments to the compiler command line.

This function behaves in the same way as add_global_arguments() except that the arguments are only used for the current project, they won't be used in any other subproject.

Signature

# Adds project specific arguments to the compiler command line
void add_project_arguments(
  str Compiler argument...,  # The compiler arguments to add

  # Keyword arguments:
  language : list[str]  [required]  # Specifies the language(s) that the arguments should be
  native   : bool                   # A boolean specifying whether the arguments should be
)
Note:

You must pass always arguments individually arg1, arg2, ... rather than as a string 'arg1 arg2', ...

Arguments

The function accepts between 0 and infinity variadic arguments (Compiler argument...) of type str.

The compiler arguments to add

The function add_project_arguments() accepts the following keyword arguments:

Name Type Description Tags
language list[str]

Specifies the language(s) that the arguments should be applied to. If a list of languages is given, the arguments are added to each of the corresponding compiler command lines. Note that there is no way to remove an argument set in this way. If you have an argument that is only used in a subset of targets, you have to specify it in per-target flags.

native bool

A boolean specifying whether the arguments should be applied to the native or cross compilation. If true the arguments will only be used for native compilations. If false the arguments will only be used in cross compilations. If omitted, the flags are added to native compilations if compiling natively and cross compilations (only) when cross compiling.

(since 0.48.0)

default = false


add_project_dependencies()

Adds arguments to the compiler and linker command line, so that the given set of dependencies is included in all build products for this project.

Signature

(since 0.63.0)

# Adds arguments to the compiler and linker command line, so that the
void add_project_dependencies(
  dep dependencies...,  # The dependencies to add; if internal dependencies are included, they must not include any built object

  # Keyword arguments:
  language : list[str]  [required]  # Specifies the language(s) that the arguments should be
  native   : bool                   # A boolean specifying whether the arguments should be
)

Arguments

The function accepts between 0 and infinity variadic arguments (dependencies...) of type dep.

The dependencies to add; if internal dependencies are included, they must not include any built object.

The function add_project_dependencies() accepts the following keyword arguments:

Name Type Description Tags
language list[str]

Specifies the language(s) that the arguments should be applied to. If a list of languages is given, the arguments are added to each of the corresponding compiler command lines. Note that there is no way to remove an argument set in this way. If you have an argument that is only used in a subset of targets, you have to specify it in per-target flags.

native bool

A boolean specifying whether the arguments should be applied to the native or cross compilation. If true the arguments will only be used for native compilations. If false the arguments will only be used in cross compilations. If omitted, the flags are added to native compilations if compiling natively and cross compilations (only) when cross compiling.

(since 0.48.0)

default = false


Adds project specific arguments to the linker command line.

Like add_project_arguments() but the arguments are passed to the linker.

Signature

# Adds project specific arguments to the linker command line
void add_project_link_arguments(
  str Linker argument...,  # The linker arguments to add

  # Keyword arguments:
  language : list[str]  [required]  # Specifies the language(s) that the arguments should be
  native   : bool                   # A boolean specifying whether the arguments should be
)
Note:

You must pass always arguments individually arg1, arg2, ... rather than as a string 'arg1 arg2', ...

Arguments

The function accepts between 0 and infinity variadic arguments (Linker argument...) of type str.

The linker arguments to add

The function add_project_link_arguments() accepts the following keyword arguments:

Name Type Description Tags


add_test_setup()

Add a custom test setup. This setup can be used to run the tests with a custom setup, for example under Valgrind.

To use the test setup, run meson test --setup=*name* inside the build dir.

Note that all these options are also available while running the meson test script for running tests instead of ninja test or msbuild RUN_TESTS.vcxproj, etc depending on the backend.

Signature

# Add a custom test setup
void add_test_setup(
  str name,     # The name of the test setup

  # Keyword arguments:
  env                : env | list[str] | dict[str]   # environment variables to set
  exclude_suites     : list[str]                     # A list of test suites that should be excluded when using this setup
  exe_wrapper        : list[str | external_program]  # The command or script followed by the arguments to it
  gdb                : bool                          # If `true`, the tests are also run under `gdb`
  is_default         : bool                          # Set whether this is the default test setup
  timeout_multiplier : int                           # A number to multiply the test timeout with
)

Arguments

The function add_test_setup() accepts the following positional arguments:

Name Type Description Tags
name str

The name of the test setup

Finally, add_test_setup() accepts the following keyword arguments:

Name Type Description Tags
env env | list[str] | dict[str]

environment variables to set , such as ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling. (Since 0.52.0) A dictionary is also accepted.

exclude_suites list[str]

A list of test suites that should be excluded when using this setup. Suites specified in the --suite option to meson test will always run, overriding add_test_setup if necessary.

(since 0.57.0)

exe_wrapper list[str | external_program]

The command or script followed by the arguments to it

gdb bool

If true, the tests are also run under gdb

default = false

is_default bool

Set whether this is the default test setup. If true, the setup will be used whenever meson test is run without the --setup option.

(since 0.49.0)

default = false

timeout_multiplier int

A number to multiply the test timeout with. Since 0.57 if timeout_multiplier is <= 0 the test has infinite duration, in previous versions of Meson the test would fail with a timeout immediately.

default = 1


alias_target()

This function creates a new top-level target. Like all top-level targets, this integrates with the selected backend. For instance, with you can run it as meson compile target_name. This is a dummy target that does not execute any command, but ensures that all dependencies are built. Dependencies can be any build target. Since 0.60.0, this includes run_tgt.

Signature

(since 0.52.0)

# This function creates a new top-level target
alias_tgt alias_target(
  str target_name,     # The name of the alias target
  tgt Dep...,          # The targets to depend on
)

Arguments

The function alias_target() accepts the following positional arguments:

Name Type Description Tags
target_name str

The name of the alias target

Additionally, the function accepts between 1 and infinity variadic arguments (Dep...) of type tgt.

The targets to depend on


assert()

Abort with an error message if condition evaluates to false.

Signature

# Abort with an error message if `condition` evaluates to `false`
void assert(
  bool condition,     # Abort if this evaluates to `false`
  str  [message],     # The error message to print
)
Note:

The message argument is optional since 0.53.0 and defaults to print the condition statement.

Arguments

The function assert() accepts the following positional arguments:

Name Type Description Tags
condition bool

Abort if this evaluates to false

message str

The error message to print.

[optional]


benchmark()

Creates a benchmark item that will be run when the benchmark target is run. The behavior of this function is identical to test() except for:

  • benchmark() has no is_parallel keyword because benchmarks are not run in parallel
  • benchmark() does not automatically add the MALLOC_PERTURB_ environment variable

Defined benchmarks can be run in a backend-agnostic way by calling meson test --benchmark inside the build dir, or by using backend-specific commands, such as ninja benchmark or msbuild RUN_TESTS.vcxproj.

Signature

# Creates a benchmark item that will be run when the benchmark target is
void benchmark(
  str                                                           name,           # The *unique* test id
  exe | jar | external_program | file | custom_tgt | custom_idx executable,     # The program to execute

  # Keyword arguments:
  args        : list[str | file | tgt]        # Arguments to pass to the executable
  depends     : list[build_tgt | custom_tgt]  # specifies that this test depends on the specified
  env         : env | list[str] | dict[str]   # environment variables to set, such as `['NAME1=value1',
  priority    : int                           # specifies the priority of a test
  protocol    : str                           # specifies how the test results are parsed and can
  should_fail : bool                          # when true the test is considered passed if the
  suite       : str | list[str]               # `'label'` (or list of labels `['label1', 'label2']`)
  timeout     : int                           # the amount of seconds the test is allowed to run, a test
  verbose     : bool                          # if true, forces the test results to be logged as if `--verbose` was passed
  workdir     : str                           # absolute path that will be used as the working directory
)
Note:

Prior to 0.52.0 benchmark would warn that depends and priority were unsupported, this is incorrect.

Arguments

The function benchmark() accepts the following positional arguments:

Name Type Description Tags
name str

The unique test id

executable exe | jar | external_program | file | custom_tgt | custom_idx

The program to execute. (Since 1.4.0) A CustomTarget is also accepted.

Finally, benchmark() accepts the following keyword arguments:

Name Type Description Tags
args list[str | file | tgt]

Arguments to pass to the executable

depends list[build_tgt | custom_tgt]

specifies that this test depends on the specified target(s), even though it does not take any of them as a command line argument. This is meant for cases where test finds those targets internally, e.g. plugins or globbing. Those targets are built before test is executed even if they have build_by_default : false.

(since 0.46.0)

env env | list[str] | dict[str]

environment variables to set, such as ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling. (Since 0.52.0) A dictionary is also accepted.

priority int

specifies the priority of a test. Tests with a higher priority are started before tests with a lower priority. The starting order of tests with identical priorities is implementation-defined. The default priority is 0, negative numbers are permitted.

(since 0.52.0)

default = 0

protocol str

specifies how the test results are parsed and can be one of exitcode, tap, or gtest. For more information about test harness protocol read Unit Tests. The following values are accepted:

  • exitcode: the executable's exit code is used by the test harness to record the outcome of the test).

  • tap: Test Anything Protocol.

  • gtest (since 0.55.0): for Google Tests.

  • rust (since 0.56.0): for native rust tests

(since 0.50.0)

default = 'exitcode'

should_fail bool

when true the test is considered passed if the executable returns a non-zero return value (i.e. reports an error)

default = false

suite str | list[str]

'label' (or list of labels ['label1', 'label2']) attached to this test. The suite name is qualified by a (sub)project name resulting in (sub)project_name:label. In the case of a list of strings, the suite names will be (sub)project_name:label1, (sub)project_name:label2, etc.

timeout int

the amount of seconds the test is allowed to run, a test that exceeds its time limit is always considered failed, defaults to 30 seconds. Since 0.57 if timeout is <= 0 the test has infinite duration, in previous versions of Meson the test would fail with a timeout immediately.

default = 30

verbose bool

if true, forces the test results to be logged as if --verbose was passed to meson test.

(since 0.62.0)

default = false

workdir str

absolute path that will be used as the working directory for the test


both_libraries()

Builds both a static and shared library with the given sources. Positional and keyword arguments are otherwise the same as for library(). Source files will be compiled only once and object files will be reused to build both shared and static libraries, unless b_staticpic user option or pic argument are set to false in which case sources will be compiled twice.

Signature

(since 0.46.0)

# Builds both a static and shared library with the given sources
both_libs both_libraries(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  <lang>_shared_args           : list[str]                                                               # Arguments that are only passed to a shared library
  <lang>_static_args           : list[str]                                                               # Arguments that are only passed to a static library
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  darwin_versions              : str | int | list[str]                                                   # Defines the `compatibility version` and `current version` for the dylib on macOS
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  pic                          : bool                                                                    # Builds the library as positional independent code
  prelink                      : bool                                                                    # If `true` the object files in the target will be prelinked,
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  soversion                    : str | int                                                               # A string or integer specifying the soversion of this shared library,
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  vala_shared_args             : list[str | file]                                                        # Arguments that are only passed to a shared library
  vala_static_args             : list[str | file]                                                        # Arguments that are only passed to a static library
  version                      : str                                                                     # A string specifying the version of this shared library,
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)

Arguments

The function both_libraries() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, both_libraries() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

<lang>_shared_args list[str]

Arguments that are only passed to a shared library

(since 1.3.0)

<lang>_static_args list[str]

Arguments that are only passed to a static library

(since 1.3.0)

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

darwin_versions str | int | list[str]

Defines the compatibility version and current version for the dylib on macOS. If a list is specified, it must be either zero, one, or two elements. If only one element is specified or if it's not a list, the specified value will be used for setting both compatibility version and current version. If unspecified, the soversion will be used as per the aforementioned rules.

(since 0.48.0)

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

pic bool

Builds the library as positional independent code (so it can be linked into a shared library). This option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be disabled on OS X.

(since 0.36.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "rlib" or "dylib" crate depending on the library type being build.

  • 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

soversion str | int

A string or integer specifying the soversion of this shared library, such as 0. On Linux and Windows this is used to set the soversion (or equivalent) in the filename. For example, if soversion is 4, a Windows DLL will be called foo-4.dll and one of the aliases of the Linux shared library would be libfoo.so.4. If this is not specified, the first part of version is used instead (see below). For example, if version is 3.6.0 and soversion is not defined, it is set to 3.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

vala_shared_args list[str | file]

Arguments that are only passed to a shared library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

vala_static_args list[str | file]

Arguments that are only passed to a static library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

version str

A string specifying the version of this shared library, such as 1.1.0. On Linux and OS X, this is used to set the shared library version in the filename, such as libfoo.so.1.1.0 and libfoo.1.1.0.dylib. If this is not specified, soversion is used instead (see above).

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

(Since 1.3.0) custom_idx are supported

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


build_target()

Creates a build target whose type can be set dynamically with the target_type keyword argument.

target_type may be set to one of:

This declaration:

executable(<arguments and keyword arguments>)

is equivalent to this:

build_target(<arguments and keyword arguments>, target_type : 'executable')

The lists for the kwargs (such as sources, objects, and dependencies) are always flattened, which means you can freely nest and add lists while creating the final list.

The returned object also has methods that are documented in build_tgt.

*"jar" is deprecated because it is fundementally a different thing than the other build_target types.

Signature

# Creates a build target whose type can be set dynamically with the
build_tgt build_target(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  <lang>_shared_args           : list[str]                                                               # Arguments that are only passed to a shared library
  <lang>_static_args           : list[str]                                                               # Arguments that are only passed to a static library
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  darwin_versions              : str | int | list[str]                                                   # Defines the `compatibility version` and `current version` for the dylib on macOS
  dependencies                 : list[dep]                                                               # one or more dependency objects
  export_dynamic               : bool                                                                    # when set to true causes the target's symbols to be
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implib                       : bool | str                                                              # When set to true, an import library is generated for the
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  java_resources               : structured_src                                                          # Resources to be added to the jar
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  main_class                   : str                                                                     # Main class for running the built jar
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  pic                          : bool                                                                    # Builds the library as positional independent code
  pie                          : bool                                                                    # Build a position-independent executable
  prelink                      : bool                                                                    # If `true` the object files in the target will be prelinked,
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  soversion                    : str | int                                                               # A string or integer specifying the soversion of this shared library,
  target_type                  : str                                                                     # The actual target type to build
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  vala_shared_args             : list[str | file]                                                        # Arguments that are only passed to a shared library
  vala_static_args             : list[str | file]                                                        # Arguments that are only passed to a static library
  version                      : str                                                                     # A string specifying the version of this shared library,
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)

Arguments

The function build_target() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, build_target() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

<lang>_shared_args list[str]

Arguments that are only passed to a shared library

(since 1.3.0)

<lang>_static_args list[str]

Arguments that are only passed to a static library

(since 1.3.0)

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

darwin_versions str | int | list[str]

Defines the compatibility version and current version for the dylib on macOS. If a list is specified, it must be either zero, one, or two elements. If only one element is specified or if it's not a list, the specified value will be used for setting both compatibility version and current version. If unspecified, the soversion will be used as per the aforementioned rules.

(since 0.48.0)

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

export_dynamic bool

when set to true causes the target's symbols to be dynamically exported, allowing modules built using the shared_module() function to refer to functions, variables and other symbols defined in the executable itself. Implies the implib argument.

(since 0.45.0)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implib bool | str

When set to true, an import library is generated for the executable (the name of the import library is based on exe_name). Alternatively, when set to a string, that gives the base name for the import library. The import library is used when the returned build target object appears in link_with: elsewhere. Only has any effect on platforms where that is meaningful (e.g. Windows). Implies the export_dynamic argument.

(since 0.42.0)

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

java_resources structured_src

Resources to be added to the jar

(since 0.62.0)

main_class str

Main class for running the built jar

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

pic bool

Builds the library as positional independent code (so it can be linked into a shared library). This option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be disabled on OS X.

(since 0.36.0)

pie bool

Build a position-independent executable.

(since 0.49.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "rlib" or "dylib" crate depending on the library type being build.

  • 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

soversion str | int

A string or integer specifying the soversion of this shared library, such as 0. On Linux and Windows this is used to set the soversion (or equivalent) in the filename. For example, if soversion is 4, a Windows DLL will be called foo-4.dll and one of the aliases of the Linux shared library would be libfoo.so.4. If this is not specified, the first part of version is used instead (see below). For example, if version is 3.6.0 and soversion is not defined, it is set to 3.

target_type str

The actual target type to build

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

vala_shared_args list[str | file]

Arguments that are only passed to a shared library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

vala_static_args list[str | file]

Arguments that are only passed to a static library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

version str

A string specifying the version of this shared library, such as 1.1.0. On Linux and OS X, this is used to set the shared library version in the filename, such as libfoo.so.1.1.0 and libfoo.1.1.0.dylib. If this is not specified, soversion is used instead (see above).

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

This can be used to expose which functions a shared_module loaded by an executable will be allowed to use.

(since 1.3.0)

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


configuration_data()

Creates an empty configuration object. You should add your configuration with the cfg_data method calls and finally use it in a call to configure_file().

Signature

# Creates an empty configuration object
cfg_data configuration_data(
  dict[str | bool | int] [data],   # Optional dictionary to specify an initial data set
)

Arguments

The function configuration_data() accepts the following positional arguments:

Name Type Description Tags
data dict[str | bool | int]

Optional dictionary to specify an initial data set. If provided, each key/value pair is added into the cfg_data object as if the cfg_data.set() method was called for each of them.

(since 0.49.0)

[optional]


configure_file()

This function can run in three modes depending on the keyword arguments passed to it.

When a cfg_data object is passed to the configuration: keyword argument, it takes a template file as the input: (optional) and produces the output: (required) by substituting values from the configuration data as detailed in the configuration file documentation. (since 0.49.0) A dictionary can be passed instead of a cfg_data object.

When a list of strings is passed to the command: keyword argument, it takes any source or configured file as the input: and assumes that the output: is produced when the specified command is run.

(since 0.47.0) When the copy: keyword argument is set to true, this function will copy the file provided in input: to a file in the build directory with the name output: in the current directory.

Signature

# This function can run in three modes depending on the keyword arguments
file configure_file(
  capture       : bool                               # When this argument is set to true,
  command       : list[str | file]                   # As explained above, if specified, Meson does not create
  configuration : cfg_data | dict[str | int | bool]  # As explained above, when passed this will provide the replacement
  copy          : bool                               # As explained above, if specified Meson only
  depfile       : str                                # A dependency file that the command can write listing
  encoding      : str                                # Set the file encoding for the input and output file
  format        : str                                # The format of defines
  input         : str | file                         # The input file name
  install       : bool                               # When true, this generated file is installed during
  install_dir   : str                                # The subdirectory to install the generated file to
  install_mode  : list[str | int]                    # Specify the file mode in symbolic format
  install_tag   : str                                # A string used by the `meson install --tags` command
  macro_name    : str                                # When specified, macro guards will be used instead of '#pragma once'
  output        : str                                # The output file name
  output_format : str                                # The format of the output to generate when no input
)
Warning:

the install_mode kwarg ignored integer values between 0.62 -- 1.1.0.

Arguments

The function configure_file() accepts the following keyword arguments:

Name Type Description Tags
capture bool

When this argument is set to true, Meson captures stdout of the command and writes it to the target file specified as output.

(since 0.41.0)

default = false

command list[str | file]

As explained above, if specified, Meson does not create the file itself but rather runs the specified command, which allows you to do fully custom file generation. (since 0.52.0) The command can contain file objects and more than one file can be passed to the input keyword argument, see custom_target() for details about string substitutions.

configuration cfg_data | dict[str | int | bool]

As explained above, when passed this will provide the replacement data for the input file (if provided) or key value pairs to be written to the output.

copy bool

As explained above, if specified Meson only copies the file from input to output.

(since 0.47.0)

default = false

depfile str

A dependency file that the command can write listing all the additional files this target depends on. A change in any one of these files triggers a reconfiguration.

(since 0.52.0)

encoding str

Set the file encoding for the input and output file. The supported encodings are those of python3, see standard-encodings.

(since 0.47.0)

default = 'utf-8'

format str

The format of defines. It defaults to 'meson', and so substitutes #mesondefine statements and variables surrounded by @ characters, you can also use 'cmake' to replace #cmakedefine statements and variables with the ${variable} syntax. Finally you can use 'cmake@' in which case substitutions will apply on #cmakedefine statements and variables with the @variable@ syntax.

(since 0.46.0)

default = 'meson'

input str | file

The input file name. If it's not specified in configuration mode, all the variables in the configuration: object (see above) are written to the output: file.

install bool

When true, this generated file is installed during the install step, and install_dir must be set and not empty. When false, this generated file is not installed regardless of the value of install_dir. When omitted it defaults to true when install_dir is set and not empty, false otherwise.

(since 0.50.0)

default = false

install_dir str

The subdirectory to install the generated file to (e.g. share/myproject), if omitted or given the value of empty string, the file is not installed.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default the file has no install tag which means it is not being installed when --tags argument is specified.

(since 0.60.0)

macro_name str

When specified, macro guards will be used instead of '#pragma once'. The macro guard name will be the specified name.

(since 1.3.0)

output str

The output file name. (since 0.41.0) may contain @PLAINNAME@ or @BASENAME@ substitutions. In configuration mode, the permissions of the input file (if it is specified) are copied to the output file.

output_format str

The format of the output to generate when no input was specified. It defaults to c, in which case preprocessor directives will be prefixed with #, you can also use nasm, in which case the prefix will be %. (since 1.3.0) json format can also be used.

(since 0.47.0)


custom_target()

Create a custom top level build target. The only positional argument is the name of this target and cannot contain path separators (/ or \). The name of custom target might not be used by every backends, for instance with the Ninja backend, subdir/meson.build containing the example below, ninja -C builddir foo or ninja -C builddir subdir/foo won't work, it is instead ninja -C builddir subdir/file.txt. However, meson compile subdir/foo is accepted.

custom_target('foo', output: 'file.txt', ...)

Since 0.60.0 the name argument is optional and defaults to the basename of the first output (file.txt in the example above).

The list of strings passed to the command keyword argument accept the following special string substitutions:

  • @INPUT@: the full path to the input passed to input. If more than one input is specified, all of them will be substituted as separate arguments only if the command uses '@INPUT@' as a standalone-argument. For instance, this would not work: command : ['cp', './@INPUT@'], but this would: command : ['cp', '@INPUT@'].
  • @OUTPUT@: the full path to the output passed to output. If more than one outputs are specified, the behavior is the same as @INPUT@.
  • @INPUT0@ @INPUT1@ ...: the full path to the input with the specified array index in input
  • @OUTPUT0@ @OUTPUT1@ ...: the full path to the output with the specified array index in output
  • @OUTDIR@: the full path to the directory where the output(s) must be written
  • @DEPFILE@: the full path to the dependency file passed to depfile
  • @PLAINNAME@: the input filename, without a path
  • @BASENAME@: the input filename, with extension removed
  • @PRIVATE_DIR@ (since 0.50.1): path to a directory where the custom target must store all its intermediate files.
  • @SOURCE_ROOT@: the path to the root of the source tree. Depending on the backend, this may be an absolute or a relative to current workdir path.
  • @BUILD_ROOT@: the path to the root of the build tree. Depending on the backend, this may be an absolute or a relative to current workdir path.
  • @CURRENT_SOURCE_DIR@: this is the directory where the currently processed meson.build is located in. Depending on the backend, this may be an absolute or a relative to current workdir path.

(since 0.47.0) The depfile keyword argument also accepts the @BASENAME@ and @PLAINNAME@ substitutions.

The returned object also has methods that are documented in custom_tgt.

Signature

# Create a custom top level build target
custom_tgt custom_target(
  str [name],   # The *unique* id of the custom target

  # Keyword arguments:
  build_always       : bool                                       # If `true` this target is always considered out of
  build_always_stale : bool                                       # If `true` the target is always considered out of date
  build_by_default   : bool                                       # Causes, when set to true, to
  capture            : bool                                       # There are some compilers that can't be told to write
  command            : list[str | file | exe | external_program]  # Command to run to create outputs from inputs
  console            : bool                                       # Keyword argument conflicts with `capture`, and is meant
  depend_files       : list[str | file]                           # files (str,
  depends            : list[build_tgt | custom_tgt]               # Specifies that this target depends on the specified
  depfile            : str                                        # A dependency file that the command can write listing
  env                : env | list[str] | dict[str]                # environment variables to set, such as
  feed               : bool                                       # There are some compilers that can't be told to read
  input              : list[str | file]                           # List of source files
  install            : bool                                       # When true, one or more files of this target are installed during the install step (see `install_dir` for details)
  install_dir        : str | list[str | bool]                     # If only one install_dir is provided, all outputs are installed there
  install_mode       : list[str | int]                            # The file mode and optionally the owner/uid and group/gid
  install_tag        : list[str]                                  # A list of strings, one per output, used by the `meson install --tags` command
  output             : list[str]                                  # List of output files
)
Note:

Assuming that command: is executed by a POSIX sh shell is not portable, notably to Windows. Instead, consider using a native: true executable(), or a python script.

Warning:

the install_mode kwarg ignored integer values between 0.60.0 -- 1.1.0.

Arguments

The function custom_target() accepts the following positional arguments:

Name Type Description Tags
name str

The unique id of the custom target

This posarg is optional since 0.60.0. It defaults to the basename of the first output.

[optional]

Finally, custom_target() accepts the following keyword arguments:

Name Type Description Tags
build_always bool

If true this target is always considered out of date and is rebuilt every time. Equivalent to setting both build_always_stale and build_by_default to true.

DEPRECATED

in 0.47.0

build_always_stale bool

If true the target is always considered out of date. Useful for things such as build timestamps or revision control tags. The associated command is run even if the outputs are up to date.

(since 0.47.0)

default = false

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is false.

(since 0.50.0) If build_by_default is explicitly set to false, install will no longer override it. If build_by_default is not set, install will still determine its default.

(since 0.38.0)

capture bool

There are some compilers that can't be told to write their output to a file but instead write it to standard output. When this argument is set to true, Meson captures stdout and writes it to the target file. Note that your command argument list may not contain @OUTPUT@ when capture mode is active.

default = false

command list[str | file | exe | external_program]

Command to run to create outputs from inputs. The command may be strings or the return value of functions that return file-like objects such as find_program(), executable(), configure_file(), files(), custom_target(), etc. Meson will automatically insert the appropriate dependencies on targets and files listed in this keyword argument. Note: always specify commands in array form ['commandname', '-arg1', '-arg2'] rather than as a string 'commandname -arg1 -arg2' as the latter will not work.

console bool

Keyword argument conflicts with capture, and is meant for commands that are resource-intensive and take a long time to finish. With the Ninja backend, setting this will add this target to Ninja's console pool, which has special properties such as not buffering stdout and serializing all targets in this pool.

(since 0.48.0)

depend_files list[str | file]

files (str, file, or the return value of configure_file() that this target depends on but are not listed in the command keyword argument. Useful for adding regen dependencies.

depends list[build_tgt | custom_tgt]

Specifies that this target depends on the specified target(s), even though it does not take any of them as a command line argument. This is meant for cases where you have a tool that e.g. does globbing internally. Usually you should just put the generated sources as inputs and Meson will set up all dependencies automatically.

depfile str

A dependency file that the command can write listing all the additional files this target depends on, for example a C compiler would list all the header files it included, and a change in any one of these files triggers a recompilation.

(since 0.47.0) the @BASENAME@ and @PLAINNAME@ substitutions are also accepted.

env env | list[str] | dict[str]

environment variables to set, such as {'NAME1': 'value1', 'NAME2': 'value2'} or ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling.

(since 0.57.0)

feed bool

There are some compilers that can't be told to read their input from a file and instead read it from standard input. When this argument is set to true, Meson feeds the input file to stdin. Note that your argument list may not contain @INPUT@ when feed mode is active.

(since 0.59.0)

default = false

input list[str | file]

List of source files. (since 0.41.0) the list is flattened.

install bool

When true, one or more files of this target are installed during the install step (see install_dir for details).

install_dir str | list[str | bool]

If only one install_dir is provided, all outputs are installed there. Since 0.40.0 Allows you to specify the installation directory for each corresponding output. For example:

custom_target('different-install-dirs',
  output : ['first.file', 'second.file'],
  install : true,
  install_dir : ['somedir', 'otherdir'])

This would install first.file to somedir and second.file to otherdir.

To only install some outputs, pass false for the outputs that you don't want installed. For example:

    custom_target('only-install-second',
      output : ['first.file', 'second.file'],
      install : true,
      install_dir : [false, 'otherdir'])

This would install second.file to otherdir and not install first.file.

install_mode list[str | int]

The file mode and optionally the owner/uid and group/gid. See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_tag list[str]

A list of strings, one per output, used by the meson install --tags command to install only a subset of the files.

By default all outputs have no install tag which means they are not being installed when --tags argument is specified. If only one tag is specified, it is assumed that all outputs have the same tag. false can be used for outputs that have no tag or are not installed.

(since 0.60.0)

output list[str]

List of output files.


debug()

Write the argument string to the meson build log.

Signature

(since 0.63.0)

# Write the argument string to the meson build log
void debug(
  str | int | bool | list[str | int | bool] | dict[str | int | bool] message,     # The message to print
  str | int | bool | list[str | int | bool] | dict[str | int | bool] msg...,      # Additional parameters will be separated by spaces
)

Arguments

The function debug() accepts the following positional arguments:

Name Type Description Tags
message str | int | bool | list[str | int | bool] | dict[str | int | bool]

The message to print

Additionally, the function accepts between 0 and infinity variadic arguments (msg...) of type str | int | bool | list[str | int | bool] | dict[str | int | bool].

Additional parameters will be separated by spaces


declare_dependency()

This function returns a dep object that behaves like the return value of dependency() but is internal to the current build. The main use case for this is in subprojects. This allows a subproject to easily specify how it should be used. This makes it interchangeable with the same dependency that is provided externally by the system.

Signature

# This function returns a dep object that
dep declare_dependency(
  compile_args        : list[str]                                                    # Compile arguments to use
  d_import_dirs       : list[inc | str]                                              # the directories to add to the string search path (i
  d_module_versions   : str | int | list[str | int]                                  # The [D version identifiers](https://dlang
  dependencies        : list[dep]                                                    # Other dependencies needed to use this dependency
  extra_files         : list[str | file]                                             # extra files to add to targets
  include_directories : list[inc | str]                                              # the directories to add to header search path,
  link_args           : list[str]                                                    # Link arguments to use
  link_whole          : list[lib]                                                    # Libraries to link fully, same as executable().
  link_with           : list[lib]                                                    # Libraries to link against
  objects             : list[extracted_obj]                                          # a list of object files, to be linked directly into the targets that use the
  sources             : list[str | file | custom_tgt | custom_idx | generated_list]  # sources to add to targets
  variables           : dict[str] | list[str]                                        # a dictionary of arbitrary strings,
  version             : str                                                          # the version of this dependency,
)

Arguments

The function declare_dependency() accepts the following keyword arguments:

Name Type Description Tags
compile_args list[str]

Compile arguments to use.

d_import_dirs list[inc | str]

the directories to add to the string search path (i.e. -J switch for DMD). Must be inc objects or plain strings.

(since 0.62.0)

d_module_versions str | int | list[str | int]

The D version identifiers to add during the compilation of D source files.

(since 0.62.0)

dependencies list[dep]

Other dependencies needed to use this dependency.

extra_files list[str | file]

extra files to add to targets. mostly used for IDE integration.

(since 1.2.0)

include_directories list[inc | str]

the directories to add to header search path, must be inc objects or (since 0.50.0) plain strings.

objects list[extracted_obj]

a list of object files, to be linked directly into the targets that use the dependency.

(since 1.1.0)

sources list[str | file | custom_tgt | custom_idx | generated_list]

sources to add to targets (or generated header files that should be built before sources including them are built)

variables dict[str] | list[str]

a dictionary of arbitrary strings, this is meant to be used in subprojects where special variables would be provided via cmake or pkg-config. since 0.56.0 it can also be a list of 'key=value' strings.

(since 0.54.0)

version str

the version of this dependency, such as 1.2.3. Defaults to the project version.


dependency()

Finds an external dependency (usually a library installed on your system) with the given name with pkg-config and with CMake if pkg-config fails. Additionally, frameworks (OSX only) and library-specific fallback detection logic are also supported.

Since 0.60.0 more than one name can be provided, they will be tried in order and the first name to be found will be used. The fallback subproject will be used only if none of the names are found on the system. Once one of the name has been found, all other names are added into the cache so subsequent calls for any of those name will return the same value. This is useful in case a dependency could have different names, such as png and libpng.

  • Since 0.64.0 a dependency fallback can be provided by WrapDB. Simply download the database locally using meson wrap update-db command and Meson will automatically fallback to subprojects provided by WrapDB if the dependency is not found on the system and the project does not ship their own .wrap file.

Dependencies can also be resolved in two other ways:

  • if the same name was used in a meson.override_dependency prior to the call to dependency, the overriding dependency will be returned unconditionally; that is, the overriding dependency will be used independent of whether an external dependency is installed in the system. Typically, meson.override_dependency will have been used by a subproject.

  • by a fallback subproject which, if needed, will be brought into the current build specification as if subproject() had been called. The subproject can be specified with the fallback argument. Alternatively, if the fallback argument is absent, since 0.55.0 Meson can automatically identify a subproject as a fallback if a wrap file provides the dependency, or if a subproject has the same name as the dependency. In the latter case, the subproject must use meson.override_dependency to specify the replacement, or Meson will report a hard error. See the Wrap documentation for more details. This automatic search can be controlled using the allow_fallback keyword argument.

If dependency_name is '', the dependency is always not found. So with required: false, this always returns a dependency object for which the found() method returns false, and which can be passed like any other dependency to the dependencies: keyword argument of a build_target. This can be used to implement a dependency which is sometimes not required e.g. in some branches of a conditional, or with a fallback: kwarg, can be used to declare an optional dependency that only looks in the specified subproject, and only if that's allowed by --wrap-mode.

The returned object dep also has additional methods.

Signature

# Finds an external dependency (usually a library installed on your
dep dependency(
  str names...,  # The names of the dependency to look up

  # Keyword arguments:
  allow_fallback    : bool                                          # Specifies whether Meson should automatically pick a fallback subproject
  default_options   : list[str] | dict[str | bool | int | list[str]]  # An array of default option values
  disabler          : bool                                          # Returns a disabler() object instead of a not-found dependency
  fallback          : list[str] | str                               # Manually specifies a subproject fallback
  include_type      : str                                           # An enum flag, marking how the dependency
  language          : str                                           # Defines what language-specific dependency to find
  method            : str                                           # Defines the way the dependency is detected, the default is
  native            : bool                                          # If set to `true`, causes Meson to find the dependency on
  not_found_message : str                                           # An optional string that will be printed as a message() if the dependency was not found.
  required          : bool | feature                                # When set to `false`, Meson will proceed with the build
  static            : bool                                          # Tells the dependency provider to try to get static
  version           : list[str] | str                               # Specifies the required version,
)
Note:

This function supports additional library-specific keyword arguments that may also be accepted (e.g. modules specifies submodules to use for dependencies such as Qt5 or Boost. components allows the user to manually add CMake COMPONENTS for the find_package lookup)

Arguments

The function accepts between 1 and infinity variadic arguments (names...) of type str.

The names of the dependency to look up. The dependencies are looked up in the order they are provided here. The first found dependency will then be used. The fallback subproject will be used only if none of the names are found on the system. Once one of the name has been found, all other names are added into the cache so subsequent calls for any of those name will return the same value. This is useful in case a dependency could have different names, such as png and libpng.

NOTE: Before 0.60.0 only a single dependency name was allowed.

(since 0.60.0)

The function dependency() accepts the following keyword arguments:

Name Type Description Tags
allow_fallback bool

Specifies whether Meson should automatically pick a fallback subproject in case the dependency is not found in the system. If true and the dependency is not found on the system, Meson will fallback to a subproject that provides this dependency. If false, Meson will not fallback even if a subproject provides this dependency. By default, Meson will do so if required is true or enabled; see the Wrap documentation for more details.

(since 0.56.0)

default_options list[str] | dict[str | bool | int | list[str]]

An array of default option values that override those set in the subproject's meson.options (like default_options in project(), they only have effect when Meson is run for the first time, and command line arguments override any default options in build files) (since 1.2.0): A dictionary may now be passed.

(since 0.38.0)

disabler bool

Returns a disabler() object instead of a not-found dependency if this kwarg is set to true and the dependency couldn't be found.

(since 0.49.0)

default = false

fallback list[str] | str

Manually specifies a subproject fallback to use in case the dependency is not found in the system. This is useful if the automatic search is not applicable or if you want to support versions of Meson older than 0.55.0. If the value is an array ['subproj_name', 'subproj_dep'], the first value is the name of the subproject and the second is the variable name in that subproject that contains a dependency object such as the return value of declare_dependency() or dependency(), etc. Note that this means the fallback dependency may be a not-found dependency, in which case the value of the required: kwarg will be obeyed. Since 0.54.0 the value can be a single string, the subproject name; in this case the subproject must use meson.override_dependency('dependency_name', subproj_dep) to specify the dependency object used in the superproject. If the value is an empty list, it has the same effect as allow_fallback: false.

include_type str

An enum flag, marking how the dependency flags should be converted. Supported values are 'preserve', 'system' and 'non-system'. System dependencies may be handled differently on some platforms, for instance, using -isystem instead of -I, where possible. If include_type is set to 'preserve', no additional conversion will be performed.

(since 0.52.0)

default = 'preserve'

language str

Defines what language-specific dependency to find if it's available for multiple languages.

(since 0.42.0)

method str

Defines the way the dependency is detected, the default is auto but can be overridden to be e.g. qmake for Qt development, and different dependencies support different values for this (though auto will work on all of them)

(since 0.40.0)

default = 'auto'

native bool

If set to true, causes Meson to find the dependency on the build machine system rather than the host system (i.e. where the cross compiled binary will run on), usually only needed if you build a tool to be used during compilation.

default = false

not_found_message str

An optional string that will be printed as a message() if the dependency was not found.

(since 0.50.0)

required bool | feature

When set to false, Meson will proceed with the build even if the dependency is not found.

When set to a feature option, the feature will control if it is searched and whether to fail if not found.

(since 0.47.0) The value of a feature option can also be passed.

default = true

static bool

Tells the dependency provider to try to get static libraries instead of dynamic ones (note that this is not supported by all dependency backends)

Since 0.60.0 it also sets default_library option accordingly on the fallback subproject if it was not set explicitly in default_options keyword argument.

default = false

version list[str] | str

Specifies the required version, a string containing a comparison operator followed by the version string, examples include >1.0.0, <=2.3.5 or 3.1.4 for exact matching. You can also specify multiple restrictions by passing a list to this keyword argument, such as: ['>=3.14.0', '<=4.1.0']. These requirements are never met if the version is unknown.

(since 0.37.0)


disabler()

Returns a disabler object.

Signature

(since 0.44.0)

disabler disabler()


environment()

Returns an empty env object.

Signature

(since 0.35.0)

# Returns an empty env object.
env environment(
  str | list[str] | dict[str] | dict[list[str]] [env],   # If provided, each key/value pair is added into the env object

  # Keyword arguments:
  method    : str  # Must be one of 'set', 'prepend', or 'append'
  separator : str  # The separator to use for the initial values defined in
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function environment() accepts the following positional arguments:

Name Type Description Tags
env str | list[str] | dict[str] | dict[list[str]]

If provided, each key/value pair is added into the env object as if env.set() method was called for each of them. Since 0.62.0 list of strings is allowed in dictionary values. In that case values are joined using the separator.

(since 0.52.0)

[optional]

Finally, environment() accepts the following keyword arguments:

Name Type Description Tags
method str

Must be one of 'set', 'prepend', or 'append' (defaults to 'set'). Controls if initial values defined in the first positional argument are prepended, appended or replace the current value of the environment variable.

(since 0.62.0)

separator str

The separator to use for the initial values defined in the first positional argument. If not explicitly specified, the default path separator for the host operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems.

(since 0.62.0)


error()

Print the argument string and halts the build process.

Signature

# Print the argument string and halts the build process
void error(
  str message,     # The message to print
  str msg...,      # Additional parameters will be separated by spaces
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function error() accepts the following positional arguments:

Name Type Description Tags
message str

The message to print

Additionally, the function accepts between 0 and infinity variadic arguments (msg...) of type str.

Additional parameters will be separated by spaces

(since 0.58.0)


executable()

Creates a new executable. The first argument specifies its name and the remaining positional arguments define the input files to use.

The lists for the kwargs (such as sources, objects, and dependencies) are always flattened, which means you can freely nest and add lists while creating the final list.

The returned object also has methods that are documented in exe.

Since 1.3.0 executable names can be the same across multiple targets as long as they each have a different name_suffix.

Signature

# Creates a new executable
exe executable(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  dependencies                 : list[dep]                                                               # one or more dependency objects
  export_dynamic               : bool                                                                    # when set to true causes the target's symbols to be
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implib                       : bool | str                                                              # When set to true, an import library is generated for the
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  pie                          : bool                                                                    # Build a position-independent executable
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)
Warning:

The link_language kwarg was broken until 0.55.0

Arguments

The function executable() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, executable() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

export_dynamic bool

when set to true causes the target's symbols to be dynamically exported, allowing modules built using the shared_module() function to refer to functions, variables and other symbols defined in the executable itself. Implies the implib argument.

(since 0.45.0)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implib bool | str

When set to true, an import library is generated for the executable (the name of the import library is based on exe_name). Alternatively, when set to a string, that gives the base name for the import library. The import library is used when the returned build target object appears in link_with: elsewhere. Only has any effect on platforms where that is meaningful (e.g. Windows). Implies the export_dynamic argument.

(since 0.42.0)

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

pie bool

Build a position-independent executable.

(since 0.49.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

This can be used to expose which functions a shared_module loaded by an executable will be allowed to use.

(since 1.3.0)

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


files()

This command takes the strings given to it in arguments and returns corresponding File objects that you can use as sources for build targets. The difference is that file objects remember the subdirectory they were defined in and can be used anywhere in the source tree.

Signature

# This command takes the strings given to it in arguments and returns
list[file] files(
  str file...,  # Path to the file
)

Example

As an example suppose you have source file foo.cpp in subdirectory bar1 and you would like to use it in a build target that is defined in bar2. To make this happen you first create the object in bar1 like this:

    foofile = files('foo.cpp')

Then you can use it in bar2 like this:

    executable('myprog', 'myprog.cpp', foofile, ...)

Meson will then do the right thing.

Arguments

The function accepts between 0 and infinity variadic arguments (file...) of type str.

Path to the file.


find_program()

program_name here is a string that can be an executable or script to be searched for in PATH or other places inside the project. The search order is:

  1. Program overrides set via meson.override_find_program()
  2. [provide] sections in subproject wrap files, if wrap_mode is set to forcefallback
  3. [binaries] section in your machine files
  4. Directories provided using the dirs: kwarg (see below)
  5. Project's source tree relative to the current subdir
    • If you use the return value of configure_file(), the current subdir inside the build tree is used instead
  6. PATH environment variable
  7. [provide] sections in subproject wrap files, if wrap_mode is set to anything other than nofallback

Meson will also autodetect scripts with a shebang line and run them with the executable/interpreter specified in it both on Windows (because the command invocator will reject the command otherwise) and Unixes (if the script file does not have the executable bit set). Hence, you must not manually add the interpreter while using this script as part of a list of commands. Since 0.50.0 if the "python3" program is requested and it is not found in the system, Meson will return its current interpreter.

If you need to check for a program in a non-standard location, you can just pass an absolute path to find_program, e.g.

setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)

It is also possible to pass an array to find_program in case you need to construct the set of paths to search on the fly:

setcap = find_program(['setcap', '/usr/sbin/setcap', '/sbin/setcap'], required : false)

Since 1.2.0 find_program('meson') is automatically overridden to the Meson command used to execute the build script.

The returned external_program object also has documented methods.

Signature

# `program_name` here is a string that can be an executable or script
external_program find_program(
  str | file program_name,     # The name of the program to search, or a file object to be used
  str | file fallback...,      # These parameters are used as fallback names to search for

  # Keyword arguments:
  default_options : list[str] | dict[str | bool | int | list[str]]  # An array of default option values
  dirs            : list[str]                                     # extra list of absolute paths where to look for program names
  disabler        : bool                                          # If `true` and the program couldn't be found, return a disabler object
  native          : bool                                          # Defines how this executable should be searched
  required        : bool | feature                                # When `true`, Meson will abort if no program can be found
  version         : str | list[str]                               # Specifies the required version, see
)

Arguments

The function find_program() accepts the following positional arguments:

Name Type Description Tags
program_name str | file

The name of the program to search, or a file object to be used without searching.

Additionally, the function accepts between 0 and infinity variadic arguments (fallback...) of type str | file.

These parameters are used as fallback names to search for. This is meant to be used for cases where the program may have many alternative names, such as foo and foo.py. The function will check for the arguments one by one and the first one that is found is returned.

(since 0.37.0)

Finally, find_program() accepts the following keyword arguments:

Name Type Description Tags
default_options list[str] | dict[str | bool | int | list[str]]

An array of default option values that override those set in the subproject's meson.options (like default_options in project(), they only have effect when Meson is run for the first time, and command line arguments override any default options in build files)

(since 1.3.0)

dirs list[str]

extra list of absolute paths where to look for program names.

(since 0.53.0)

disabler bool

If true and the program couldn't be found, return a disabler object instead of a not-found object.

(since 0.49.0)

default = false

native bool

Defines how this executable should be searched. By default it is set to false, which causes Meson to first look for the executable in the cross file (when cross building) and if it is not defined there, then from the system. If set to true, the cross file is ignored and the program is only searched from the system.

(since 0.43.0)

default = false

required bool | feature

When true, Meson will abort if no program can be found. If required is set to false, Meson continue even if none of the programs can be found. You can then use the .found() method on the returned external_program to check whether it was found or not. (since 0.47.0) The value of a feature option can also be passed to the required keyword argument.

default = true

version str | list[str]

Specifies the required version, see dependency() for argument format. The version of the program is determined by running program_name --version command. If stdout is empty it fallbacks to stderr. If the output contains more text than simply a version number, only the first occurrence of numbers separated by dots is kept. If the output is more complicated than that, the version checking will have to be done manually using run_command().

(since 0.52.0)


generator()

See also: custom_target()

This function creates a generator object that can be used to run custom compilation commands. The only positional argument is the executable to use. It can either be a self-built executable or one returned by find_program.

The template strings passed to all the keyword arguments accept the following special substitutions:

  • @PLAINNAME@: the complete input file name, e.g: foo.c becomes foo.c (unchanged)
  • @BASENAME@: the base of the input filename, e.g.: foo.c.y becomes foo.c (extension is removed)

Each string passed to the output keyword argument must be constructed using one or both of these two substitutions.

In addition to the above substitutions, the arguments keyword argument also accepts the following:

  • @OUTPUT@: the full path to the output file
  • @INPUT@: the full path to the input file
  • @DEPFILE@: the full path to the depfile
  • @SOURCE_DIR@: the full path to the root of the source tree
  • @CURRENT_SOURCE_DIR@: this is the directory where the currently processed meson.build is located in
  • @BUILD_DIR@: the full path to the root of the build dir where the output will be placed

NOTE: Generators should only be used for outputs that will only be used as inputs for a build_target() or a custom_target(). When you use the processed output of a generator in multiple targets, the generator will be run multiple times to create outputs for each target. Each output will be created in a target-private directory @BUILD_DIR@.

If you want to generate files for general purposes such as for generating headers to be used by several sources, or data that will be installed, and so on, use a custom_target() instead.

Signature

# See also: custom_target()
generator generator(
  exe | external_program exe,     # Executable for the command to run

  # Keyword arguments:
  arguments : list[str]                     # A list of template strings that will be the command line arguments passed to the executable
  capture   : bool                          # When this argument is set to true, Meson captures `stdout`
  depends   : list[build_tgt | custom_tgt]  # An array of build targets that must be built before
  depfile   : str                           # A template string pointing to a dependency file that a
  output    : list[str]                     # Template string (or list of template strings) defining
)

Arguments

The function generator() accepts the following positional arguments:

Name Type Description Tags
exe exe | external_program

Executable for the command to run

Finally, generator() accepts the following keyword arguments:

Name Type Description Tags
arguments list[str]

A list of template strings that will be the command line arguments passed to the executable.

capture bool

When this argument is set to true, Meson captures stdout of the executable and writes it to the target file specified as output.

(since 0.43.0)

default = false

depends list[build_tgt | custom_tgt]

An array of build targets that must be built before this generator can be run. This is used if you have a generator that calls a second executable that is built in this project.

(since 0.51.0)

depfile str

A template string pointing to a dependency file that a generator can write listing all the additional files this target depends on, for example a C compiler would list all the header files it included, and a change in any one of these files triggers a recompilation,

output list[str]

Template string (or list of template strings) defining how an output file name is (or multiple output names are) generated from a single source file name.


get_option()

Obtains the value of the project build option specified in the positional argument.

Note that the value returned for built-in options that end in dir such as bindir and libdir is usually a path relative to (and inside) the prefix but you should not rely on that, as it can also be an absolute path in some cases. install_dir arguments handle that as expected but if you need an absolute path, e.g. to use in a define etc., you should use the path concatenation operator like this: get_option('prefix') / get_option('localstatedir'). Never manually join paths as if they were strings.

For options of type feature a feature option object is returned instead of a string. See feature options documentation for more details.

Signature

# Obtains the value of the [project build option](Build-options
str | int | bool | feature | list[str | int | bool] get_option(
  str option_name,     # Name of the option to query
)

Arguments

The function get_option() accepts the following positional arguments:

Name Type Description Tags
option_name str

Name of the option to query


get_variable()

This function can be used to dynamically obtain a variable. res = get_variable(varname, fallback) takes the value of varname (which must be a string) and stores the variable of that name into res. If the variable does not exist, the variable fallback is stored to resinstead. If a fallback is not specified, then attempting to read a non-existing variable will cause a fatal error.

Signature

# This function can be used to dynamically obtain a variable
any get_variable(
  str variable_name,     # Name of the variable to get
  any [default],         # Fallback value to return when the variable does not exist
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function get_variable() accepts the following positional arguments:

Name Type Description Tags
variable_name str

Name of the variable to get

default any

Fallback value to return when the variable does not exist

[optional]


import()

Imports the given extension module. Returns an object that can be used to call the methods of the module. Here's an example for a hypothetical testmod module.

Signature

# Imports the given extension module
module import(
  str module_name,     # Name of the module to import

  # Keyword arguments:
  disabler : bool            # Returns a disabler object when not found.
  required : bool | feature  # When set to `false`, Meson will proceed with the build even if the module is not found
)

Example

tmod = import('testmod')
tmod.do_something()

Arguments

The function import() accepts the following positional arguments:

Name Type Description Tags
module_name str

Name of the module to import.

Finally, import() accepts the following keyword arguments:

Name Type Description Tags
disabler bool

Returns a disabler object when not found.

(since 0.59.0)

required bool | feature

When set to false, Meson will proceed with the build even if the module is not found. When set to a feature option, the feature will control if it is searched and whether to fail if not found.

(since 0.59.0)

default = true


include_directories()

Returns an opaque object which contains the directories (relative to the current directory) given in the positional arguments. The result can then be passed to the include_directories: keyword argument when building executables or libraries. You can use the returned object in any subdirectory you want, Meson will make the paths work automatically.

Note that this function call itself does not add the directories into the search path, since there is no global search path. For something like that, see add_project_arguments().

See also implicit_include_directories parameter of executable(), which adds current source and build directories to include path.

Each directory given is converted to two include paths: one that is relative to the source root and one relative to the build root.

Signature

# Returns an opaque object which contains the directories (relative to
inc include_directories(
  str includes...,  # Include paths to add

  # Keyword arguments:
  is_system : bool  # If set to `true`, flags the specified directories as system directories
)

Example

For example, with the following source tree layout in /home/user/project.git:

meson.build:

project(...)

subdir('include')
subdir('src')

...

include/meson.build:

inc = include_directories('.')

...

src/meson.build:

sources = [...]

executable('some-tool', sources,
  include_directories : inc,
  ...)

...

If the build tree is /tmp/build-tree, the following include paths will be added to the executable() call: -I/tmp/build-tree/include -I/home/user/project.git/include.

Arguments

The function accepts between 0 and infinity variadic arguments (includes...) of type str.

Include paths to add.

The function include_directories() accepts the following keyword arguments:

Name Type Description Tags
is_system bool

If set to true, flags the specified directories as system directories. This means that they will be used with the -isystem compiler argument rather than -I on compilers that support this flag (in practice everything except Visual Studio).

default = false


install_data()

Installs files from the source tree that are listed as positional arguments.

See Installing for more examples.

Signature

# Installs files from the source tree that are listed as positional arguments
void install_data(
  file | str file...,  # Files to install

  # Keyword arguments:
  follow_symlinks : bool              # If true, dereferences links and copies their target instead
  install_dir     : str               # The absolute or relative path to the installation directory
  install_mode    : list[str | int]   # specify the file mode in symbolic format and
  install_tag     : str               # A string used by the `meson install --tags` command
  preserve_path   : bool              # Disable stripping child-directories from data files when installing
  rename          : list[str]         # If specified renames each source file into corresponding file from `rename` list
  sources         : list[file | str]  # Additional files to install
)
Warning:

the install_mode kwarg ignored integer values between 0.59.0 -- 1.1.0.

Warning:

an omitted install_dir kwarg did not work correctly inside of a subproject until 1.3.0.

Warning:

an omitted install_dir kwarg did not work correctly when combined with the preserve_path kwarg untill 1.3.0.

Arguments

The function accepts between 0 and infinity variadic arguments (file...) of type file | str.

Files to install.

The function install_data() accepts the following keyword arguments:

Name Type Description Tags
install_dir str

The absolute or relative path to the installation directory. If this is a relative path, it is assumed to be relative to the prefix.

If omitted, the directory defaults to {datadir}/{projectname} (since 0.45.0).

install_mode list[str | int]

specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files. For example:

install_mode: 'rw-r--r--' for just the file mode

install_mode: ['rw-r--r--', 'nobody', 'nogroup'] for the file mode and the user/group

install_mode: ['rw-r-----', 0, 0] for the file mode and uid/gid

To leave any of these three as the default, specify false.

(since 0.38.0)

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default these files have no install tag which means they are not being installed when --tags argument is specified.

(since 0.60.0)

preserve_path bool

Disable stripping child-directories from data files when installing.

This is equivalent to GNU Automake's nobase option.

(since 0.64.0)

default = false

rename list[str]

If specified renames each source file into corresponding file from rename list. Nested paths are allowed and they are joined with install_dir. Length of rename list must be equal to the number of sources.

(since 0.46.0)

sources list[file | str]

Additional files to install.


install_emptydir()

Installs a new directory entry to the location specified by the positional argument. If the directory exists and is not empty, the contents are left in place.

Signature

(since 0.60.0)

# Installs a new directory entry to the location specified by the positional
void install_emptydir(
  str dirpath...,  # Directory to create during installation

  # Keyword arguments:
  install_mode : list[str | int]  # Specify the file mode in symbolic format and optionally the owner/uid and
  install_tag  : str              # A string used by the `meson install --tags` command to install only a
)
Warning:

the install_mode kwarg ignored integer values before 1.1.0.

Arguments

The function accepts between 0 and infinity variadic arguments (dirpath...) of type str.

Directory to create during installation.

The function install_emptydir() accepts the following keyword arguments:

Name Type Description Tags
install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the created directory.

See the install_mode kwarg of install_data() for more information.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default this directory has no install tag which means it is not installed when the --tags argument is specified.


install_headers()

Installs the specified header files from the source tree into the system header directory (usually /{prefix}/include) during the install step. This directory can be overridden by specifying it with the install_dir keyword argument. If you just want to install into a subdirectory of the system header directory, then use the subdir argument. As an example if this has the value myproj then the headers would be installed to /{prefix}/include/myproj.

Signature

# Installs the specified header files from the source tree into the
void install_headers(
  file | str file...,  # Header files to install

  # Keyword arguments:
  follow_symlinks : bool             # If true, dereferences links and copies their target instead
  install_dir     : str              # Where to install to
  install_mode    : list[str | int]  # Specify the file mode in symbolic format
  preserve_path   : bool             # Disable stripping child-directories from header files when installing
  subdir          : str              # Install to the `subdir` subdirectory of the default includedir
)

Example

For example, this will install common.h and kola.h into /{prefix}/include:

install_headers('common.h', 'proj/kola.h')

This will install common.h and kola.h into /{prefix}/include/myproj:

install_headers('common.h', 'proj/kola.h', subdir : 'myproj')

This will install common.h and kola.h into /{prefix}/cust/myproj:

install_headers('common.h', 'proj/kola.h', install_dir : 'cust', subdir : 'myproj')

This will install common.h into /{prefix}/include and kola.h into /{prefix}/include/proj/:

install_headers('common.h, 'proj/kola.h', preserve_path : true)
Warning:

the install_mode kwarg ignored integer values between 0.59.0 -- 1.1.0.

Arguments

The function accepts between 0 and infinity variadic arguments (file...) of type file | str.

Header files to install.

The function install_headers() accepts the following keyword arguments:

Name Type Description Tags
install_dir str

Where to install to.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

preserve_path bool

Disable stripping child-directories from header files when installing.

This is equivalent to GNU Automake's nobase option.

(since 0.63.0)

default = false

subdir str

Install to the subdir subdirectory of the default includedir.

Incompatible with the install_dir kwarg.


install_man()

Installs the specified man files from the source tree into system's man directory during the install step. This directory can be overridden by specifying it with the install_dir keyword argument.

(since 0.49.0) manpages are no longer compressed implicitly.

Signature

# Installs the specified man files from the source tree into system's man directory
void install_man(
  file | str file...,  # Man pages to install

  # Keyword arguments:
  install_dir  : str              # Where to install to
  install_mode : list[str | int]  # Specify the file mode in symbolic format
  locale       : str              # Can be used to specify the locale
)
Warning:

the install_mode kwarg ignored integer values between 0.59.0 -- 1.1.0.

Arguments

The function accepts between 0 and infinity variadic arguments (file...) of type file | str.

Man pages to install.

The function install_man() accepts the following keyword arguments:

Name Type Description Tags
install_dir str

Where to install to.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

locale str

Can be used to specify the locale into which the man page will be installed within the manual page directory tree. An example manual might be foo.fr.1 with a locale of fr, such that {mandir}/{locale}/man{num}/foo.1 becomes the installed file.

(since 0.58.0)


install_subdir()

Installs the entire given subdirectory and its contents from the source tree to the location specified by the keyword argument install_dir.

(since 0.45.0, deprecated since 0.60.0) If the subdirectory does not exist in the source tree, an empty directory is created in the specified location. A newly created subdirectory may only be created in the keyword argument install_dir. There are a number of flaws with this method, and it was never intentionally designed to work this way, please use install_emptydir() instead.

Signature

# Installs the entire given subdirectory and its contents from the
void install_subdir(
  str subdir_name,     # The sub-directory to install

  # Keyword arguments:
  exclude_directories : list[str]        # A list of directory names that should not be installed
  exclude_files       : list[str]        # A list of file names that should not be installed
  follow_symlinks     : bool             # If true, dereferences links and copies their target instead
  install_dir         : str              # Where to install to
  install_mode        : list[str | int]  # Specify the file mode in symbolic format
  install_tag         : str              # A string used by the `meson install --tags` command
  strip_directory     : bool             # Install directory contents
)

Example

For a given directory foo:

foo/
  bar/
    file1
  file2

install_subdir('foo', install_dir : 'share', strip_directory : false) creates

share/
  foo/
    bar/
      file1
    file2

install_subdir('foo', install_dir : 'share', strip_directory : true) creates

share/
  bar/
    file1
  file2

install_subdir('foo/bar', install_dir : 'share', strip_directory : false) creates

share/
  bar/
    file1

install_subdir('foo/bar', install_dir : 'share', strip_directory : true) creates

share/
  file1

install_subdir('new_directory', install_dir : 'share') creates

share/
  new_directory/
Warning:

the install_mode kwarg ignored integer values between 0.59.0 -- 1.1.0.

Arguments

The function install_subdir() accepts the following positional arguments:

Name Type Description Tags
subdir_name str

The sub-directory to install

Finally, install_subdir() accepts the following keyword arguments:

Name Type Description Tags
exclude_directories list[str]

A list of directory names that should not be installed. Names are interpreted as paths relative to the subdir_name location.

(since 0.47.0)

exclude_files list[str]

A list of file names that should not be installed. Names are interpreted as paths relative to the subdir_name location.

install_dir str

Where to install to.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default these files have no install tag which means they are not being installed when --tags argument is specified.

(since 0.60.0)

strip_directory bool

Install directory contents. If strip_directory=true only the last component of the source path is used.

(since 0.45.0)

default = false


Installs a symbolic link to pointing_to target under install_dir.

Signature

(since 0.61.0)

# Installs a symbolic link to `pointing_to` target under install_dir
void install_symlink(
  str link_name,     # Name of the created link under `install_dir`

  # Keyword arguments:
  install_dir : str  [required]  # The absolute or relative path to the installation directory for the links
  install_tag : str              # A string used by the `meson install --tags` command
  pointing_to : str  [required]  # Target to point the link to
)

Arguments

The function install_symlink() accepts the following positional arguments:

Name Type Description Tags

Finally, install_symlink() accepts the following keyword arguments:

Name Type Description Tags


is_disabler()

Returns true if a variable is a disabler and false otherwise.

Signature

(since 0.52.0)

# Returns true if a variable is a disabler and false otherwise
bool is_disabler(
  any var,     # The variable to test
)

Arguments

The function is_disabler() accepts the following positional arguments:

Name Type Description Tags
var any

The variable to test


is_variable()

Returns true if a variable of the given name exists and false otherwise.

Signature

(since 0.52.0)

# Returns true if a variable of the given name exists and false otherwise
bool is_variable(
  str var,     # The variable to test
)

Arguments

The function is_variable() accepts the following positional arguments:

Name Type Description Tags
var str

The variable to test


jar()

Build a jar from the specified Java source files. Keyword arguments are the same as executable()'s, with the addition of main_class which specifies the main class to execute when running the jar with java -jar file.jar.

Signature

# Build a jar from the specified Java source files
jar jar(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  java_resources               : structured_src                                                          # Resources to be added to the jar
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  main_class                   : str                                                                     # Main class for running the built jar
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)

Arguments

The function jar() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, jar() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

java_resources structured_src

Resources to be added to the jar

(since 0.62.0)

main_class str

Main class for running the built jar

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


join_paths()

Joins the given strings into a file system path segment. For example join_paths('foo', 'bar') results in foo/bar. If any one of the individual segments is an absolute path, all segments before it are dropped. That means that join_paths('foo', '/bar') returns /bar.

(since 0.49.0) Using the / operator on strings is equivalent to calling join_paths().

# res1 and res2 will have identical values
res1 = join_paths(foo, bar)
res2 = foo / bar

Signature

(since 0.36.0)

# Joins the given strings into a file system path segment
str join_paths(
  str part...,  # The path parts to join
)
Warning:

Don't use join_paths() for sources in library() and executable(). You should use files() instead.

Arguments

The function accepts between 1 and infinity variadic arguments (part...) of type str.

The path parts to join.


library()

Builds a library that is either static, shared or both depending on the value of default_library user option. You should use this instead of shared_library(), static_library() or both_libraries() most of the time. This allows you to toggle your entire project (including subprojects) from shared to static with only one option. This option applies to libraries being built internal to the entire project. For external dependencies, the default library type preferred is shared. This can be adapted on a per library basis using the dependency() static keyword.

The keyword arguments for this are the same as for build_target()

Signature

# Builds a library that is either static, shared or both depending on
lib library(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  <lang>_shared_args           : list[str]                                                               # Arguments that are only passed to a shared library
  <lang>_static_args           : list[str]                                                               # Arguments that are only passed to a static library
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  darwin_versions              : str | int | list[str]                                                   # Defines the `compatibility version` and `current version` for the dylib on macOS
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  pic                          : bool                                                                    # Builds the library as positional independent code
  prelink                      : bool                                                                    # If `true` the object files in the target will be prelinked,
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  soversion                    : str | int                                                               # A string or integer specifying the soversion of this shared library,
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  vala_shared_args             : list[str | file]                                                        # Arguments that are only passed to a shared library
  vala_static_args             : list[str | file]                                                        # Arguments that are only passed to a static library
  version                      : str                                                                     # A string specifying the version of this shared library,
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)
Warning:

using _shared_args and/or _static_args may lead to much higher compilation times with both_library, as object files cannot be shared between the static and shared targets. It is guaranteed to not duplicate the build if these arguments are empty arrays

Arguments

The function library() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, library() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

<lang>_shared_args list[str]

Arguments that are only passed to a shared library

(since 1.3.0)

<lang>_static_args list[str]

Arguments that are only passed to a static library

(since 1.3.0)

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

darwin_versions str | int | list[str]

Defines the compatibility version and current version for the dylib on macOS. If a list is specified, it must be either zero, one, or two elements. If only one element is specified or if it's not a list, the specified value will be used for setting both compatibility version and current version. If unspecified, the soversion will be used as per the aforementioned rules.

(since 0.48.0)

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

pic bool

Builds the library as positional independent code (so it can be linked into a shared library). This option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be disabled on OS X.

(since 0.36.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "rlib" or "dylib" crate depending on the library type being build.

  • 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

soversion str | int

A string or integer specifying the soversion of this shared library, such as 0. On Linux and Windows this is used to set the soversion (or equivalent) in the filename. For example, if soversion is 4, a Windows DLL will be called foo-4.dll and one of the aliases of the Linux shared library would be libfoo.so.4. If this is not specified, the first part of version is used instead (see below). For example, if version is 3.6.0 and soversion is not defined, it is set to 3.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

vala_shared_args list[str | file]

Arguments that are only passed to a shared library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

vala_static_args list[str | file]

Arguments that are only passed to a static library Like vala_args, files() is allowed in addition to string

(since 1.3.0)

version str

A string specifying the version of this shared library, such as 1.1.0. On Linux and OS X, this is used to set the shared library version in the filename, such as libfoo.so.1.1.0 and libfoo.1.1.0.dylib. If this is not specified, soversion is used instead (see above).

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

(Since 1.3.0) custom_idx are supported

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


message()

This function prints its argument to stdout.

Signature

# This function prints its argument to stdout
void message(
  str | int | bool | list[str | int | bool] | dict[str | int | bool] text,          # The message to print
  str | int | bool | list[str | int | bool] | dict[str | int | bool] more_text...,  # Additional text that will be printed separated by spaces
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function message() accepts the following positional arguments:

Name Type Description Tags
text str | int | bool | list[str | int | bool] | dict[str | int | bool]

The message to print.

Additionally, the function accepts between 0 and infinity variadic arguments (more_text...) of type str | int | bool | list[str | int | bool] | dict[str | int | bool].

Additional text that will be printed separated by spaces.

(since 0.54.0)


project()

The first function called in each project, to initialize Meson.

The first argument to this function must be a string defining the name of this project.

The project name can be any string you want, it's not used for anything except descriptive purposes. However since it is written to e.g. the dependency manifest is usually makes sense to have it be the same as the project tarball or pkg-config name. So for example you would probably want to use the name libfoobar instead of The Foobar Library.

It may be followed by the list of programming languages that the project uses.

(since 0.40.0) The list of languages is optional.

These languages may be used both for native: false (the default) (host machine) targets and for native: true (build machine) targets. (since 0.56.0) The build machine compilers for the specified languages are not required.

Supported values for languages are c, cpp (for C++), cuda, cython, d, objc, objcpp, fortran, java, cs (for C#), vala and rust.

Signature

# The first function called in each project, to initialize Meson
void project(
  str project_name,     # The name of the project
  str language...,      # The languages that Meson should initialize

  # Keyword arguments:
  default_options : list[str] | dict[str | bool | int | list[str]]  # Accepts strings in the form `key=value`
  license         : str | list[str]                               # Takes a string or array of strings describing the license(s) the code is under
  license_files   : str | list[str]                               # Takes a string or array of strings with the paths to the license file(s)
  meson_version   : str                                           # Takes a string describing which Meson version the project requires
  subproject_dir  : str                                           # Specifies the top level directory name that holds Meson subprojects
  version         : str | file                                    # A free form string describing the version of this project
)

Arguments

The function project() accepts the following positional arguments:

Name Type Description Tags
project_name str

The name of the project.

Additionally, the function accepts between 0 and infinity variadic arguments (language...) of type str.

The languages that Meson should initialize.

Finally, project() accepts the following keyword arguments:

Name Type Description Tags
default_options list[str] | dict[str | bool | int | list[str]]

Accepts strings in the form key=value which have the same format as options to meson configure. For example to set the default project type you would set this: default_options : ['buildtype=debugoptimized']. Note that these settings are only used when running Meson for the first time. Global options such as buildtype can only be specified in the master project, settings in subprojects are ignored. Project specific options are used normally even in subprojects.

Note that some options can override the default behavior; for example, using c_args here means that the CFLAGS environment variable is not used. Consider using [add_project_arguments()] instead.

(since 1.2.0): A dictionary may now be passed.

license str | list[str]

Takes a string or array of strings describing the license(s) the code is under.

This should be an SPDX license expression, using the standardized license identifier from the SPDX license list. Usually this would be something like license : 'GPL-2.0-or-later'. If there are multiple licenses you can use the AND and OR operators to join them: license : 'Apache-2.0 OR GPL-2.0'.

For backwards compatibility reasons you can also pass an array of licenses here. This is not recommended, as it is ambiguous: license : ['Apache-2.0', 'GPL-2.0-only'] instead use an SPDX expression: license : 'Apache-2.0 OR GPL-2.0-only', which makes it clear that the license mean OR, not AND.

Note that the text is informal and is only written to the dependency manifest. Meson does not do any license validation, you are responsible for verifying that you abide by all licensing terms. You can access the value in your Meson build files with meson.project_license().

license_files str | list[str]

Takes a string or array of strings with the paths to the license file(s) the code is under.

This enhances the value of the license kwarg by allowing to specify both the short license name and the full license text. Usually this would be something like license_files: ['COPYING'].

Note that the files are informal and are only installed with the dependency manifest. Meson does not do any license validation, you are responsible for verifying that you abide by all licensing terms. You can access the value in your Meson build files with meson.project_license_files().

(since 1.1.0)

meson_version str

Takes a string describing which Meson version the project requires. Usually something like >=0.28.0.

subproject_dir str

Specifies the top level directory name that holds Meson subprojects. This is only meant as a compatibility option for existing code bases that house their embedded source code in a custom directory. All new projects should not set this but instead use the default value. It should be noted that this keyword argument is ignored inside subprojects. There can be only one subproject dir and it is set in the top level Meson file.

default = 'subprojects'

version str | file

A free form string describing the version of this project. You can access the value in your Meson build files with meson.project_version(). (Since 0.57.0) this can also be a file object pointing to a file that contains exactly one line of text.


range()

Return an opaque object that can be only be used in foreach statements.

range range(int stop)
range range(int start, int stop[, int step])
  • start must be integer greater or equal to 0. Defaults to 0.
  • stop must be integer greater or equal to start.
  • step must be integer greater or equal to 1. Defaults to 1.

It cause the foreach loop to be called with the value from start included to stop excluded with an increment of step after each loop.

Signature

(since 0.58.0)

# Return an opaque object that can be only be used in `foreach` statements
range range(
  int [start],   # The start of the range
  int [stop],    # The end of the range
  int [step],    # The loop increment
)

Example

# Loop 15 times with i from 0 to 14 included.
foreach i : range(15)
  ...
endforeach

The range object can also be assigned to a variable and indexed.

r = range(5, 10, 2)
assert(r[2] == 9)

Arguments

The function range() accepts the following positional arguments:

Name Type Description Tags
start int

The start of the range

[optional]

default = 0

stop int

The end of the range

[optional]

step int

The loop increment

[optional]

default = 1


run_command()

Runs the command specified in positional arguments. command can be a string, or the output of find_program(), files() or configure_file(), or a compiler object.

Returns a runresult object containing the result of the invocation. The command is run from an unspecified directory, and Meson will set three environment variables MESON_SOURCE_ROOT, MESON_BUILD_ROOT and MESON_SUBDIR that specify the source directory, build directory and subdirectory the target was defined in, respectively.

See also External commands.

Signature

# Runs the command specified in positional arguments
runresult run_command(
  str | file | external_program command...,  # The command to execute during the setup process

  # Keyword arguments:
  capture : bool                         # If `true`, any output generated on stdout will be captured and returned by
  check   : bool                         # If `true`, the exit status code of the command will be checked,
  env     : env | list[str] | dict[str]  # environment variables to set,
)

Arguments

The function accepts between 0 and infinity variadic arguments (command...) of type str | file | external_program.

The command to execute during the setup process.

The function run_command() accepts the following keyword arguments:

Name Type Description Tags
capture bool

If true, any output generated on stdout will be captured and returned by the .stdout() method. If it is false, then .stdout() will return an empty string.

(since 0.47.0)

default = true

check bool

If true, the exit status code of the command will be checked, and the configuration will fail if it is non-zero. Note that the default value will be true in future releases.

(since 0.47.0)

default = false

env env | list[str] | dict[str]

environment variables to set, such as ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling. (Since 0.52.0) A dictionary is also accepted.

(since 0.50.0)


run_target()

This function creates a new top-level target that runs a specified command with the specified arguments. Like all top-level targets, this integrates with the selected backend. For instance, you can run it as meson compile target_name. Note that a run target produces no output as far as Meson is concerned. It is only meant for tasks such as running a code formatter or flashing an external device's firmware with a built file.

The command is run from an unspecified directory, and Meson will set three environment variables MESON_SOURCE_ROOT, MESON_BUILD_ROOT and MESON_SUBDIR that specify the source directory, build directory and subdirectory the target was defined in, respectively.

Since 0.57.0 The template strings passed to command keyword arguments accept the following special substitutions:

  • @SOURCE_ROOT@: the path to the root of the source tree. Depending on the backend, this may be an absolute or a relative to current workdir path.
  • @BUILD_ROOT@: the path to the root of the build tree. Depending on the backend, this may be an absolute or a relative to current workdir path.
  • @CURRENT_SOURCE_DIR@ Since 0.57.1: this is the directory where the currently processed meson.build is located in. Depending on the backend, this may be an absolute or a relative to current workdir path.

Signature

# This function creates a new top-level target that runs a specified
run_tgt run_target(
  str target_name,     # The name of the run target

  # Keyword arguments:
  command : list[exe | external_program | custom_tgt | file | str]  # A list containing the command to run and the arguments
  depends : list[build_tgt | custom_tgt]                            # A list of targets that this target depends on but which
  env     : env | list[str] | dict[str]                             # environment variables to set, such as
)

Arguments

The function run_target() accepts the following positional arguments:

Name Type Description Tags
target_name str

The name of the run target

Finally, run_target() accepts the following keyword arguments:

Name Type Description Tags
command list[exe | external_program | custom_tgt | file | str]

A list containing the command to run and the arguments to pass to it. Each list item may be a string or a target. For instance, passing the return value of executable() as the first item will run that executable, or passing a string as the first item will find that command in PATH and run it.

depends list[build_tgt | custom_tgt]

A list of targets that this target depends on but which are not listed in the command array (because, for example, the script does file globbing internally)

env env | list[str] | dict[str]

environment variables to set, such as {'NAME1': 'value1', 'NAME2': 'value2'} or ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling.

(since 0.57.0)


set_variable()

Assigns a value to the given variable name. Calling set_variable('foo', bar) is equivalent to foo = bar.

(since 0.46.1) The value parameter can be an array type.

Signature

# Assigns a value to the given variable name
void set_variable(
  str variable_name,     # The name of the variable to set
  any value,             # The value to set the variable to
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function set_variable() accepts the following positional arguments:

Name Type Description Tags
variable_name str

The name of the variable to set

value any

The value to set the variable to


shared_library()

Builds a shared library with the given sources.

Signature

# Builds a shared library with the given sources
lib shared_library(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  darwin_versions              : str | int | list[str]                                                   # Defines the `compatibility version` and `current version` for the dylib on macOS
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  soversion                    : str | int                                                               # A string or integer specifying the soversion of this shared library,
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  version                      : str                                                                     # A string specifying the version of this shared library,
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)

Arguments

The function shared_library() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, shared_library() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

darwin_versions str | int | list[str]

Defines the compatibility version and current version for the dylib on macOS. If a list is specified, it must be either zero, one, or two elements. If only one element is specified or if it's not a list, the specified value will be used for setting both compatibility version and current version. If unspecified, the soversion will be used as per the aforementioned rules.

(since 0.48.0)

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "dylib" crate.

  • 'c': Create a "cdylib" crate.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

soversion str | int

A string or integer specifying the soversion of this shared library, such as 0. On Linux and Windows this is used to set the soversion (or equivalent) in the filename. For example, if soversion is 4, a Windows DLL will be called foo-4.dll and one of the aliases of the Linux shared library would be libfoo.so.4. If this is not specified, the first part of version is used instead (see below). For example, if version is 3.6.0 and soversion is not defined, it is set to 3.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

version str

A string specifying the version of this shared library, such as 1.1.0. On Linux and OS X, this is used to set the shared library version in the filename, such as libfoo.so.1.1.0 and libfoo.1.1.0.dylib. If this is not specified, soversion is used instead (see above).

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

(Since 1.3.0) custom_idx are supported

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


shared_module()

Builds a shared module with the given sources.

This is useful for building modules that will be dlopen()ed and hence may contain undefined symbols that will be provided by the library that is loading it.

If you want the shared module to be able to refer to functions and variables defined in the executable() it is loaded by, you will need to set the export_dynamic argument of the executable to true.

Signature

(since 0.37.0)

# Builds a shared module with the given sources
build_tgt shared_module(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  vs_module_defs               : str | file | custom_tgt | custom_idx                                    # Specify a Microsoft module definition file for controlling symbol exports,
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)
Note:

Linking to a shared module on platforms other than Android is deprecated, and will be an error in the future. It was previously allowed because it was the only way to have a shared-library-like target that contained references to undefined symbols. However, since 0.40.0, the override_options: build_target() keyword argument can be used to create such a shared_library() by passing override_options: 'b_lundef=false'. Shared modules have other characteristics that make them incompatible with linking, such as a lack of SONAME. On macOS and iOS, linking to shared modules is disallowed by the linker, so we disallow it at configure time. On Android, if a shared module foo uses symbols from another shared module bar, foo must also be linked to bar. Hence, linking one shared module to another will always be allowed when building for Android.

Arguments

The function shared_module() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, shared_module() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "dylib" crate.

  • 'c': Create a "cdylib" crate.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

vs_module_defs str | file | custom_tgt | custom_idx

Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows).

(Since 1.3.0) custom_idx are supported

(since 0.52.0)

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


static_library()

Builds a static library with the given sources.

Signature

# Builds a static library with the given sources
lib static_library(
  str                                                   target_name,     # The *unique* name of the build target
  str | file | custom_tgt | custom_idx | generated_list source...,       # Input source to compile

  # Keyword arguments:
  <lang>_args                  : list[str]                                                               # compiler flags to use for the given language;
  <lang>_pch                   : str                                                                     # precompiled header file to use for the given language
  build_by_default             : bool                                                                    # Causes, when set to `true`, to have this target be built by default
  build_rpath                  : str                                                                     # A string to add to target's rpath definition in the build dir,
  d_debug                      : list[str]                                                               # The [D version identifiers](https://dlang
  d_import_dirs                : list[str]                                                               # List of directories to look in for string imports used in the D programming language
  d_module_versions            : list[str | int]                                                         # List of module version identifiers set when compiling D sources
  d_unittest                   : bool                                                                    # When set to true, the D modules are compiled in debug mode
  dependencies                 : list[dep]                                                               # one or more dependency objects
  extra_files                  : str | file | custom_tgt | custom_idx                                    # Not used for the build itself but are shown as source files in IDEs
  gnu_symbol_visibility        : str                                                                     # Specifies how symbols should be exported, see
  gui_app                      : bool                                                                    # When set to true flags this target as a GUI application
  implicit_include_directories : bool                                                                    # Controls whether Meson adds the current source and build directories to the include path
  include_directories          : list[inc | str]                                                         # one or more objects created with the include_directories() function,
  install                      : bool                                                                    # When set to true, this executable should be installed
  install_dir                  : str                                                                     # override install directory for this file
  install_mode                 : list[str | int]                                                         # Specify the file mode in symbolic format
  install_rpath                : str                                                                     # A string to set the target's rpath to after install
  install_tag                  : str                                                                     # A string used by the `meson install --tags` command
  link_args                    : list[str]                                                               # Flags to use during linking
  link_depends                 : str | file | custom_tgt | custom_idx                                    # Strings, files, or custom targets the link step depends on
  link_language                : str                                                                     # Makes the linker for this target be for the specified language
  link_whole                   : list[lib | custom_tgt | custom_idx]                                     # Links all contents of the given static libraries whether they are used or
  link_with                    : list[lib | custom_tgt | custom_idx]                                     # One or more shared or static libraries
  name_prefix                  : str | list[void]                                                        # The string that will be used as the prefix for the
  name_suffix                  : str | list[void]                                                        # The string that will be used as the extension for the
  native                       : bool                                                                    # Controls whether the target is compiled for the build or host machines
  objects                      : list[extracted_obj | file | str]                                        # List of object files that should be linked in this target
  override_options             : list[str] | dict[str | bool | int | list[str]]                            # takes an array of strings in the same format as `project`'s `default_options`
  pic                          : bool                                                                    # Builds the library as positional independent code
  prelink                      : bool                                                                    # If `true` the object files in the target will be prelinked,
  rust_abi                     : str                                                                     # Set the specific ABI to compile (when compiling rust)
  rust_crate_type              : str                                                                     # Set the specific type of rust crate to compile (when compiling rust)
  rust_dependency_map          : dict[str]                                                               # On rust targets this provides a map of library names to the crate name
  sources                      : str | file | custom_tgt | custom_idx | generated_list | structured_src  # Additional source files
  vala_args                    : list[str | file]                                                        # Compiler flags for Vala
  win_subsystem                : str                                                                     # Specifies the subsystem type to use
)

Arguments

The function static_library() accepts the following positional arguments:

Name Type Description Tags
target_name str

The unique name of the build target

Additionally, the function accepts between 0 and infinity variadic arguments (source...) of type str | file | custom_tgt | custom_idx | generated_list.

Input source to compile. The following types are supported:

These input files can be sources, objects, libraries, or any other file. Meson will automatically categorize them based on the extension and use them accordingly. For instance, sources (.c, .cpp, .vala, .rs, etc) will be compiled and objects (.o, .obj) and libraries (.so, .dll, etc) will be linked.

With the Ninja backend, Meson will create a build-time order-only dependency on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile generated by your compiler to determine when to rebuild sources. Ninja relies on this dependency file for all input files, generated and non-generated. The behavior is similar for other backends.

Finally, static_library() accepts the following keyword arguments:

Name Type Description Tags
<lang>_args list[str]

compiler flags to use for the given language; eg: cpp_args for C++

<lang>_pch str

precompiled header file to use for the given language

build_by_default bool

Causes, when set to true, to have this target be built by default. This means it will be built when meson compile is called without any arguments. The default value is true for all built target types.

(since 0.38.0)

default = true

build_rpath str

A string to add to target's rpath definition in the build dir, but which will be removed on install

(since 0.42.0)

d_debug list[str]

The D version identifiers to add during the compilation of D source files.

d_import_dirs list[str]

List of directories to look in for string imports used in the D programming language.

d_module_versions list[str | int]

List of module version identifiers set when compiling D sources.

d_unittest bool

When set to true, the D modules are compiled in debug mode.

default = false

dependencies list[dep]

one or more dependency objects created with dependency() or compiler.find_library() (for external deps) or declare_dependency() (for deps built by the project)

extra_files str | file | custom_tgt | custom_idx

Not used for the build itself but are shown as source files in IDEs that group files by targets (such as Visual Studio)

gnu_symbol_visibility str

Specifies how symbols should be exported, see e.g the GCC Wiki for more information. This value can either be an empty string or one of default, internal, hidden, protected or inlineshidden, which is the same as hidden but also includes things like C++ implicit constructors as specified in the GCC manual. Ignored on compilers that do not support GNU visibility arguments.

(since 0.48.0)

gui_app bool

When set to true flags this target as a GUI application on platforms where this makes a difference, deprecated since 0.56.0, use win_subsystem instead.

DEPRECATED

in 0.56.0

default = false

implicit_include_directories bool

Controls whether Meson adds the current source and build directories to the include path

(since 0.42.0)

default = true

include_directories list[inc | str]

one or more objects created with the include_directories() function, or (since 0.50.0) strings, which will be transparently expanded to include directory objects

install bool

When set to true, this executable should be installed.

default = false

install_dir str

override install directory for this file. If the value is a relative path, it will be considered relative the prefix option. For example, if you want to install plugins into a subdir, you'd use something like this: install_dir : get_option('libdir') / 'projectname-1.0'.

install_mode list[str | int]

Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the installed files.

See the install_mode kwarg of install_data() for more information.

(since 0.47.0)

install_rpath str

A string to set the target's rpath to after install (but not before that). On Windows, this argument has no effect.

install_tag str

A string used by the meson install --tags command to install only a subset of the files. By default all build targets have the tag runtime except for static libraries that have the devel tag.

(since 0.60.0)

name_prefix str | list[void]

The string that will be used as the prefix for the target output filename by overriding the default (only used for libraries). By default this is lib on all platforms and compilers, except for MSVC shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is cyg.

Set this to [], or omit the keyword argument for the default behaviour.

name_suffix str | list[void]

The string that will be used as the extension for the target by overriding the default. By default on Windows this is exe for executables and on other platforms it is omitted.

For shared libraries, the default value is dylib on macOS, dll on Windows, and so everywhere else. For static libraries, it is a everywhere. By convention MSVC static libraries use the lib suffix, but we use a to avoid a potential name clash with shared libraries which also generate import libraries with a lib suffix.

Set this to [], or omit the keyword argument for the default behaviour.

native bool

Controls whether the target is compiled for the build or host machines.

default = false

objects list[extracted_obj | file | str]

List of object files that should be linked in this target.

Since 1.1.0 this can include generated files in addition to object files that you don't have source to or that object files produced by other build targets. In earlier release, generated object files had to be placed in sources.

override_options list[str] | dict[str | bool | int | list[str]]

takes an array of strings in the same format as project's default_options overriding the values of these options for this target only. (since 1.2.0): A dictionary may now be passed.

(since 0.40.0)

pic bool

Builds the library as positional independent code (so it can be linked into a shared library). This option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be disabled on OS X.

(since 0.36.0)

rust_abi str

Set the specific ABI to compile (when compiling rust).

  • 'rust' (default): Create a "rlib" crate.

  • 'c': Create a "staticlib" crate.

(since 1.3.0)

rust_crate_type str

Set the specific type of rust crate to compile (when compiling rust).

If the target is an executable() this defaults to "bin", the only allowed value.

If it is a static_library() it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib" then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.

If it is a shared_library() it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a Rust ABI, and "proc-macro" is a special rust procedural macro crate.

"proc-macro" is new in 0.62.0.

Since 1.3.0 this is deprecated and replaced by "rust_abi" keyword argument. proc_macro crates are now handled by the rust.proc_macro() method.

(since 0.42.0)

DEPRECATED

in 1.3.0

rust_dependency_map dict[str]

On rust targets this provides a map of library names to the crate name with which it would be available inside the rust code.

This allows renaming similar to the dependency renaming feature of cargo or extern crate foo as bar inside rust code.

(since 1.2.0)

sources str | file | custom_tgt | custom_idx | generated_list | structured_src

Additional source files. Same as the source varargs.

vala_args list[str | file]

Compiler flags for Vala. Unlike other languages this may contain Files

win_subsystem str

Specifies the subsystem type to use on the Windows platform. Typical values include console for text mode programs and windows for gui apps. The value can also contain version specification such as windows,6.0. See MSDN documentation for the full list.

(since 0.56.0)

default = 'console'


structured_sources()

Create a StructuredSource object, which is opaque and may be passed as a source to any build_target (including static_library, shared_library, executable, etc.). This is useful for languages like Rust, which use the filesystem layout to determine import names. This is only allowed in Rust targets, and cannot be mixed with non structured inputs.

Signature

(since 0.62.0)

# Create a StructuredSource object, which is opaque and may be passed as a source
structured_src structured_sources(
  list[str | file | custom_tgt | custom_idx | generated_list] root,           # Sources to put at the root of the generated structure
  dict[str | file | custom_tgt | custom_idx | generated_list] [additional],   # Additional sources, where the key is the directory under the root to place
)

Arguments

The function structured_sources() accepts the following positional arguments:

Name Type Description Tags
root list[str | file | custom_tgt | custom_idx | generated_list]

Sources to put at the root of the generated structure

additional dict[str | file | custom_tgt | custom_idx | generated_list]

Additional sources, where the key is the directory under the root to place the values

[optional]


subdir()

Enters the specified subdirectory and executes the meson.build file in it. Once that is done, it returns and execution continues on the line following this subdir() command. Variables defined in that meson.build file are then available for use in later parts of the current build file and in all subsequent build files executed with subdir().

Note that this means that each meson.build file in a source tree can and must only be executed once.

Signature

# Enters the specified subdirectory and executes the `meson
void subdir(
  str dir_name,     # Directory relative to the current `meson

  # Keyword arguments:
  if_found : list[dep]  # Only enter the subdir if all dep.found() methods return `true`.
)

Arguments

The function subdir() accepts the following positional arguments:

Name Type Description Tags
dir_name str

Directory relative to the current meson.build to enter.

Cannot contain ..

Finally, subdir() accepts the following keyword arguments:

Name Type Description Tags
if_found list[dep]

Only enter the subdir if all dep.found() methods return true.

(since 0.44.0)


subdir_done()

Stops further interpretation of the Meson script file from the point of the invocation. All steps executed up to this point are valid and will be executed by Meson. This means that all targets defined before the call of subdir_done() will be build.

If the current script was called by subdir the execution returns to the calling directory and continues as if the script had reached the end. If the current script is the top level script Meson configures the project as defined up to this point.

Signature

(since 0.46.0)

void subdir_done()

Example

project('example exit', 'cpp')
executable('exe1', 'exe1.cpp')
subdir_done()
executable('exe2', 'exe2.cpp')

The executable exe1 will be build, while the executable exe2 is not build.


subproject()

Takes the project specified in the positional argument and brings that in the current build specification by returning a subproject object. Subprojects must always be placed inside the subprojects directory at the top source directory. So for example a subproject called foo must be located in ${MESON_SOURCE_ROOT}/subprojects/foo.

  • default_options (since 0.37.0): an array of default option values that override those set in the subproject's meson.options (like default_options in project, they only have effect when Meson is run for the first time, and command line arguments override any default options in build files). (since 0.54.0): default_library built-in option can also be overridden. (since 1.2.0): A dictionary may be passed instead of array.
  • version: works just like the same as in dependency. It specifies what version the subproject should be, as an example >=1.0.1
  • required (since 0.48.0): By default, required is true and Meson will abort if the subproject could not be setup. You can set this to false and then use the .found() method on the subproject object. You may also pass the value of a feature option, same as dependency().

Note that you can use the returned subproject object to access any variable in the subproject. However, if you want to use a dependency object from inside a subproject, an easier way is to use the fallback: keyword argument to dependency().

See additional documentation.

Signature

# Takes the project specified in the positional argument and brings that
subproject subproject(
  str subproject_name,     # Name of the subproject

  # Keyword arguments:
  default_options : list[str] | dict[str | bool | int | list[str]]  # An array of default option values
  required        : bool | feature                                # Works just the same as in dependency().
  version         : str                                           # Works just like the same as in dependency().
)

Arguments

The function subproject() accepts the following positional arguments:

Name Type Description Tags
subproject_name str

Name of the subproject. The subproject must exist in the subprojects directory (or the directory specified in the subproject_dir of project()) as a directory or wrap file.

Finally, subproject() accepts the following keyword arguments:

Name Type Description Tags
default_options list[str] | dict[str | bool | int | list[str]]

An array of default option values that override those set in the subproject's meson.options (like default_options in project(), they only have effect when Meson is run for the first time, and command line arguments override any default options in build files). (since 0.54.0): default_library built-in option can also be overridden. (since 1.2.0): A dictionary may now be passed.

(since 0.37.0)

required bool | feature

Works just the same as in dependency().

(since 0.48.0)

default = true

version str

Works just like the same as in dependency(). It specifies what version the subproject should be, as an example >=1.0.1.


summary()

This function is used to summarize build configuration at the end of the build process. This function provides a way for projects (and subprojects) to report this information in a clear way.

The content is a series of key/value pairs grouped into sections. If the section keyword argument is omitted, those key/value pairs are implicitly grouped into a section with no title. key/value pairs can optionally be grouped into a dictionary, but keep in mind that dictionaries do not guarantee ordering. key must be string, value can be:

  • an integer, boolean or string
  • since 0.57.0 an external program or a dependency
  • since 0.58.0 a feature option
  • a list of those.

Instead of calling summary as summary(key, value), it is also possible to directly pass a dictionary to the summary() function, as seen in the example below.

summary() can be called multiple times as long as the same section/key pair doesn't appear twice. All sections will be collected and printed at the end of the configuration in the same order as they have been called.

Signature

(since 0.53.0)

# This function is used to summarize build configuration at the end of the build
void summary(
  str | dict[str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]] key_or_dict,     # The name of the new entry, or a dict containing multiple entries
  str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]           [value],         # The value to print for the `key`

  # Keyword arguments:
  bool_yn  : bool  # Convert bool values to yes and no
  list_sep : str   # The separator to use when printing list values in this summary
  section  : str   # The section to put this summary information under
)

Example

Example meson.build:

project('My Project', version : '1.0')
summary({'bindir': get_option('bindir'),
        'libdir': get_option('libdir'),
        'datadir': get_option('datadir'),
        }, section: 'Directories')
summary({'Some boolean': false,
        'Another boolean': true,
        'Some string': 'Hello World',
        'A list': ['string', 1, true],
        }, section: 'Configuration')

Output:

My Project 1.0

  Directories
    prefix         : /opt/gnome
    bindir         : bin
    libdir         : lib/x86_64-linux-gnu
    datadir        : share

  Configuration
    Some boolean   : False
    Another boolean: True
    Some string    : Hello World
    A list         : string
                     1
                     True

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function summary() accepts the following positional arguments:

Name Type Description Tags
key_or_dict str | dict[str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]]

The name of the new entry, or a dict containing multiple entries. If a dict is passed it is equivalent to calling summary() once for each key-value pair. Keep in mind that dictionaries do not guarantee ordering.

value str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]

The value to print for the key. Only valid if key_or_dict is a str.

[optional]

Finally, summary() accepts the following keyword arguments:

Name Type Description Tags
bool_yn bool

Convert bool values to yes and no

default = false

list_sep str

The separator to use when printing list values in this summary. If no separator is given, each list item will be printed on its own line.

(since 0.54.0)

section str

The section to put this summary information under. If the section keyword argument is omitted, key/value pairs are implicitly grouped into a section with no title.


test()

Defines a test to run with the test harness. Takes two positional arguments, the first is the name of the test and the second is the executable to run. The executable can be an exe object returned by executable() or an external_program object] returned by find_program().

(since 0.55.0) When cross compiling, if an exe_wrapper is needed and defined the environment variable MESON_EXE_WRAPPER will be set to the string value of that wrapper (implementation detail: using mesonlib.join_args). Test scripts may use this to run cross built binaries. If your test needs MESON_EXE_WRAPPER in cross build situations it is your responsibility to return code 77 to tell the harness to report "skip".

By default, environment variable MALLOC_PERTURB_ is automatically set by meson test to a random value between 1..255. This can help find memory leaks on configurations using glibc, including with non-GCC compilers. However, this can have a performance impact, and may fail a test due to external libraries whose internals are out of the user's control. To check if this feature is causing an expected runtime crash, disable the feature by temporarily setting environment variable MALLOC_PERTURB_=0. While it's preferable to only temporarily disable this check, if a project requires permanent disabling of this check in meson.build do like:

nomalloc = environment({'MALLOC_PERTURB_': '0'})

test(..., env: nomalloc, ...)

By default, the environment variables ASAN_OPTIONS, UBSAN_OPTIONS, and MSAN_OPTIONS are set to enable aborting on detected violations and to give a backtrace. To suppress this, ASAN_OPTIONS, UBSAN_OPTIONS, or MSAN_OPTIONS can be set in the environment.

In addition to running individual executables as test cases, test() can also be used to invoke an external test harness. In this case, it is best to use verbose: true (since 0.62.0) and, if supported by the external harness, protocol: 'tap' (since 0.50.0). This will ensure that Meson logs each subtest as it runs, instead of including the whole log at the end of the run.

Defined tests can be run in a backend-agnostic way by calling meson test inside the build dir, or by using backend-specific commands, such as ninja test or msbuild RUN_TESTS.vcxproj.

Signature

# Defines a test to run with the test harness
void test(
  str                                                           name,           # The *unique* test id
  exe | jar | external_program | file | custom_tgt | custom_idx executable,     # The program to execute

  # Keyword arguments:
  args        : list[str | file | tgt]        # Arguments to pass to the executable
  depends     : list[build_tgt | custom_tgt]  # specifies that this test depends on the specified
  env         : env | list[str] | dict[str]   # environment variables to set, such as `['NAME1=value1',
  is_parallel : bool                          # when false, specifies that no other test must be
  priority    : int                           # specifies the priority of a test
  protocol    : str                           # specifies how the test results are parsed and can
  should_fail : bool                          # when true the test is considered passed if the
  suite       : str | list[str]               # `'label'` (or list of labels `['label1', 'label2']`)
  timeout     : int                           # the amount of seconds the test is allowed to run, a test
  verbose     : bool                          # if true, forces the test results to be logged as if `--verbose` was passed
  workdir     : str                           # absolute path that will be used as the working directory
)

Arguments

The function test() accepts the following positional arguments:

Name Type Description Tags
name str

The unique test id

executable exe | jar | external_program | file | custom_tgt | custom_idx

The program to execute. (Since 1.4.0) A CustomTarget is also accepted.

Finally, test() accepts the following keyword arguments:

Name Type Description Tags
args list[str | file | tgt]

Arguments to pass to the executable

depends list[build_tgt | custom_tgt]

specifies that this test depends on the specified target(s), even though it does not take any of them as a command line argument. This is meant for cases where test finds those targets internally, e.g. plugins or globbing. Those targets are built before test is executed even if they have build_by_default : false.

(since 0.46.0)

env env | list[str] | dict[str]

environment variables to set, such as ['NAME1=value1', 'NAME2=value2'], or an env object which allows more sophisticated environment juggling. (Since 0.52.0) A dictionary is also accepted.

is_parallel bool

when false, specifies that no other test must be running at the same time as this test

default = true

priority int

specifies the priority of a test. Tests with a higher priority are started before tests with a lower priority. The starting order of tests with identical priorities is implementation-defined. The default priority is 0, negative numbers are permitted.

(since 0.52.0)

default = 0

protocol str

specifies how the test results are parsed and can be one of exitcode, tap, or gtest. For more information about test harness protocol read Unit Tests. The following values are accepted:

  • exitcode: the executable's exit code is used by the test harness to record the outcome of the test).

  • tap: Test Anything Protocol.

  • gtest (since 0.55.0): for Google Tests.

  • rust (since 0.56.0): for native rust tests

(since 0.50.0)

default = 'exitcode'

should_fail bool

when true the test is considered passed if the executable returns a non-zero return value (i.e. reports an error)

default = false

suite str | list[str]

'label' (or list of labels ['label1', 'label2']) attached to this test. The suite name is qualified by a (sub)project name resulting in (sub)project_name:label. In the case of a list of strings, the suite names will be (sub)project_name:label1, (sub)project_name:label2, etc.

timeout int

the amount of seconds the test is allowed to run, a test that exceeds its time limit is always considered failed, defaults to 30 seconds. Since 0.57 if timeout is <= 0 the test has infinite duration, in previous versions of Meson the test would fail with a timeout immediately.

default = 30

verbose bool

if true, forces the test results to be logged as if --verbose was passed to meson test.

(since 0.62.0)

default = false

workdir str

absolute path that will be used as the working directory for the test


unset_variable()

Unsets a variable. Referencing a variable which has been unset is an error until it has been set again.

Signature

(since 0.60.0)

# Unsets a variable
void unset_variable(
  str varname,     # The variable to unset
)

Arguments

The function unset_variable() accepts the following positional arguments:

Name Type Description Tags
varname str

The variable to unset.


vcs_tag()

This command detects revision control commit information at build time and places it in the specified output file. This file is guaranteed to be up to date on every build. Keywords are similar to custom_target().

Meson will read the contents of input, substitute the replace_string with the detected revision number, and write the result to output. This method returns a custom_tgt object that (as usual) should be used to signal dependencies if other targets use the file outputted by this.

For example, if you generate a header with this and want to use that in a build target, you must add the return value to the sources of that build target. Without that, Meson will not know the order in which to build the targets.

If you desire more specific behavior than what this command provides, you should use custom_target().

Signature

# This command detects revision control commit information at build time
custom_tgt vcs_tag(
  command        : list[exe | external_program | custom_tgt | file | str]              # The command to execute, see custom_target() for details
  fallback       : str                                                                 # Version number to use when no revision control information is present,
  input          : str                                                     [required]  # File to modify (e
  output         : str                                                     [required]  # File to write the results to (e
  replace_string : str                                                                 # String in the input file to substitute with the commit information
)

Arguments

The function vcs_tag() accepts the following keyword arguments:

Name Type Description Tags
command list[exe | external_program | custom_tgt | file | str]

The command to execute, see custom_target() for details on how this command must be specified.

This parameter is optional. If it is absent, Meson will try its best to find a suitable default command.

(since 0.62.0) file is accepted.

(since 0.63.0) custom_tgt, exe, and external_program are accepted.

fallback str

Version number to use when no revision control information is present, such as when building from a release tarball.

input str

File to modify (e.g. version.c.in).

output str

File to write the results to (e.g. version.c).

replace_string str

String in the input file to substitute with the commit information.

default = '@VCS_TAG@'


warning()

This function prints its argument to stdout prefixed with WARNING:.

Signature

(since 0.44.0)

# This function prints its argument to stdout prefixed with WARNING:
void warning(
  str | int | bool | list[str | int | bool] | dict[str | int | bool] text,          # The message to print
  str | int | bool | list[str | int | bool] | dict[str | int | bool] more_text...,  # Additional text that will be printed separated by spaces
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The function warning() accepts the following positional arguments:

Name Type Description Tags
text str | int | bool | list[str | int | bool] | dict[str | int | bool]

The message to print.

Additionally, the function accepts between 0 and infinity variadic arguments (more_text...) of type str | int | bool | list[str | int | bool] | dict[str | int | bool].

Additional text that will be printed separated by spaces.

(since 0.54.0)


The results of the search are