meson-reference(3) | Library Functions Manual | meson-reference(3) |
NAME¶
meson-reference v1.5.1 - a reference for meson functions and objects
DESCRIPTION¶
This manual is divided into two sections, FUNCTIONS and OBJECTS. FUNCTIONS contains a reference for all meson functions and methods. Methods are denoted by object_name.method_name(). OBJECTS contains additional information about each object.
FUNCTIONS¶
add_global_arguments()¶
language:,
native: false,
DESCRIPTION
VARARGS
native bool, default: false, since 0.48.0
add_global_link_arguments()¶
language:,
native: false,
DESCRIPTION
Like add_global_arguments but the arguments are passed to the linker.
VARARGS
native bool, default: false, since 0.48.0
add_languages()¶
DESCRIPTION
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.
VARARGS
required bool | feature, default: true
if compiling_for_osx
add_languages('objc')
endif
if add_languages('cpp', required : false)
executable('cpp-app', 'main.cpp')
endif
# More code...
add_project_arguments()¶
language:,
native: false,
DESCRIPTION
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.
VARARGS
native bool, default: false, since 0.48.0
add_project_dependencies()¶
language:,
native: false,
since 0.63.0
DESCRIPTION
VARARGS
native bool, default: false, since 0.48.0
add_project_link_arguments()¶
language:,
native: false,
DESCRIPTION
Like add_project_arguments but the arguments are passed to the linker.
VARARGS
native bool, default: false, since 0.48.0
add_test_setup()¶
env:,
exclude_suites:,
exe_wrapper:,
gdb: false,
is_default: false,
timeout_multiplier: 1,
DESCRIPTION
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.
POSARGS
exclude_suites list[str], since 0.57.0
exe_wrapper list[str | external_program]
gdb bool, default: false
is_default bool, default: false, since 0.49.0
timeout_multiplier int, default: 1
alias_target()¶
since 0.52.0
DESCRIPTION
POSARGS
assert()¶
DESCRIPTION
POSARGS
benchmark()¶
executable,
args:,
depends:,
env:,
priority: 0,
protocol: 'exitcode',
should_fail: false,
suite:,
timeout: 30,
verbose: false,
workdir:,
DESCRIPTION
* 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`.
POSARGS
executable exe | jar | external_program | file |
custom_tgt | custom_idx, required
depends list[build_tgt | custom_tgt], since 0.46.0
env env | list[str] | dict[str]
priority int, default: 0, since 0.52.0
protocol str, default: 'exitcode', since 0.50.0
- `exitcode`: the executable's exit code is used by the test
harness to record the outcome of the test).
- `tap`: Test Anything Protocol[3].
- `gtest` (since 0.55.0): for Google Tests.
- `rust` (since 0.56.0): for native rust tests
should_fail bool, default: false
suite str | list[str]
timeout int, default: 30
verbose bool, default: false, since 0.62.0
workdir str
both_libraries()¶
source...,
<lang>_args:,
<lang>_pch:,
<lang>_shared_args:,
<lang>_static_args:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
darwin_versions:,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
pic:,
prelink:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
soversion:,
vala_args:,
vala_shared_args:,
vala_static_args:,
version:,
vs_module_defs:,
win_subsystem: 'console',
since 0.46.0
DESCRIPTION
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[4] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[5] 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.
<lang>_pch str
<lang>_shared_args list[str], since 1.3.0
<lang>_static_args list[str], since 1.3.0
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
darwin_versions str | int | list[str], since 0.48.0
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
pic bool, since 0.36.0
prelink bool, since 0.57.0
rust_abi str, since 1.3.0
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[8] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
soversion str | int
vala_args list[str | file]
vala_shared_args list[str | file], since 1.3.0
vala_static_args list[str | file], since 1.3.0
version str
vs_module_defs str | file | custom_tgt | custom_idx
(Since 1.3.0) custom_idx are supported
win_subsystem str, default: 'console', since 0.56.0
build_target()¶
source...,
<lang>_args:,
<lang>_pch:,
<lang>_shared_args:,
<lang>_static_args:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
darwin_versions:,
dependencies:,
export_dynamic:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implib:,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
java_resources:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
main_class:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
pic:,
pie:,
prelink:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
soversion:,
target_type:,
vala_args:,
vala_shared_args:,
vala_static_args:,
version:,
vs_module_defs:,
win_subsystem: 'console',
DESCRIPTION
`target_type` may be set to one of:
- `executable` (see executable)
- `shared_library` (see shared_library)
- `shared_module` (see shared_module)
- `static_library` (see static_library)
- `both_libraries` (see both_libraries)
- `library` (see library)
- `jar` (see jar)*
This declaration:
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.
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
<lang>_shared_args list[str], since 1.3.0
<lang>_static_args list[str], since 1.3.0
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
darwin_versions str | int | list[str], since 0.48.0
dependencies list[dep]
export_dynamic bool, since 0.45.0
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.
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implib bool | str, since 0.42.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
java_resources structured_src, since 0.62.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
main_class str
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
pic bool, since 0.36.0
pie bool, since 0.49.0
prelink bool, since 0.57.0
rust_abi str, since 1.3.0
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
soversion str | int
target_type str
vala_args list[str | file]
vala_shared_args list[str | file], since 1.3.0
vala_static_args list[str | file], since 1.3.0
version str
vs_module_defs str | file | custom_tgt | custom_idx,
since 1.3.0
This can be used to expose which functions a shared_module loaded by an executable will be allowed to use.
win_subsystem str, default: 'console', since 0.56.0
configuration_data()¶
DESCRIPTION
OPTARGS
configure_file()¶
command:,
configuration:,
copy: false,
depfile:,
encoding: 'utf-8',
format: 'meson',
input:,
install: false,
install_dir:,
install_mode:,
install_tag:,
macro_name:,
output:,
output_format:,
DESCRIPTION
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[10]. (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.
KWARGS
command list[str | file | compiler | external_program |
exe]
configuration cfg_data | dict[str | int | bool]
copy bool, default: false, since 0.47.0
depfile str, since 0.52.0
encoding str, default: 'utf-8', since 0.47.0
format str, default: 'meson', since 0.46.0
input str | file
install bool, default: false, since 0.50.0
install_dir str | bool
install_mode list[str | int | bool], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_tag str, since 0.60.0
macro_name str, since 1.3.0
output str
output_format str, since 0.47.0
custom_target()¶
build_always:,
build_always_stale: false,
build_by_default:,
capture: false,
command:,
console:,
depend_files:,
depends:,
depfile:,
env:,
feed: false,
input:,
install:,
install_dir:,
install_mode:,
install_tag:,
output:,
DESCRIPTION
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
- `@PLAINNAME0@` `@PLAINNAME1@` `...` (since 1.5.0): the input filename
without a path, with the specified array index in `input`
- `@BASENAME@`: the input filename, with extension removed
- `@BASENAME0@` `@BASENAME1@` `...` (since 1.5.0): the input filename
with extension removed, with the specified array index in `input`
- `@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.
OPTARGS
This posarg is optional since 0.60.0. It defaults to the basename of the first output.
build_always_stale bool, default: false, since
0.47.0
build_by_default bool, since 0.38.0
(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.
capture bool, default: false
command list[str | file | exe | external_program |
custom_tgt | build_tgt | custom_idx]
console bool, since 0.48.0
depend_files list[str | file]
depends list[build_tgt | custom_tgt | custom_idx]
depfile str
(since 0.47.0) the `@BASENAME@` and `@PLAINNAME@` substitutions are also accepted.
env env | list[str] | dict[str], since 0.57.0
feed bool, default: false, since 0.59.0
input list[str | file | build_tgt | custom_idx |
custom_tgt | external_program | extracted_obj | generated_list]
install bool
install_dir bool | str | list[bool | str]
output : ['first.file', 'second.file'],
install : true,
install_dir : ['somedir', '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'])
install_mode list[str | int | bool], since 0.47.0
install_tag list[str | bool], since 0.60.0
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.
output list[str]
debug()¶
since 0.63.0
DESCRIPTION
POSARGS
declare_dependency()¶
d_import_dirs:,
d_module_versions:,
dependencies:,
extra_files:,
include_directories:,
link_args:,
link_whole:,
link_with:,
objects:,
sources:,
variables:,
version:,
DESCRIPTION
KWARGS
d_import_dirs list[inc | str], since 0.62.0
d_module_versions str | int | list[str | int], since
0.62.0
dependencies list[dep]
extra_files list[str | file], since 1.2.0
include_directories list[inc | str]
link_args list[str]
link_whole list[lib], since 0.46.0
link_with list[lib]
objects list[extracted_obj], since 1.1.0
sources list[str | file | custom_tgt | custom_idx |
generated_list]
variables dict[str] | list[str], since 0.54.0
version str
dependency()¶
allow_fallback:,
default_options:,
disabler: false,
fallback:,
include_type: 'preserve',
language:,
method: 'auto',
native: false,
not_found_message:,
required: true,
static: false,
version:,
DESCRIPTION
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[15] 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[14] 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.
VARARGS
NOTE: Before 0.60.0 only a single dependency name was allowed.
default_options list[str] | dict[str | bool | int |
list[str]], since 0.38.0
disabler bool, default: false, since 0.49.0
fallback list[str] | str
include_type str, default: 'preserve', since 0.52.0
language str, since 0.42.0
method str, default: 'auto', since 0.40.0
native bool, default: false
not_found_message str, since 0.50.0
required bool | feature, default: true
When set to a `feature`[0] 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.
static bool, default: false
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.
version list[str] | str, since 0.37.0
disabler()¶
since 0.44.0
DESCRIPTION
environment()¶
since 0.35.0
DESCRIPTION
OPTARGS
separator str, since 0.62.0
error()¶
DESCRIPTION
POSARGS
executable()¶
source...,
<lang>_args:,
<lang>_pch:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
dependencies:,
export_dynamic:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implib:,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
pie:,
rust_crate_type:,
rust_dependency_map:,
sources:,
vala_args:,
vs_module_defs:,
win_subsystem: 'console',
DESCRIPTION
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`.
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
dependencies list[dep]
export_dynamic bool, since 0.45.0
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.
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implib bool | str, since 0.42.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
pie bool, since 0.49.0
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
vala_args list[str | file]
vs_module_defs str | file | custom_tgt | custom_idx,
since 1.3.0
This can be used to expose which functions a shared_module loaded by an executable will be allowed to use.
win_subsystem str, default: 'console', since 0.56.0
files()¶
DESCRIPTION
VARARGS
foofile = files('foo.cpp')
executable('myprog', 'myprog.cpp', foofile, ...)
find_program()¶
fallback...,
default_options:,
dirs:,
disabler: false,
native: false,
required: true,
version:,
version_argument:,
DESCRIPTION
1. Program overrides set via meson.override_find_program 1.
`[provide]` sections[14]
in subproject wrap files, if `wrap_mode`[17] is
set to `forcefallback` 1. `[binaries]` section[18] in your machine
files 1. Directories provided using the `dirs:` kwarg (see below) 1.
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 1. `PATH` environment
variable 1. `[provide]` sections[14] in
subproject wrap files, if `wrap_mode`[16] 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.
The returned external_program object also has documented methods.
POSARGS
dirs list[str], since 0.53.0
disabler bool, default: false, since 0.49.0
native bool, default: false, since 0.43.0
required bool | feature, default: true
version list[str], since 0.52.0
version_argument str, since 1.5.0
generator()¶
arguments:,
capture: false,
depends:,
depfile:,
output:,
DESCRIPTION
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.
POSARGS
capture bool, default: false, since 0.43.0
depends list[build_tgt | custom_tgt | custom_idx],
since 0.51.0
depfile str
output list[str]
get_option()¶
DESCRIPTION
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[20]. `install_dir` arguments[21] 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[0] documentation for more details.
POSARGS
get_variable()¶
DESCRIPTION
POSARGS
import()¶
DESCRIPTION
POSARGS
required bool | feature, default: true, since 0.59.0
tmod.do_something()
include_directories()¶
DESCRIPTION
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.
VARARGS
`meson.build`:
subdir('include')
subdir('src')
executable('some-tool', sources,
include_directories : inc,
...)
install_data()¶
follow_symlinks: true,
install_dir:,
install_mode:,
install_tag:,
preserve_path: false,
rename:,
sources:,
DESCRIPTION
See Installing[20] for more examples.
VARARGS
install_dir str
If omitted, the directory defaults to `{datadir}/{projectname}` (since 0.45.0).
install_mode list[str | int | bool], since 0.38.0
`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`.
install_tag str, since 0.60.0
preserve_path bool, default: false, since 0.64.0
This is equivalent to GNU Automake's `nobase` option.
rename list[str], since 0.46.0
sources list[file | str]
install_emptydir()¶
since 0.60.0
DESCRIPTION
VARARGS
See the `install_mode` kwarg of install_data for more information.
install_tag str
install_headers()¶
follow_symlinks: true,
install_dir:,
install_mode:,
preserve_path: false,
subdir:,
DESCRIPTION
VARARGS
install_dir str
install_mode list[str | int | bool], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
preserve_path bool, default: false, since 0.63.0
This is equivalent to GNU Automake's `nobase` option.
subdir str
Incompatible with the `install_dir` kwarg.
install_man()¶
DESCRIPTION
(since 0.49.0) [manpages are no longer compressed implicitly][install_man_49].
[install_man_49]: https://mesonbuild.com/Release-notes-for-0-49-0.html#manpages-are-no-longer-compressed-implicitly
VARARGS
install_mode list[str | int | bool], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
locale str, since 0.58.0
install_subdir()¶
exclude_directories:,
exclude_files:,
follow_symlinks: true,
install_dir:,
install_mode:,
install_tag:,
strip_directory: false,
DESCRIPTION
(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.
POSARGS
exclude_files list[str]
follow_symlinks bool, default: true, since 1.3.0
install_dir str
install_mode list[str | int | bool], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_tag str, since 0.60.0
strip_directory bool, default: false, since 0.45.0
foo/
bar/
file1
file2
share/
foo/
bar/
file1
file2
share/
bar/
file1
file2
share/
bar/
file1
share/
file1
share/
new_directory/
install_symlink()¶
install_dir:,
install_tag:,
pointing_to:,
since 0.61.0
DESCRIPTION
POSARGS
install_tag str
pointing_to str, required
is_disabler()¶
since 0.52.0
DESCRIPTION
POSARGS
is_variable()¶
since 0.52.0
DESCRIPTION
POSARGS
jar()¶
source...,
<lang>_args:,
<lang>_pch:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
java_resources:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
main_class:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
rust_crate_type:,
rust_dependency_map:,
sources:,
vala_args:,
win_subsystem: 'console',
DESCRIPTION
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
java_resources structured_src, since 0.62.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
main_class str
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
vala_args list[str | file]
win_subsystem str, default: 'console', since 0.56.0
join_paths()¶
since 0.36.0
DESCRIPTION
(since 0.49.0) Using the `/` operator on strings is equivalent to calling join_paths.
res1 = join_paths(foo, bar)
res2 = foo / bar
VARARGS
library()¶
source...,
<lang>_args:,
<lang>_pch:,
<lang>_shared_args:,
<lang>_static_args:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
darwin_versions:,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
pic:,
prelink:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
soversion:,
vala_args:,
vala_shared_args:,
vala_static_args:,
version:,
vs_module_defs:,
win_subsystem: 'console',
DESCRIPTION
The keyword arguments for this are the same as for build_target
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
<lang>_shared_args list[str], since 1.3.0
<lang>_static_args list[str], since 1.3.0
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
darwin_versions str | int | list[str], since 0.48.0
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
pic bool, since 0.36.0
prelink bool, since 0.57.0
rust_abi str, since 1.3.0
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
soversion str | int
vala_args list[str | file]
vala_shared_args list[str | file], since 1.3.0
vala_static_args list[str | file], since 1.3.0
version str
vs_module_defs str | file | custom_tgt | custom_idx
(Since 1.3.0) custom_idx are supported
win_subsystem str, default: 'console', since 0.56.0
message()¶
DESCRIPTION
POSARGS
project()¶
language...,
default_options:,
license:,
license_files:,
meson_version:,
subproject_dir: 'subprojects',
version:,
DESCRIPTION
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`.
POSARGS
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]
This should be an SPDX license expression[23], using the standardized license identifier from the SPDX license list[24]. 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], since 1.1.0
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.
meson_version str
subproject_dir str, default: 'subprojects'
version str | file
range()¶
since 0.58.0
DESCRIPTION
<pre><code class="language-meson">range range(int <b>stop</b>) range range(int <b>start</b>, int <b>stop</b>[, int <b>step</b>])</code></pre>
- `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.
OPTARGS
stop int
step int, default: 1
foreach i : range(15)
...
endforeach
assert(r[2] == 9)
run_command()¶
capture: true,
check: false,
env:,
DESCRIPTION
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[25].
VARARGS
check bool, default: false, since 0.47.0
env env | list[str] | dict[str], since 0.50.0
run_target()¶
DESCRIPTION
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.
POSARGS
depends list[build_tgt | custom_tgt | custom_idx]
env env | list[str] | dict[str], since 0.57.0
set_variable()¶
DESCRIPTION
(since 0.46.1) The `value` parameter can be an array type.
POSARGS
value any, required
shared_library()¶
source...,
<lang>_args:,
<lang>_pch:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
darwin_versions:,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
soversion:,
vala_args:,
version:,
vs_module_defs:,
win_subsystem: 'console',
DESCRIPTION
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
darwin_versions str | int | list[str], since 0.48.0
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
rust_abi str, since 1.3.0
- 'c': Create a "cdylib" crate.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
soversion str | int
vala_args list[str | file]
version str
vs_module_defs str | file | custom_tgt | custom_idx
(Since 1.3.0) custom_idx are supported
win_subsystem str, default: 'console', since 0.56.0
shared_module()¶
source...,
<lang>_args:,
<lang>_pch:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
vala_args:,
vs_module_defs:,
win_subsystem: 'console',
since 0.37.0
DESCRIPTION
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`.
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
rust_abi str, since 1.3.0
- 'c': Create a "cdylib" crate.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
vala_args list[str | file]
vs_module_defs str | file | custom_tgt | custom_idx,
since 0.52.0
(Since 1.3.0) custom_idx are supported
win_subsystem str, default: 'console', since 0.56.0
static_library()¶
source...,
<lang>_args:,
<lang>_pch:,
build_by_default: true,
build_rpath:,
d_debug:,
d_import_dirs:,
d_module_versions:,
d_unittest: false,
dependencies:,
extra_files:,
gnu_symbol_visibility:,
gui_app: false,
implicit_include_directories: true,
include_directories:,
install: false,
install_dir:,
install_mode:,
install_rpath:,
install_tag:,
link_args:,
link_depends:,
link_language:,
link_whole:,
link_with:,
name_prefix:,
name_suffix:,
native: false,
objects:,
override_options:,
pic:,
prelink:,
rust_abi:,
rust_crate_type:,
rust_dependency_map:,
sources:,
vala_args:,
win_subsystem: 'console',
DESCRIPTION
POSARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
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[3] on all generated input files, including unknown files. This is needed to bootstrap the generation of the real dependencies in the depfile[4] 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.
<lang>_pch str
build_by_default bool, default: true, since 0.38.0
build_rpath str, since 0.42.0
d_debug list[str]
d_import_dirs list[str]
d_module_versions list[str | int]
d_unittest bool, default: false
dependencies list[dep]
extra_files str | file | custom_tgt | custom_idx
gnu_symbol_visibility str, since 0.48.0
gui_app bool, default: false, deprecated
since 0.56.0
implicit_include_directories bool, default: true,
since 0.42.0
include_directories list[inc | str]
install bool, default: false
install_dir str
install_mode list[str | int], since 0.47.0
See the `install_mode` kwarg of install_data for more information.
install_rpath str
install_tag str, since 0.60.0
link_args list[str]
link_depends str | file | custom_tgt | custom_idx
link_language str, since 0.51.0
(broken until 0.55.0)
link_whole list[lib | custom_tgt | custom_idx],
since 0.40.0
(since 0.41.0) If passed a list that list will be flattened.
(since 0.51.0) This argument also accepts outputs produced by custom targets. The user must ensure that the output is a library in the correct format.
link_with list[lib | custom_tgt | custom_idx]
name_prefix str | list[void]
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffix str | list[void]
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, default: false
objects list[extracted_obj | file | str]
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]], since 0.40.0
pic bool, since 0.36.0
prelink bool, since 0.57.0
rust_abi str, since 1.3.0
- 'c': Create a "staticlib" crate.
rust_crate_type str, deprecated since 1.3.0,
since 0.42.0
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()`[7] method.
rust_dependency_map dict[str], since 1.2.0
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as bar` inside rust code.
sources str | file | custom_tgt | custom_idx |
generated_list | structured_src
vala_args list[str | file]
win_subsystem str, default: 'console', since 0.56.0
structured_sources()¶
since 0.62.0
DESCRIPTION
POSARGS
subdir()¶
DESCRIPTION
Note that this means that each `meson.build` file in a source tree can and must only be executed once.
POSARGS
Cannot contain `..`
subdir_done()¶
since 0.46.0
DESCRIPTION
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.
EXAMPLE
executable('exe1', 'exe1.cpp')
subdir_done()
executable('exe2', 'exe2.cpp')
subproject()¶
default_options:,
required: true,
version:,
DESCRIPTION
- `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`[0] 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[26].
POSARGS
required bool | feature, default: true, since 0.48.0
version str | list[str]
summary()¶
[value],
bool_yn: false,
list_sep:,
section:,
since 0.53.0
DESCRIPTION
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.
POSARGS
list_sep str, since 0.54.0
section str
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')
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
test()¶
executable,
args:,
depends:,
env:,
is_parallel: true,
priority: 0,
protocol: 'exitcode',
should_fail: false,
suite:,
timeout: 30,
verbose: false,
workdir:,
DESCRIPTION
(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_`[27] 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:
test(..., env: nomalloc, ...)
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`.
POSARGS
executable exe | jar | external_program | file |
custom_tgt | custom_idx, required
depends list[build_tgt | custom_tgt], since 0.46.0
env env | list[str] | dict[str]
is_parallel bool, default: true
priority int, default: 0, since 0.52.0
protocol str, default: 'exitcode', since 0.50.0
- `exitcode`: the executable's exit code is used by the test
harness to record the outcome of the test).
- `tap`: Test Anything Protocol[2].
- `gtest` (since 0.55.0): for Google Tests.
- `rust` (since 0.56.0): for native rust tests
should_fail bool, default: false
suite str | list[str]
timeout int, default: 30
verbose bool, default: false, since 0.62.0
workdir str
unset_variable()¶
since 0.60.0
DESCRIPTION
POSARGS
vcs_tag()¶
fallback: [[meson.project_version]],
input:,
output:,
replace_string: '@VCS_TAG@',
DESCRIPTION
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.
KWARGS
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, default: [[meson.project_version]]
input list[build_tgt | custom_idx | custom_tgt |
external_program | extracted_obj | file | generated_list | str],
required
output str, required
replace_string str, default: '@VCS_TAG@'
warning()¶
since 0.44.0
DESCRIPTION
POSARGS
bool.to_int()¶
DESCRIPTION
bool.to_string()¶
DESCRIPTION
OPTARGS
false_str str, default: 'false'
both_libs.get_shared_lib()¶
DESCRIPTION
both_libs.get_static_lib()¶
DESCRIPTION
build_machine.cpu()¶
DESCRIPTION
build_machine.cpu_family()¶
DESCRIPTION
build_machine.endian()¶
DESCRIPTION
build_machine.system()¶
DESCRIPTION
build_tgt.extract_all_objects()¶
DESCRIPTION
By default only objects built for this target are returned to maintain backward compatibility with previous versions. The default value for the `recursive` kwarg will eventually be changed to `true` in a future version.
KWARGS
build_tgt.extract_objects()¶
DESCRIPTION
VARARGS
build_tgt.found()¶
since 0.59.0
DESCRIPTION
build_tgt.full_path()¶
DESCRIPTION
build_tgt.get_id()¶
since 0.26.0
DESCRIPTION
build_tgt.name()¶
since 0.54.0
DESCRIPTION
build_tgt.outdir()¶
since 0.26.0
DESCRIPTION
build_tgt.path()¶
deprecated since 0.59.0, since 0.59.0
DESCRIPTION
build_tgt.private_dir_include()¶
DESCRIPTION
cfg_data.get()¶
since 0.38.0
DESCRIPTION
POSARGS
cfg_data.get_unquoted()¶
since 0.44.0
DESCRIPTION
POSARGS
cfg_data.has()¶
DESCRIPTION
POSARGS
cfg_data.keys()¶
since 0.57.0
DESCRIPTION
You can iterate over this array with the `foreach` statement[30].
cfg_data.merge_from()¶
since 0.42.0
DESCRIPTION
POSARGS
cfg_data.set()¶
DESCRIPTION
POSARGS
value str | int | bool, required
cfg_data.set10()¶
DESCRIPTION
POSARGS
value bool | int, required
Passing numbers was never intended to work, and since 0.62 it has been deprecated. It will be removed in a future version of Meson. If you need to pass numbers use the `.set` method.
cfg_data.set_quoted()¶
DESCRIPTION
POSARGS
value str | int | bool, required
cmake.subproject_options()¶
DESCRIPTION
cmake_options.add_cmake_defines()¶
DESCRIPTION
VARARGS
compiler.alignment()¶
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
prefix str | list[str]
compiler.check_header()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
since 0.47.0
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since
0.50.0
compiler.cmd_array()¶
DESCRIPTION
compiler.compiles()¶
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
DESCRIPTION
POSARGS
If a string is passed, the code is used directly. If a file object is passed, its content is used for the compiler check.
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
name str
no_builtin_args bool, default: false
required bool | feature, default: false, since 1.5.0
werror bool, default: false, since 1.3.0
compiler.compute_int()¶
args:,
dependencies:,
guess:,
high: 1024,
include_directories:,
low: -1024,
no_builtin_args: false,
prefix:,
since 0.40.0
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
guess int
high int, default: 1024
include_directories inc | list[inc], since 0.38.0
low int, default: -1024
no_builtin_args bool, default: false
prefix str | list[str]
compiler.find_library()¶
dirs:,
disabler: false,
has_headers:,
header_args:,
header_dependencies:,
header_include_directories:,
header_no_builtin_args: false,
header_prefix:,
header_required:,
required: true,
static: false,
DESCRIPTION
POSARGS
By default the library is searched for in the system library directory (e.g. /usr/lib). Specifying more directories here, causes Meson to search in those directories as well as the system directories.
disabler bool, default: false, since 0.49.0
has_headers list[str], since 0.50.0
When used, kwargs that compiler.has_header would accept can be passed here prefixed with `header_`, and will have the same effect on the header check.
header_args list[str], since 0.51.0
header_dependencies dep | list[dep], since 0.51.0
header_include_directories inc | list[inc], since
0.51.0
header_no_builtin_args bool, default: false, since
0.51.0
header_prefix str, since 0.51.0
header_required bool | feature, since 0.50.0
required bool | feature, default: true
When set to a `feature`[0] 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 here.
static bool, default: false, since 0.51.0
compiler.first_supported_argument()¶
since 0.43.0
DESCRIPTION
VARARGS
compiler.first_supported_link_argument()¶
since 0.46.0
DESCRIPTION
VARARGS
compiler.get_argument_syntax()¶
since 0.49.0
DESCRIPTION
compiler.get_define()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
since 0.40.0
DESCRIPTION
(since 0.47.0) This method will concatenate string literals as the compiler would. E.g. `"a" "b"` will become `"ab"`.
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
compiler.get_id()¶
DESCRIPTION
compiler.get_linker_id()¶
since 0.53.0
DESCRIPTION
compiler.get_supported_arguments()¶
checked: 'off',
since 0.43.0
DESCRIPTION
VARARGS
- `'off'`: Quietly ignore unsupported arguments
- `'warn'`: Print a warning for unsupported arguments
- `'require'`: Abort if at least one argument is not supported
compiler.get_supported_function_attributes()¶
since 0.48.0
DESCRIPTION
VARARGS
compiler.get_supported_link_arguments()¶
since 0.46.0
DESCRIPTION
VARARGS
compiler.has_argument()¶
DESCRIPTION
POSARGS
compiler.has_define()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
since 1.3.0
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
compiler.has_function()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since 1.3.0
compiler.has_function_attribute()¶
required: false,
since 0.48.0
DESCRIPTION
POSARGS
compiler.has_header()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
This method is faster than compiler.check_header since it only does a pre-processor check.
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since
0.50.0
compiler.has_header_symbol()¶
symbol,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
Symbols here include function, variable, `#define`, type definition, etc.
POSARGS
symbol str, required
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since
0.50.0
compiler.has_link_argument()¶
since 0.46.0
DESCRIPTION
POSARGS
compiler.has_member()¶
membername,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
POSARGS
membername str, required
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since 1.3.0
compiler.has_members()¶
member...,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since 1.3.0
compiler.has_multi_arguments()¶
since 0.37.0
DESCRIPTION
VARARGS
compiler.has_multi_link_arguments()¶
required: false,
since 0.46.0
DESCRIPTION
VARARGS
compiler.has_type()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
required bool | feature, default: false, since 1.3.0
compiler.links()¶
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
DESCRIPTION
Since 0.60.0, if the `file` object's suffix does not match the compiler object's language, the compiler corresponding to the suffix is used to compile the source, while the target of the `links` method is used to link the resulting object file.
POSARGS
If a string is passed, the code is used directly. If a file object is passed, its content is used for the compiler check.
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
name str
no_builtin_args bool, default: false
required bool | feature, default: false, since 1.5.0
werror bool, default: false, since 1.3.0
compiler.preprocess()¶
compile_args:,
dependencies:,
depends:,
include_directories:,
output:,
since 0.64.0
DESCRIPTION
VARARGS
- Strings relative to the current source directory
- file objects defined in any preceding build file
- The return value of configure-time generators such as configure_file
- The return value of build-time generators such as custom_target or
generator.process
dependencies dep | list[dep], since 1.1.0
depends list[build_tgt | custom_tgt], since 1.4.0
include_directories inc | list[inc], since 0.38.0
output str
compiler.run()¶
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
DESCRIPTION
POSARGS
If a string is passed, the code is used directly. If a file object is passed, its content is used for the compiler check.
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
name str
no_builtin_args bool, default: false
required bool | feature, default: false, since 1.5.0
werror bool, default: false, since 1.3.0
compiler.sizeof()¶
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
DESCRIPTION
POSARGS
This is because include directories can also be specified via the `include_directories` or the `dependency` kwarg (if present). The same is also true for passing libraries to link with `-lfoo`.
dependencies dep | list[dep]
include_directories inc | list[inc], since 0.38.0
no_builtin_args bool, default: false
prefix str | list[str]
compiler.symbols_have_underscore_prefix()¶
since 0.37.0
DESCRIPTION
compiler.version()¶
DESCRIPTION
custom_idx.full_path()¶
since 0.54.0
DESCRIPTION
See custom_tgt.full_path
custom_tgt.[index]()¶
DESCRIPTION
custom_tgt.full_path()¶
DESCRIPTION
custom_tgt.to_list()¶
since 0.54.0
DESCRIPTION
dep.as_link_whole()¶
since 0.56.0
DESCRIPTION
dep.as_system()¶
since 0.52.0
DESCRIPTION
OPTARGS
dep.found()¶
DESCRIPTION
dep.get_configtool_variable()¶
deprecated since 0.56.0, since 0.44.0
DESCRIPTION
POSARGS
dep.get_pkgconfig_variable()¶
default:,
define_variable:,
deprecated since 0.56.0, since 0.36.0
DESCRIPTION
POSARGS
define_variable list[str], since 0.44.0
(Since 1.3.0) Multiple variables can be specified in pairs.
dep.get_variable()¶
cmake:,
configtool:,
default_value:,
internal:,
pkgconfig:,
pkgconfig_define:,
since 0.51.0
DESCRIPTION
OPTARGS
configtool str
default_value str
internal str, since 0.54.0
pkgconfig str
pkgconfig_define list[str]
dep.include_type()¶
since 0.52.0
DESCRIPTION
dep.name()¶
since 0.48.0
DESCRIPTION
NOTE: This was not implemented for dep objects returned by compiler.find_library until Meson 1.5.0
dep.partial_dependency()¶
includes: false,
link_args: false,
links: false,
sources: false,
since 0.46.0
DESCRIPTION
If the parent has any dependencies, those will be applied to the new partial dependency with the same rules. So, given:
dep2 = declare_dependency(compile_args : '-Werror=bar', dependencies : dep1)
dep3 = dep2.partial_dependency(compile_args : true)
The following arguments will add the following attributes:
- compile_args: any arguments passed to the compiler
- link_args: any arguments passed to the linker
- links: anything passed via link_with or link_whole
- includes: any include_directories
- sources: any compiled or static sources the dependency has
KWARGS
includes bool, default: false
link_args bool, default: false
links bool, default: false
sources bool, default: false
dep.type_name()¶
DESCRIPTION
dep.version()¶
DESCRIPTION
dict.get()¶
DESCRIPTION
POSARGS
dict.has_key()¶
DESCRIPTION
POSARGS
dict.keys()¶
DESCRIPTION
disabler.found()¶
DESCRIPTION
env.append()¶
DESCRIPTION
POSARGS
env.prepend()¶
DESCRIPTION
POSARGS
env.set()¶
DESCRIPTION
POSARGS
env.unset()¶
since 1.4.0
DESCRIPTION
external_program.found()¶
DESCRIPTION
external_program.full_path()¶
since 0.55.0
DESCRIPTION
NOTE: You should not usually need to use this method. Passing the object itself should work in most contexts where a program can appear, and allows Meson to setup inter-target dependencies correctly (for example in cases where a program might be overridden by a build_tgt). Only use this if you specifically need a string, such as when embedding a program path into a header file, or storing it into an environment variable.
For example:
external_program.path()¶
deprecated since 0.55.0
DESCRIPTION
Returns a string pointing to the script or executable.
NOTE: You should not usually need to use this method. Passing the object itself should work in most contexts where a program can appear, and allows Meson to setup inter-target dependencies correctly (for example in cases where a program might be overridden by a build_tgt). Only use this if you specifically need a string, such as when embedding a program path into a header file, or storing it into an environment variable.
For example:
external_program.version()¶
since 0.62.0
DESCRIPTION
`unknown` if the program cannot determine the version via a `--version` argument.
feature.allowed()¶
since 0.59.0
DESCRIPTION
feature.auto()¶
DESCRIPTION
feature.disable_auto_if()¶
since 0.59.0
DESCRIPTION
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | | Auto | Disabled | Auto | | Enabled | Enabled | Enabled | | Disabled | Disabled | Disabled |
POSARGS
use_bar = get_option('bar')
use_foo = get_option('foo').disable_auto_if(use_bar.enabled())
dep_foo = dependency('foo', required: use_foo)
if not dep_foo.found()
dep_foo = dependency('bar', required: use_bar)
endif
feature.disable_if()¶
since 1.1.0
DESCRIPTION
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | | Auto | Disabled | Auto | | Enabled | Error | Enabled | | Disabled | Disabled | Disabled |
This is equivalent to `feature_opt.require(not condition)`, but may make code easier to reason about, especially when mixed with `enable_if`
POSARGS
.disable_if(host_machine.system() == 'darwin', error_message : 'os feature not supported on MacOS')
dep_os_feature = dependency('os_feature', required: use_os_feature)
feature.disabled()¶
DESCRIPTION
feature.enable_auto_if()¶
since 1.1.0
DESCRIPTION
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | | Auto | Enabled | Auto | | Enabled | Enabled | Enabled | | Disabled | Disabled | Disabled |
POSARGS
feature.enable_if()¶
since 1.1.0
DESCRIPTION
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | | Auto | Enabled | Auto | | Enabled | Enabled | Enabled | | Disabled | Error | Disabled |
POSARGS
dep_llvm = dependency('llvm', required: use_llvm)
feature.enabled()¶
DESCRIPTION
feature.require()¶
since 0.59.0
DESCRIPTION
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | | Auto | Auto | Disabled | | Enabled | Enabled | Error | | Disabled | Disabled | Disabled |
POSARGS
error_message: 'DirectX only available on Windows').allowed() then
src += ['directx.c']
config.set10('HAVE_DIRECTX', true)
endif
file.full_path()¶
since 1.4.0
DESCRIPTION
generator.process()¶
env:,
extra_args:,
preserve_path_from:,
DESCRIPTION
VARARGS
extra_args list[str]
preserve_path_from str, since 0.45.0
int.is_even()¶
DESCRIPTION
int.is_odd()¶
DESCRIPTION
int.to_string()¶
DESCRIPTION
OPTARGS
list.contains()¶
DESCRIPTION
POSARGS
list.get()¶
DESCRIPTION
POSARGS
list.length()¶
DESCRIPTION
meson.add_devenv()¶
since 0.58.0
DESCRIPTION
This is useful for developers who wish to use the project without installing it, it is often needed to set for example the path to plugins directory, etc. Alternatively, a list or dictionary can be passed as first argument.
devenv.set('PLUGINS_PATH', meson.current_build_dir())
meson.add_devenv(devenv)
$ meson devenv -C <builddir>
$ echo $PLUGINS_PATH
/path/to/source/subdir
POSARGS
separator str, since 0.62.0
meson.add_dist_script()¶
since 0.48.0
DESCRIPTION
(since 0.54.0) The `MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT` environment variables are set when dist scripts are run. They are path to the root source and build directory of the main project, even when the script comes from a subproject.
(since 0.58.0) This command can be invoked from a subproject, it was a hard error in earlier versions. Subproject dist scripts will only be executed when running `meson dist --include-subprojects`. `MESON_PROJECT_SOURCE_ROOT`, `MESON_PROJECT_BUILD_ROOT` and `MESON_PROJECT_DIST_ROOT` environment variables are set when dist scripts are run. They are identical to `MESON_SOURCE_ROOT`, `MESON_BUILD_ROOT` and `MESON_DIST_ROOT` for main project scripts, but for subproject scripts they have the path to the root of the subproject appended, usually `subprojects/<subproject-name>`.
(since 1.4.0) The `MESONREWRITE` environment variable contains the path to the rewrite command that corresponds to the `meson` executable that was used to configure the build. (This might be a different path than the first executable found in `PATH`.) It can be used to remove or replace any run_command that depends on the revision control system from the build configuration. Note that the value will contain many parts. For example, it may be `python3 /path/to/meson.py introspect`. The user is responsible for splitting the string to an array if needed by splitting lexically like a UNIX shell would. If your script uses Python, `shlex.split()` is the easiest correct way to do this.
POSARGS
(since 0.55.0) The output of find_program as well as strings are accepted.
(since 0.57.0) file objects and the output of configure_file may be used.
(since 0.55.0) The output of configure_file, files, and find_program as well as strings are accepted.
meson.add_install_script()¶
arg...,
dry_run: false,
install_tag:,
skip_if_destdir: false,
DESCRIPTION
(since 0.54.0) If `meson install` is called with the `--quiet` option, the environment variable `MESON_INSTALL_QUIET` will be set.
(since 1.1.0) If `meson install` is called with the `--dry-run` option, the environment variable `MESON_INSTALL_DRY_RUN` will be set.
Meson uses the `DESTDIR` environment variable as set by the inherited environment to determine the (temporary) installation location for files. Your install script must be aware of this while manipulating and installing files. The correct way to handle this is with the `MESON_INSTALL_DESTDIR_PREFIX` variable which is always set and contains `DESTDIR` (if set) and `prefix` joined together. This is useful because both are usually absolute paths and there are platform-specific edge-cases in joining two absolute paths.
In case it is needed, `MESON_INSTALL_PREFIX` is also always set and has the value of the `prefix` option passed to Meson.
`MESONINTROSPECT` contains the path to the introspect command that corresponds to the `meson` executable that was used to configure the build. (This might be a different path than the first executable found in `PATH`.) It can be used to query build configuration. Note that the value will contain many parts, f.ex., it may be `python3 /path/to/meson.py introspect`. The user is responsible for splitting the string to an array if needed by splitting lexically like a UNIX shell would. If your script uses Python, `shlex.split()` is the easiest correct way to do this.
POSARGS
(since 0.55.0) The output of find_program, executable, custom_target, as well as strings are accepted.
(since 0.57.0) file objects and the output of configure_file may be used.
(since 0.55.0) The output of find_program, executable, custom_target, as well as strings are accepted.
install_tag str, since 0.60.0
skip_if_destdir bool, default: false, since 0.57.0
meson.add_postconf_script()¶
DESCRIPTION
POSARGS
(since 0.55.0) The output of find_program as well as strings are accepted.
(since 0.57.0) file objects and the output of configure_file may be used.
(since 0.55.0) The output of configure_file, files, and find_program as well as strings are accepted.
meson.backend()¶
since 0.37.0
DESCRIPTION
- `ninja`
- `vs2010`
- `vs2012`
- `vs2013`
- `vs2015`
- `vs2017`
- `vs2019`
- `vs2022`
- `xcode`
meson.build_options()¶
since 1.1.0
DESCRIPTION
NOTES
You should use cfg_data.set_quoted to safely escape any embedded quotes prior to storing it into e.g. a C header macro.
The contents returned by this function are the same as the "Build Options:" line reported in `<builddir>/meson-logs/meson-log.txt`.
meson.build_root()¶
deprecated since 0.56.0
DESCRIPTION
meson.can_run_host_binaries()¶
since 0.55.0
DESCRIPTION
meson.current_build_dir()¶
DESCRIPTION
meson.current_source_dir()¶
DESCRIPTION
NOTES
When passing files from the current source directory to a function since that is the default. Also, you can use the files function to refer to files in the current or any other source directory instead of constructing paths manually with meson.current_source_dir.
meson.get_compiler()¶
DESCRIPTION
POSARGS
See our list of supported languages[35].
meson.get_cross_property()¶
deprecated since 0.58.0
DESCRIPTION
This method is replaced by meson.get_external_property.
POSARGS
meson.get_external_property()¶
[fallback_value],
native:,
since 0.54.0
DESCRIPTION
POSARGS
meson.global_build_root()¶
since 0.58.0
DESCRIPTION
meson.global_source_root()¶
since 0.58.0
DESCRIPTION
meson.has_exe_wrapper()¶
deprecated since 0.55.0
DESCRIPTION
meson.has_external_property()¶
since 0.58.0
DESCRIPTION
POSARGS
meson.install_dependency_manifest()¶
DESCRIPTION
If license files are defined as well, they will be copied next to the manifest and referenced in it.
If this function is not used, the builtin option `licensedir` can be used to install the manifest to a given directory with the name `depmf.json`.
POSARGS
meson.is_cross_build()¶
DESCRIPTION
meson.is_subproject()¶
DESCRIPTION
meson.is_unity()¶
DESCRIPTION
meson.override_dependency()¶
dep_object,
native: false,
static:,
since 0.54.0
DESCRIPTION
Doing this in a subproject allows the parent project to retrieve the dependency without having to know the dependency variable name: `dependency(name, fallback : subproject_name)`.
POSARGS
dep_object dep, required
static bool, since 0.60.0
meson.override_find_program()¶
since 0.46.0
DESCRIPTION
(since 0.55.0) If a version check is passed to find_program for a program that has been overridden with an executable, the current project version is used.
POSARGS
program exe | file | external_program,
required
meson.project_build_root()¶
since 0.56.0
DESCRIPTION
meson.project_license()¶
since 0.45.0
DESCRIPTION
meson.project_license_files()¶
since 1.1.0
DESCRIPTION
meson.project_name()¶
DESCRIPTION
meson.project_source_root()¶
since 0.56.0
DESCRIPTION
meson.project_version()¶
DESCRIPTION
meson.source_root()¶
deprecated since 0.56.0
DESCRIPTION
This function will return the source root of the parent project if called from a subproject, which is usually not what you want. Try using meson.current_source_dir or meson.project_source_root. In the rare cases where the root of the main project is needed, use meson.global_source_root that has the same behaviour but with a more explicit name.
NOTES
meson.version()¶
DESCRIPTION
module.found()¶
since 0.59.0
DESCRIPTION
runresult.compiled()¶
DESCRIPTION
runresult.returncode()¶
DESCRIPTION
runresult.stderr()¶
DESCRIPTION
runresult.stdout()¶
DESCRIPTION
str.contains()¶
DESCRIPTION
POSARGS
is_fbsd = target.to_lower().contains('freebsd')
# is_fbsd now has the boolean value 'true'
str.endswith()¶
DESCRIPTION
POSARGS
is_bsd = target.to_lower().endswith('bsd') # boolean value 'true'
str.format()¶
DESCRIPTION
See the Meson syntax entry[38] for more information.
Since 1.3.0 values other than strings, integers, bools, options, dictionaries and lists thereof are deprecated. They were previously printing the internal representation of the raw Python object.
POSARGS
The formatting works by replacing placeholders of type `@number@` with the corresponding varargs.
res = template.format('text', 1, true)
# res now has value 'string: text, number: 1, bool: true'
str.join()¶
DESCRIPTION
VARARGS
Before Meson 0.60.0 this function only accepts a single positional argument of the type list[str].
output = ' '.join(['foo', 'bar'])
# Output value is 'foo bar'
pathsep = ':'
path = pathsep.join(['/usr/bin', '/bin', '/usr/local/bin'])
# path now has the value '/usr/bin:/bin:/usr/local/bin'
str.replace()¶
since 0.58.0
DESCRIPTION
POSARGS
new str, required
s = 'semicolons;as;separators'
s = s.replace('as', 'are')
# 's' now has the value of 'semicolons;are;separators'
str.split()¶
DESCRIPTION
OPTARGS
components = 'a b c d '.split()
# components now has the value ['a', 'b', 'c', 'd']
components = 'a b c d '.split(' ')
# components now has the value ['a', 'b', '', '', 'c', 'd', '']
str.splitlines()¶
since 1.2.0
DESCRIPTION
EXAMPLE
# Output value is ['hello', 'world']
output = ''.splitlines()
# Output value is []
fs = import('fs')
paths = fs.read('my_paths.list').splitlines()
# paths is now the paths listed in 'my_paths.list', or an empty list
# if 'my_paths.list' is empty
str.startswith()¶
DESCRIPTION
POSARGS
is_x86 = target.startswith('x86') # boolean value 'true'
str.strip()¶
DESCRIPTION
By default the characters to remove are spaces and newlines.
OPTARGS
define = ' -Dsomedefine '
stripped_define = define.strip()
# 'stripped_define' now has the value '-Dsomedefine'
str.substring()¶
since 0.56.0
DESCRIPTION
The method accepts negative values where negative `start` is relative to the end of string `len(string) - start` as well as negative `end`.
If `start` or `end` are out of bounds, the position of the closest character will be used. If `start` is bigger than `end`, the result will be an empty substring.
OPTARGS
end int
target = 'x86_FreeBSD'
platform = target.substring(0, 3) # prefix string value 'x86'
system = target.substring(4) # suffix string value 'FreeBSD'
string.substring(-5, -3) # => 'oo'
string.substring(1, -1) # => 'ooba'
string.substring(64) # => ''
string.substring(0, 64) # => 'foobar'
string.substring(64, 0) # => ''
str.to_int()¶
DESCRIPTION
EXAMPLE
# Converts the string to an int and throws an error if it can't be
ver_int = version.to_int()
str.to_lower()¶
DESCRIPTION
EXAMPLE
lower = target.to_lower() # t now has the value 'x86_freebsd'
str.to_upper()¶
DESCRIPTION
EXAMPLE
upper = target.to_upper() # t now has the value 'X86_FREEBSD'
str.underscorify()¶
DESCRIPTION
EXAMPLE
# Replaces all characters other than `a-zA-Z0-9` with `_` (underscore)
# Useful for substituting into #defines, filenames, etc.
underscored = name.underscorify()
# underscored now has the value 'Meson_Docs_txt_Reference_manual'
str.version_compare()¶
DESCRIPTION
POSARGS
# Compare version numbers semantically
is_new = version.version_compare('>=2.0')
# is_new now has the boolean value false
# Supports the following operators: '>', '<', '>=', '<=', '!=', '==', '='
subproject.found()¶
since 0.48.0
DESCRIPTION
subproject.get_variable()¶
DESCRIPTION
If the variable does not exist, the variable `fallback` is returned. If a fallback is not specified, then attempting to read a non-existing variable will cause a fatal error.
POSARGS
OBJECTS¶
alias_tgt¶
returned_by: alias_target
Opaque object returned by alias_target.
any¶
A placeholder representing all types. This includes builtin, as well as returned objects.
bool¶
A boolean object which is either `true` or `false`
both_libs¶
extends: lib
returned_by: both_libraries
Container for both a static and shared library.
build_machine¶
Provides information about the build machine -- the machine that is doing the actual compilation. See Cross-compilation[35].
Currently, these values are populated using `platform.system()`[39] and `platform.machine()`[40]. If you think the returned values for any of these are incorrect for your system or CPU, or if your OS is not in the linked table, please file a bug[41] report with details and we'll look into it.
build_tgt¶
returned_by: build_target, shared_module
extended_by: exe, jar, lib
A build target is either an executable, shared library, static library, both shared and static library or shared module.
cfg_data¶
This object encapsulates configuration values to be used for generating configuration files. A more in-depth description can be found in the the configuration wiki page[9].
cmake¶
The CMake module
cmake_options¶
returned_by: subproject_options
Central configuration object for CMake subprojects
compiler¶
This object is returned by meson.get_compiler. It represents a compiler for a given language and allows you to query its properties.
NOTES
However, with GCC, these variables will be ignored when cross-compiling. In that case you need to use a specs file. See: http://www.mingw.org/wiki/SpecsFileHOWTO
custom_idx¶
References a specific output file of a custom_tgt object.
custom_tgt¶
returned_by: custom_target, vcs_tag
This object is returned by custom_target and contains a target with the following methods:
dep¶
Abstract representation of a dependency
dict¶
Stores a mapping of strings to other objects. See dictionaries[42].
You can also iterate over dictionaries with the `foreach` statement[29].
(since 0.48.0): Dictionaries can be added (e.g. `d1 = d2 + d3` and `d1 += d2`). Values from the second dictionary overrides values from the first. (since 0.62.0): Dictionary order is guaranteed to be insertion order.
disabler¶
A disabler object is an object that behaves in much the same way as NaN numbers do in floating point math. That is when used in any statement (function call, logical op, etc) they will cause the statement evaluation to immediately short circuit to return a disabler object. A disabler object has one method:
env¶
This object is returned by environment and stores detailed information about how environment variables should be set. It should be passed as the `env` keyword argument to tests and other functions.
Since 0.58.0 env.append and env.prepend can be called multiple times on the same `varname`. Earlier Meson versions would warn and only the last operation took effect.
EXAMPLE
# MY_PATH will be '0:1:2:3'
env.set('MY_PATH', '1')
env.append('MY_PATH', '2')
env.append('MY_PATH', '3')
env.prepend('MY_PATH', '0')
exe¶
returned_by: executable, find_program
An executable
external_program¶
Opaque object representing an external program
extracted_obj¶
Opaque object representing extracted object files from build targets
feature¶
returned_by: get_option, disable_auto_if, disable_if, enable_auto_if, enable_if, require
Meson object representing a `feature` options[0]
file¶
Object that stores the path to an existing file
generated_list¶
Opaque object representing the result of a generator.process call.
generator¶
This object is returned by generator and contains a generator that is used to transform files from one type to another by an executable (e.g. `idl` files into source code and headers).
host_machine¶
Provides information about the host machine -- the machine on which the compiled binary will run. See Cross-compilation[35].
It has the same methods as build_machine.
When not cross-compiling, all the methods return the same values as build_machine (because the build machine is the host machine)
Note that while cross-compiling, it simply returns the values defined in the cross-info file.
inc¶
Opaque wrapper for storing include directories
int¶
All integer numbers. See Numbers[43] for more information.
jar¶
returned_by: jar
A Java JAR build target
lib¶
returned_by: library, shared_library, static_library, get_shared_lib, get_static_lib
extended_by: both_libs
Represents either a shared or static library
list¶
An array of elements. See arrays[44].
meson¶
The `meson` object allows you to introspect various properties of the system. This object is always mapped in the `meson` variable.
module¶
Base type for all modules.
Modules provide their own specific implementation methods, but all modules provide the following methods:
range¶
returned_by: range
Opaque object that can be used in a loop and accessed via `[num]`.
run_tgt¶
returned_by: run_target
Opaque object returned by run_target.
runresult¶
This object encapsulates the result of trying to compile and run a sample piece of code with compiler.run or run_command.
str¶
All strings[45] have the following methods. Strings are immutable, all operations return their results as a new string.
structured_src¶
Opaque object returned by structured_sources.
subproject¶
This object is returned by subproject and is an opaque object representing it.
target_machine¶
Provides information about the target machine -- the machine on which the compiled binary's output will run. Hence, this object should only be used while cross-compiling a compiler. See Cross-compilation[35].
It has the same methods as build_machine.
When all compilation is 'native', all the methods return the same values as build_machine (because the build machine is the host machine and the target machine).
Note that while cross-compiling, it simply returns the values defined in the cross-info file. If `target_machine` values are not defined in the cross-info file, `host_machine` values are returned instead.
tgt¶
Opaque base object for all Meson targets
void¶
Indicates that the function does not return anything. Similar to `void` in C and C++
SEE ALSO¶
[1] Build-options.md#features
[2] Unit-tests.md
[3] https://www.testanything.org/
[4] https://ninja-build.org/manual.html#ref_dependencies
[5] https://ninja-build.org/manual.html#ref_headers
[6] https://dlang.org/spec/version.html#version
[7] https://gcc.gnu.org/wiki/Visibility
[8] Rust-module.md#proc_macro
[9]
https://docs.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem
[10] Configuration.md
[11] https://docs.python.org/3/library/codecs.html#standard-encodings
[12] https://ninja-build.org/manual.html#_the_literal_console_literal_pool
[13] Dependencies.md#cmake
[14] Dependencies.md#dependencies-with-custom-lookup-functionality
[15] Wrap-dependency-system-manual.md#provide-section
[16] Dependencies.md#dependencies-with-custom-lookup-functionality
[17] Builtin-options.md#core-options
[18] Machine-files.md#binaries
[19] Build-options.md
[20] Builtin-options.md#universal-options
[21] Installing.md
[22] https://mesonbuild.com/Builtin-options.html
[23] https://spdx.dev/ids/
[24] https://spdx.org/licenses/
[25] External-commands.md
[26] Subprojects.md
[27] http://man7.org/linux/man-pages/man3/mallopt.3.html
[28] Reference-tables.md#cpu-families
[29] Reference-tables.md#operating-system-names
[30] Syntax.md#foreach-statements
[31] Reference-tables.md#compiler-ids
[32] Reference-tables.md#linker-ids
[33] Reference-tables.md#gcc-__attribute__
[34] Commands.md#devenv
[35] Reference-tables.md#language-arguments-parameter-names
[36] Cross-compilation.md
[37] Unity-builds.md
[38] Syntax.md#string-formatting
[39] https://docs.python.org/3.7/library/platform.html#platform.system
[40] https://docs.python.org/3.7/library/platform.html#platform.machine
[41] https://github.com/mesonbuild/meson/issues/new
[42] Syntax.md#dictionaries
[43] Syntax.md#numbers
[44] Syntax.md#arrays
[45] Syntax.md#strings
COPYRIGHT¶
Documentation comes from the meson project (https://mesonbuild.com) and is released under Attribution-ShareAlike 4.0 International (CC BY-SA 4.0). Code samples are released under CC0 1.0 Universal (CC0 1.0).
Meson is a registered trademark of Jussi Pakkanen.
2024-09-27 |