add_global_arguments()SYNOPSISvoid add_global_arguments(
Compiler argument...,
language:,
native: false,
)
DESCRIPTION
Adds global arguments to the compiler command line.
VARARGSCompilerargumentstr, 0...N times
The compiler arguments to add
KWARGSlanguagelist[str], required
Specifies the language(s) that the arguments should be applied to. If a list of languages is given,
the arguments are added to each of the corresponding compiler command lines. Note that there is no
way to remove an argument set in this way. If you have an argument that is only used in a subset of
targets, you have to specify it in per-target flags.
nativebool, default: false, since 0.48.0
A boolean specifying whether the arguments should be applied to the native or cross compilation. If
`true` the arguments will only be used for native compilations. If `false` the arguments will only
be used in cross compilations. If omitted, the flags are added to native compilations if compiling
natively and cross compilations (only) when cross compiling.
NOTES
Usually you should use add_project_arguments instead, because that works even when you project is
used as a subproject. You must pass always arguments individually `arg1, arg2, ...` rather than as a
string `'arg1 arg2', ...`
add_global_link_arguments()SYNOPSISvoid add_global_link_arguments(
Linker argument...,
language:,
native: false,
)
DESCRIPTION
Adds global arguments to the linker command line.
Like add_global_arguments but the arguments are passed to the linker.
VARARGSLinkerargumentstr, 0...N times
The linker arguments to add
KWARGSlanguagelist[str], required
Specifies the language(s) that the arguments should be applied to. If a list of languages is given,
the arguments are added to each of the corresponding compiler command lines. Note that there is no
way to remove an argument set in this way. If you have an argument that is only used in a subset of
targets, you have to specify it in per-target flags.
nativebool, default: false, since 0.48.0
A boolean specifying whether the arguments should be applied to the native or cross compilation. If
`true` the arguments will only be used for native compilations. If `false` the arguments will only
be used in cross compilations. If omitted, the flags are added to native compilations if compiling
natively and cross compilations (only) when cross compiling.
NOTES
Usually you should use add_project_link_arguments instead, because that works even when you project
is used as a subproject. You must pass always arguments individually `arg1, arg2, ...` rather than
as a string `'arg1 arg2', ...`
add_languages()SYNOPSISbool add_languages(Language..., native:, required: true)
DESCRIPTION
Add programming languages used by the project.
This is equivalent to having them in the `project` declaration. This function is usually used to add
languages that are only used under some conditions.
Returns `true` if all languages specified were found and `false` otherwise.
If `native` is omitted, the languages may be used for either build or host machine, but are never
required for the build machine. (i.e. it is equivalent to `add_languages(langs, native: false,
required: required) and add_languages(langs, native: true, required: false)`. This default behaviour
may change to `native: false` in a future Meson version.
VARARGSLanguagestr, 0...N times
The languages to add
KWARGSnativebool, since 0.54.0
If set to `true`, the language will be used to compile for the build machine, if `false`, for the
host machine.
requiredbool|feature, default: true
If set to `true`, Meson will halt if any of the languages specified are not found. (since0.47.0)
The value of a `feature`[1] option can also be passed.
EXAMPLE
project('foobar', 'c')
if compiling_for_osx
add_languages('objc')
endif
if add_languages('cpp', required : false)
executable('cpp-app', 'main.cpp')
endif
# More code...
add_project_arguments()SYNOPSISvoid add_project_arguments(
Compiler argument...,
language:,
native: false,
)
DESCRIPTION
Adds project specific arguments to the compiler command line.
This function behaves in the same way as add_global_arguments except that the arguments are only used
for the current project, they won't be used in any other subproject.
VARARGSCompilerargumentstr, 0...N times
The compiler arguments to add
KWARGSlanguagelist[str], required
Specifies the language(s) that the arguments should be applied to. If a list of languages is given,
the arguments are added to each of the corresponding compiler command lines. Note that there is no
way to remove an argument set in this way. If you have an argument that is only used in a subset of
targets, you have to specify it in per-target flags.
nativebool, default: false, since 0.48.0
A boolean specifying whether the arguments should be applied to the native or cross compilation. If
`true` the arguments will only be used for native compilations. If `false` the arguments will only
be used in cross compilations. If omitted, the flags are added to native compilations if compiling
natively and cross compilations (only) when cross compiling.
NOTES
You must pass always arguments individually `arg1, arg2, ...` rather than as a string `'arg1 arg2',
...`
add_project_dependencies()SYNOPSISvoid add_project_dependencies(
dependencies...,
language:,
native: false,
)
since 0.63.0
DESCRIPTION
Adds arguments to the compiler and linker command line, so that the given set of dependencies is
included in all build products for this project.
VARARGSdependenciesdep, 0...N times
The dependencies to add; if internal dependencies are included, they must not include any built
object.
KWARGSlanguagelist[str], required
Specifies the language(s) that the arguments should be applied to. If a list of languages is given,
the arguments are added to each of the corresponding compiler command lines. Note that there is no
way to remove an argument set in this way. If you have an argument that is only used in a subset of
targets, you have to specify it in per-target flags.
nativebool, default: false, since 0.48.0
A boolean specifying whether the arguments should be applied to the native or cross compilation. If
`true` the arguments will only be used for native compilations. If `false` the arguments will only
be used in cross compilations. If omitted, the flags are added to native compilations if compiling
natively and cross compilations (only) when cross compiling.
add_project_link_arguments()SYNOPSISvoid add_project_link_arguments(
Linker argument...,
language:,
native: false,
)
DESCRIPTION
Adds project specific arguments to the linker command line.
Like add_project_arguments but the arguments are passed to the linker.
VARARGSLinkerargumentstr, 0...N times
The linker arguments to add
KWARGSlanguagelist[str], required
Specifies the language(s) that the arguments should be applied to. If a list of languages is given,
the arguments are added to each of the corresponding compiler command lines. Note that there is no
way to remove an argument set in this way. If you have an argument that is only used in a subset of
targets, you have to specify it in per-target flags.
nativebool, default: false, since 0.48.0
A boolean specifying whether the arguments should be applied to the native or cross compilation. If
`true` the arguments will only be used for native compilations. If `false` the arguments will only
be used in cross compilations. If omitted, the flags are added to native compilations if compiling
natively and cross compilations (only) when cross compiling.
NOTES
You must pass always arguments individually `arg1, arg2, ...` rather than as a string `'arg1 arg2',
...`
add_test_setup()SYNOPSISvoid add_test_setup(
name,
env:,
exclude_suites:,
exe_wrapper:,
gdb: false,
is_default: false,
timeout_multiplier: 1,
)
DESCRIPTION
Add a custom test setup. This setup can be used to run the tests with a custom setup, for example
under Valgrind.
To use the test setup, run `meson test --setup=name` inside the build dir.
Note that all these options are also available while running the `meson test` script for running
tests instead of `ninja test` or `msbuild RUN_TESTS.vcxproj`, etc depending on the backend.
POSARGSnamestr, required
The name of the test setup
KWARGSenvenv|list[str]|dict[str]
environment variables to set , such as `['NAME1=value1', 'NAME2=value2']`, or an env object which
allows more sophisticated environment juggling. (Since0.52.0) A dictionary is also accepted.
exclude_suiteslist[str], since 0.57.0
A list of test suites that should be excluded when using this setup. Suites specified in the
`--suite` option to `meson test` will always run, overriding `add_test_setup` if necessary.
exe_wrapperlist[str|external_program]
The command or script followed by the arguments to it
gdbbool, default: false
If `true`, the tests are also run under `gdb`
is_defaultbool, default: false, since 0.49.0
Set whether this is the default test setup. If `true`, the setup will be used whenever `meson
test` is run without the `--setup` option.
timeout_multiplierint, default: 1
A number to multiply the test timeout with. Since0.57 if timeout_multiplier is `<= 0` the test
has infinite duration, in previous versions of Meson the test would fail with a timeout
immediately.
alias_target()SYNOPSISalias_tgt alias_target(target_name, Dep...)
since 0.52.0
DESCRIPTION
This function creates a new top-level target. Like all top-level targets, this integrates with the
selected backend. For instance, with you can run it as `meson compile target_name`. This is a dummy
target that does not execute any command, but ensures that all dependencies are built. Dependencies
can be any build target. Since 0.60.0, this includes run_tgt.
POSARGStarget_namestr, required
The name of the alias target
VARARGSDeptgt, 1...N times
The targets to depend on
assert()SYNOPSISvoid assert(condition, [message])
DESCRIPTION
Abort with an error message if `condition` evaluates to `false`.
POSARGSconditionbool, required
Abort if this evaluates to `false`
OPTARGSmessagestr
The error message to print.
NOTES
The `message` argument is optional since 0.53.0 and defaults to print the condition statement.
benchmark()SYNOPSISvoid benchmark(
name,
executable,
args:,
depends:,
env:,
priority: 0,
protocol: 'exitcode',
should_fail: false,
suite:,
timeout: 30,
verbose: false,
workdir:,
)
DESCRIPTION
Creates a benchmark item that will be run when the benchmark target is run. The behavior of this
function is identical to test except for:
* benchmark() has no `is_parallel` keyword because benchmarks are not run in parallel
* benchmark() does not automatically add the `MALLOC_PERTURB_` environment variable
Defined benchmarks can be run in a backend-agnostic way by calling `meson test --benchmark` inside
the build dir, or by using backend-specific commands, such as `ninja benchmark` or `msbuild
RUN_TESTS.vcxproj`.
POSARGSnamestr, required
The unique test id
executableexe|jar|external_program|file|custom_tgt|custom_idx, required
The program to execute. (Since1.4.0) A CustomTarget is also accepted.
KWARGSargslist[str|file|build_tgt|custom_tgt|custom_idx]
Arguments to pass to the executable
dependslist[build_tgt|custom_tgt], since 0.46.0
specifies that this test depends on the specified target(s), even though it does not take any of
them as a command line argument. This is meant for cases where test finds those targets internally,
e.g. plugins or globbing. Those targets are built before test is executed even if they have
`build_by_default : false`.
envenv|list[str]|dict[str]
environment variables to set, such as `['NAME1=value1', ´NAME2=value2']`, or an env object which
allows more sophisticated environment juggling. (Since0.52.0) A dictionary is also accepted.
priorityint, default: 0, since 0.52.0
specifies the priority of a test. Tests with a higher priority are started before tests with a
lower priority. The starting order of tests with identical priorities is implementation-defined.
The default priority is 0, negative numbers are permitted.
protocolstr, default: 'exitcode', since 0.50.0
specifies how the test results are parsed and can be one of `exitcode`, `tap`, or `gtest`. For more
information about test harness protocol read UnitTests[2]. The following values are accepted:
- `exitcode`: the executable's exit code is used by the test harness to record the outcome of the
test).
- `tap`: TestAnythingProtocol[3].
- `gtest` (since0.55.0): for Google Tests.
- `rust` (since0.56.0): for native rust tests
should_failbool, default: false
when true the test is considered passed if the executable returns a non-zero return value (i.e.
reports an error)
suitestr|list[str]
`'label'` (or list of labels `['label1', 'label2']`) attached to this test. The suite name is
qualified by a (sub)project name resulting in `(sub)project_name:label`. In the case of a list of
strings, the suite names will be `(sub)project_name:label1`, `(sub)project_name:label2`, etc.
timeoutint, default: 30
the amount of seconds the test is allowed to run, a test that exceeds its time limit is always
considered failed, defaults to 30 seconds. Since0.57 if timeout is `<= 0` the test has infinite
duration, in previous versions of Meson the test would fail with a timeout immediately.
verbosebool, default: false, since 0.62.0
if true, forces the test results to be logged as if `--verbose` was passed to `meson test`.
workdirstr
absolute path that will be used as the working directory for the test
NOTES
Prior to 0.52.0 benchmark would warn that `depends` and `priority` were unsupported, this is
incorrect.
both_libraries()SYNOPSISboth_libs both_libraries(
target_name,
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
Builds both a static and shared library with the given sources. Positional and keyword arguments are
otherwise the same as for library. Source files will be compiled only once and object files will be
reused to build both shared and static libraries, unless `b_staticpic` user option or `pic` argument
are set to false in which case sources will be compiled twice.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
<lang>_shared_argslist[str], since 1.3.0
Arguments that are only passed to a shared library
<lang>_static_argslist[str], since 1.3.0
Arguments that are only passed to a static library
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[6] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
darwin_versionsstr|int|list[str], since 0.48.0
Defines the `compatibility version` and `current version` for the dylib on macOS. If a list is
specified, it must be either zero, one, or two elements. If only one element is specified or if
it's not a list, the specified value will be used for setting both compatibility version and
current version. If unspecified, the `soversion` will be used as per the aforementioned rules.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[7] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
picbool, since 0.36.0
Builds the library as positional independent code (so it can be linked into a shared library). This
option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be
disabled on OS X.
prelinkbool, since 0.57.0
If `true` the object files in the target will be prelinked, meaning that it will contain only one
prelinked object file rather than the individual object files.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "rlib" or
"dylib" crate depending on the library type being build.
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
soversionstr|int
A string or integer specifying the soversion of this shared library, such as `0`. On Linux and
Windows this is used to set the soversion (or equivalent) in the filename. For example, if
`soversion` is `4`, a Windows DLL will be called `foo-4.dll` and one of the aliases of the Linux
shared library would be `libfoo.so.4`. If this is not specified, the first part of `version` is
used instead (see below). For example, if `version` is `3.6.0` and `soversion` is not defined, it
is set to `3`.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
vala_shared_argslist[str|file], since 1.3.0
Arguments that are only passed to a shared library Like `vala_args`, files is allowed in addition
to string
vala_static_argslist[str|file], since 1.3.0
Arguments that are only passed to a static library Like `vala_args`, files is allowed in addition
to string
versionstr
A string specifying the version of this shared library, such as `1.1.0`. On Linux and OS X, this is
used to set the shared library version in the filename, such as `libfoo.so.1.1.0` and
`libfoo.1.1.0.dylib`. If this is not specified, `soversion` is used instead (see above).
vs_module_defsstr|file|custom_tgt|custom_idx
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
(Since1.3.0)custom_idx are supported
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[9] for the full list.
build_target()SYNOPSISbuild_tgt build_target(
target_name,
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
Creates a build target whose type can be set dynamically with the `target_type` keyword argument.
`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:
executable(<arguments and keyword arguments>)
is equivalent to this:
build_target(<arguments and keyword arguments>, target_type : 'executable')
The lists for the kwargs (such as `sources`, `objects`, and `dependencies`) are always flattened,
which means you can freely nest and add lists while creating the final list.
The returned object also has methods that are documented in build_tgt.
*"jar" is deprecated because it is fundementally a different thing than the other build_target types.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
<lang>_shared_argslist[str], since 1.3.0
Arguments that are only passed to a shared library
<lang>_static_argslist[str], since 1.3.0
Arguments that are only passed to a static library
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
darwin_versionsstr|int|list[str], since 0.48.0
Defines the `compatibility version` and `current version` for the dylib on macOS. If a list is
specified, it must be either zero, one, or two elements. If only one element is specified or if
it's not a list, the specified value will be used for setting both compatibility version and
current version. If unspecified, the `soversion` will be used as per the aforementioned rules.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
export_dynamicbool, since 0.45.0
when set to true causes the target's symbols to be
dynamically exported, allowing modules built using the
shared_module function to refer to functions,
variables and other symbols defined in the executable itself. Implies
the `implib` argument.
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implibbool|str, since 0.42.0
When set to true, an import library is generated for the executable (the name of the import library
is based on exe_name). Alternatively, when set to a string, that gives the base name for the
import library. The import library is used when the returned build target object appears in
`link_with:` elsewhere. Only has any effect on platforms where that is meaningful (e.g. Windows).
Implies the `export_dynamic` argument.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
java_resourcesstructured_src, since 0.62.0
Resources to be added to the jar
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
main_classstr
Main class for running the built jar
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
picbool, since 0.36.0
Builds the library as positional independent code (so it can be linked into a shared library). This
option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be
disabled on OS X.
piebool, since 0.49.0
Build a position-independent executable.
prelinkbool, since 0.57.0
If `true` the object files in the target will be prelinked, meaning that it will contain only one
prelinked object file rather than the individual object files.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "rlib" or
"dylib" crate depending on the library type being build.
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
soversionstr|int
A string or integer specifying the soversion of this shared library, such as `0`. On Linux and
Windows this is used to set the soversion (or equivalent) in the filename. For example, if
`soversion` is `4`, a Windows DLL will be called `foo-4.dll` and one of the aliases of the Linux
shared library would be `libfoo.so.4`. If this is not specified, the first part of `version` is
used instead (see below). For example, if `version` is `3.6.0` and `soversion` is not defined, it
is set to `3`.
target_typestr
The actual target type to build
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
vala_shared_argslist[str|file], since 1.3.0
Arguments that are only passed to a shared library Like `vala_args`, files is allowed in addition
to string
vala_static_argslist[str|file], since 1.3.0
Arguments that are only passed to a static library Like `vala_args`, files is allowed in addition
to string
versionstr
A string specifying the version of this shared library, such as `1.1.0`. On Linux and OS X, this is
used to set the shared library version in the filename, such as `libfoo.so.1.1.0` and
`libfoo.1.1.0.dylib`. If this is not specified, `soversion` is used instead (see above).
vs_module_defsstr|file|custom_tgt|custom_idx, since 1.3.0
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
This can be used to expose which functions a shared_module loaded by an executable will be allowed
to use.
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
configuration_data()SYNOPSIScfg_data configuration_data([data])
DESCRIPTION
Creates an empty configuration object. You should add your configuration with the cfg_data method
calls and finally use it in a call to configure_file.
OPTARGSdatadict[str|bool|int], since 0.49.0
Optional dictionary to specify an initial data set. If provided, each key/value pair is added into
the cfg_data object as if the cfg_data.set method was called for each of them.
configure_file()SYNOPSISfile configure_file(
capture: false,
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
This function can run in three modes depending on the keyword arguments passed to it.
When a cfg_data object is passed to the `configuration:` keyword argument, it takes a template file
as the `input:` (optional) and produces the `output:` (required) by substituting values from the
configuration data as detailed in theconfigurationfiledocumentation[10]. (since0.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.
(since0.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.
KWARGScapturebool, default: false, since 0.41.0
When this argument is set to true, Meson captures `stdout` of the `command` and writes it to the
target file specified as `output`.
commandlist[str|file|compiler|external_program|exe]
As explained above, if specified, Meson does not create the file itself but rather runs the
specified command, which allows you to do fully custom file generation. (since0.52.0) The command
can contain file objects and more than one file can be passed to the `input` keyword argument, see
custom_target for details about string substitutions.
configurationcfg_data|dict[str|int|bool]
As explained above, when passed this will provide the replacement data for the input file (if
provided) or key value pairs to be written to the output.
copybool, default: false, since 0.47.0
As explained above, if specified Meson only copies the file from input to output.
depfilestr, since 0.52.0
A dependency file that the command can write listing all the additional files this target depends
on. A change in any one of these files triggers a reconfiguration.
encodingstr, default: 'utf-8', since 0.47.0
Set the file encoding for the input and output file. The supported encodings are those of python3,
see standard-encodings[11].
formatstr, default: 'meson', since 0.46.0
The format of defines. It defaults to `'meson'`, and so substitutes `#mesondefine` statements and
variables surrounded by `@` characters, you can also use `'cmake'` to replace `#cmakedefine`
statements and variables with the `${variable}` syntax. Finally you can use `'cmake@'` in which
case substitutions will apply on `#cmakedefine` statements and variables with the `@variable@`
syntax.
inputstr|file
The input file name. If it's not specified in configuration mode, all the variables in the
`configuration:` object (see above) are written to the `output:` file.
installbool, default: false, since 0.50.0
When true, this generated file is installed during the install step, and `install_dir` must be set
and not empty. When false, this generated file is not installed regardless of the value of
`install_dir`. When omitted it defaults to true when `install_dir` is set and not empty, false
otherwise.
install_dirstr|bool
The subdirectory to install the generated file to (e.g. `share/myproject`), if omitted or given the
value of empty string, the file is not installed.
install_modelist[str|int|bool], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default the file has no install tag which means it is not being installed when `--tags` argument is
specified.
macro_namestr, since 1.3.0
When specified, macro guards will be used instead of '#pragma once'. The macro guard name will be
the specified name.
outputstr
The output file name. (since0.41.0) may contain `@PLAINNAME@` or `@BASENAME@` substitutions, as
well as (since1.5.0) their indexed versions, like `@PLAINNAME0@` or `@BASENAME0@`. In
configuration mode, the permissions of the input file (if it is specified) are copied to the output
file.
output_formatstr, since 0.47.0
The format of the output to generate when no input was specified. It defaults to `c`, in which case
preprocessor directives will be prefixed with `#`, you can also use `nasm`, in which case the
prefix will be `%`. (since1.3.0) `json` format can also be used.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.62 -- 1.1.0.
custom_target()SYNOPSIScustom_tgt custom_target(
[name],
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
Create a custom top level build target. The only positional argument is the name of this target and
cannot contain path separators (`/` or ``). The name of custom target might not be used by every
backends, for instance with the Ninja backend, `subdir/meson.build` containing the example below,
`ninja -C builddir foo` or `ninja -C builddir subdir/foo` won't work, it is instead `ninja -C
builddir subdir/file.txt`. However, `meson compile subdir/foo` is accepted.
custom_target('foo', output: 'file.txt', ...)
Since0.60.0 the name argument is optional and defaults to the basename of the first output
(`file.txt` in the example above).
The list of strings passed to the `command` keyword argument accept the following special string
substitutions:
- `@INPUT@`: the full path to the input passed to `input`. If more than one input is specified, all
of them will be substituted as separate arguments only if the command uses `'@INPUT@'` as a
standalone-argument. For instance, this would not work: `command : ['cp', './@INPUT@']`, but this
would: `command : ['cp', '@INPUT@']`.
- `@OUTPUT@`: the full path to the output passed to `output`. If more than one outputs are specified,
the behavior is the same as `@INPUT@`.
- `@INPUT0@` `@INPUT1@` `...`: the full path to the input with the specified array index in `input`
- `@OUTPUT0@` `@OUTPUT1@` `...`: the full path to the output with the specified array index in
`output`
- `@OUTDIR@`: the full path to the directory where the output(s) must be written
- `@DEPFILE@`: the full path to the dependency file passed to `depfile`
- `@PLAINNAME@`: the input filename, without a path
- `@PLAINNAME0@` `@PLAINNAME1@` `...` (since1.5.0): the input filename without a path, with the
specified array index in `input`
- `@BASENAME@`: the input filename, with extension removed
- `@BASENAME0@` `@BASENAME1@` `...` (since1.5.0): the input filename with extension removed, with
the specified array index in `input`
- `@PRIVATE_DIR@` (since0.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.
(since0.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.
OPTARGSnamestr
The unique id of the custom target
This posarg is optional since0.60.0. It defaults to the basename of the first output.
KWARGSbuild_alwaysbool, deprecated since 0.47.0
If `true` this target is always considered out of date and is rebuilt every time. Equivalent to
setting both `build_always_stale` and `build_by_default` to true.
build_always_stalebool, default: false, since 0.47.0
If `true` the target is always considered out of date. Useful for things such as build timestamps
or revision control tags. The associated command is run even if the outputs are up to date.
build_by_defaultbool, since 0.38.0
Causes, when set to true, to have this target be built by default. This means it will be built when
`meson compile` is called without any arguments. The default value is `false`.
(since0.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.
capturebool, default: false
There are some compilers that can't be told to write their output to a file but instead write it to
standard output. When this argument is set to true, Meson captures `stdout` and writes it to the
target file. Note that your command argument list may not contain `@OUTPUT@` when capture mode is
active.
commandlist[str|file|exe|external_program|custom_tgt|build_tgt|custom_idx]
Command to run to create outputs from inputs. The command may be strings or the return value of
functions that return file-like objects such as find_program, executable, configure_file, files,
custom_target, etc. Meson will automatically insert the appropriate dependencies on targets and
files listed in this keyword argument. Note: always specify commands in array form
`['commandname', ´-arg1', '-arg2']` rather than as a string `'commandname -arg1 -arg2'` as the
latter will not work.
consolebool, since 0.48.0
Keyword argument conflicts with `capture`, and is meant for commands that are resource-intensive
and take a long time to finish. With the Ninja backend, setting this will add this target to
Ninja's`console`pool[12], which has special properties such as not buffering stdout and
serializing all targets in this pool.
depend_fileslist[str|file]
files (str, file, or the return value of configure_file that this target depends on but are not
listed in the `command` keyword argument. Useful for adding regen dependencies.
dependslist[build_tgt|custom_tgt|custom_idx]
Specifies that this target depends on the specified target(s), even though it does not take any of
them as a command line argument. This is meant for cases where you have a tool that e.g. does
globbing internally. Usually you should just put the generated sources as inputs and Meson will set
up all dependencies automatically (custom_idx was unavailable as a type between 0.60 and 1.4.0).
depfilestr
A dependency file that the command can write listing all the additional files this target depends
on, for example a C compiler would list all the header files it included, and a change in any one
of these files triggers a recompilation.
(since0.47.0) the `@BASENAME@` and `@PLAINNAME@` substitutions are also accepted.
envenv|list[str]|dict[str], since 0.57.0
environment variables to set, such as `{'NAME1': 'value1', 'NAME2': 'value2'}` or `['NAME1=value1',
'NAME2=value2']`, or an env object which allows more sophisticated environment juggling.
feedbool, default: false, since 0.59.0
There are some compilers that can't be told to read their input from a file and instead read it
from standard input. When this argument is set to `true`, Meson feeds the input file to `stdin`.
Note that your argument list may not contain `@INPUT@` when feed mode is active.
inputlist[str|file|build_tgt|custom_idx|custom_tgt|external_program|extracted_obj|generated_list]
List of source files. (since0.41.0) the list is flattened.
installbool
When true, one or more files of this target are installed during the install step (see
`install_dir` for details).
install_dirbool|str|list[bool|str]
If only one install_dir is provided, all outputs are installed there. Since0.40.0 Allows you to
specify the installation directory for each corresponding output. For example:
custom_target('different-install-dirs',
output : ['first.file', 'second.file'],
install : true,
install_dir : ['somedir', 'otherdir'])
This would install `first.file` to `somedir` and `second.file` to `otherdir`.
To only install some outputs, pass `false` for the outputs that you don't want installed. For
example:
custom_target('only-install-second',
output : ['first.file', 'second.file'],
install : true,
install_dir : [false, 'otherdir'])
This would install `second.file` to `otherdir` and not install `first.file`.
install_modelist[str|int|bool], since 0.47.0
The file mode and optionally the owner/uid and group/gid. See the `install_mode` kwarg of
install_data for more information.
install_taglist[str|bool], since 0.60.0
A list of strings, one per output, used by the `meson install --tags` command to install only a
subset of the files.
By default all outputs have no install tag which means they are not being installed when `--tags`
argument is specified. If only one tag is specified, it is assumed that all outputs have the same
tag. `false` can be used for outputs that have no tag or are not installed.
outputlist[str]
List of output files.
NOTES
Assuming that `command:` is executed by a POSIX `sh` shell is not portable, notably to Windows.
Instead, consider using a `native: true` executable, or a python script.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.60.0 -- 1.1.0.
debug()SYNOPSISvoid debug(message, msg...)
since 0.63.0
DESCRIPTION
Write the argument string to the meson build log.
POSARGSmessagestr|int|bool|list[str|int|bool]|dict[str|int|bool], required
The message to print
VARARGSmsgstr|int|bool|list[str|int|bool]|dict[str|int|bool], 0...N times
Additional parameters will be separated by spaces
declare_dependency()SYNOPSISdep declare_dependency(
compile_args:,
d_import_dirs:,
d_module_versions:,
dependencies:,
extra_files:,
include_directories:,
link_args:,
link_whole:,
link_with:,
objects:,
sources:,
variables:,
version:,
)
DESCRIPTION
This function returns a dep object that behaves like the return value of dependency but is internal
to the current build. The main use case for this is in subprojects. This allows a subproject to
easily specify how it should be used. This makes it interchangeable with the same dependency that is
provided externally by the system.
KWARGScompile_argslist[str]
Compile arguments to use.
d_import_dirslist[inc|str], since 0.62.0
the directories to add to the string search path (i.e. `-J` switch for DMD). Must be inc objects
or plain strings.
d_module_versionsstr|int|list[str|int], since 0.62.0
The Dversionidentifiers[5] to add during the compilation of D source files.
dependencieslist[dep]
Other dependencies needed to use this dependency.
extra_fileslist[str|file], since 1.2.0
extra files to add to targets. mostly used for IDE integration.
include_directorieslist[inc|str]
the directories to add to header search path, must be inc objects or (since0.50.0) plain strings.
link_argslist[str]
Link arguments to use.
link_wholelist[lib], since 0.46.0
Libraries to link fully, same as executable.
link_withlist[lib]
Libraries to link against.
objectslist[extracted_obj], since 1.1.0
a list of object files, to be linked directly into the targets that use the dependency.
sourceslist[str|file|custom_tgt|custom_idx|generated_list]
sources to add to targets (or generated header files that should be built before sources including
them are built)
variablesdict[str]|list[str], since 0.54.0
a dictionary of arbitrary strings, this is meant to be used in subprojects where special variables
would be provided via cmake or pkg-config. since0.56.0 it can also be a list of `'key=value'`
strings.
versionstr
the version of this dependency, such as `1.2.3`. Defaults to the project version.
dependency()SYNOPSISdep dependency(
names...,
allow_fallback:,
default_options:,
disabler: false,
fallback:,
include_type: 'preserve',
language:,
method: 'auto',
native: false,
not_found_message:,
required: true,
static: false,
version:,
)
DESCRIPTION
Finds an external dependency (usually a library installed on your system) with the given name with
`pkg-config` and withCMake[13] if `pkg-config` fails. Additionally, frameworks (OSX only) and
library-specificfallbackdetectionlogic[14] are also supported.
Since0.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, since0.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 Wrapdocumentation[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.
VARARGSnamesstr, 1...N times, since 0.60.0
The names of the dependency to look up. The dependencies are looked up in the order they are
provided here. The first found dependency will then be used. The fallback subproject will be used
only if none of the names are found on the system. Once one of the name has been found, all other
names are added into the cache so subsequent calls for any of those name will return the same
value. This is useful in case a dependency could have different names, such as `png` and `libpng`.
NOTE: Before 0.60.0 only a single dependency name was allowed.
KWARGSallow_fallbackbool, since 0.56.0
Specifies whether Meson should automatically pick a fallback subproject in case the dependency is
not found in the system. If `true` and the dependency is not found on the system, Meson will
fallback to a subproject that provides this dependency. If `false`, Meson will not fallback even if
a subproject provides this dependency. By default, Meson will do so if `required` is `true` or
`enabled`[0]; see the Wrapdocumentation[14] for more details.
default_optionslist[str]|dict[str|bool|int|list[str]], since 0.38.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) (since1.2.0): A dictionary may
now be passed.
disablerbool, default: false, since 0.49.0
Returns a disabler object instead of a not-found dependency if this kwarg is set to `true` and the
dependency couldn't be found.
fallbacklist[str]|str
Manually specifies a subproject fallback to use in case the dependency is not found in the system.
This is useful if the automatic search is not applicable or if you want to support versions of
Meson older than 0.55.0. If the value is an array `['subproj_name', 'subproj_dep']`, the first
value is the name of the subproject and the second is the variable name in that subproject that
contains a dependency object such as the return value of declare_dependency or dependency, etc.
Note that this means the fallback dependency may be a not-found dependency, in which case the value
of the `required:` kwarg will be obeyed. Since0.54.0 the value can be a single string, the
subproject name; in this case the subproject must use `meson.override_dependency('dependency_name',
subproj_dep)` to specify the dependency object used in the superproject. If the value is an empty
list, it has the same effect as `allow_fallback: false`.
include_typestr, default: 'preserve', since 0.52.0
An enum flag, marking how the dependency flags should be converted. Supported values are
`'preserve'`, `'system'` and `'non-system'`. System dependencies may be handled differently on some
platforms, for instance, using `-isystem` instead of `-I`, where possible. If `include_type` is
set to `'preserve'`, no additional conversion will be performed.
languagestr, since 0.42.0
Defines what language-specific dependency to find if it's available for multiple languages.
methodstr, default: 'auto', since 0.40.0
Defines the way the dependency is detected, the default is `auto` but can be overridden to be e.g.
`qmake` for Qt development, and differentdependenciessupportdifferentvalues[16] for this
(though `auto` will work on all of them)
nativebool, default: false
If set to `true`, causes Meson to find the dependency on the build machine system rather than the
host system (i.e. where the cross compiled binary will run on), usually only needed if you build a
tool to be used during compilation.
not_found_messagestr, since 0.50.0
An optional string that will be printed as a message if the dependency was not found.
requiredbool|feature, default: true
When set to `false`, Meson will proceed with the build even if the dependency is not found.
When set to a `feature`[0] option, the feature will control if it is searched and whether to fail
if not found.
(since0.47.0) The value of a `feature` option can also be passed.
staticbool, default: false
Tells the dependency provider to try to get static libraries instead of dynamic ones (note that
this is not supported by all dependency backends)
Since0.60.0 it also sets `default_library` option accordingly on the fallback subproject if it was
not set explicitly in `default_options` keyword argument.
versionlist[str]|str, since 0.37.0
Specifies the required version, a string containing a comparison operator followed by the version
string, examples include `>1.0.0`, `<=2.3.5` or `3.1.4` for exact matching. You can also specify
multiple restrictions by passing a list to this keyword argument, such as: `['>=3.14.0',
'<=4.1.0']`. These requirements are never met if the version is unknown.
NOTES
This function supports additional library-specific[13] keyword arguments that may also be accepted
(e.g. `modules` specifies submodules to use for dependencies such as Qt5 or Boost. `components`
allows the user to manually add CMake `COMPONENTS` for the `find_package` lookup)
disabler()SYNOPSISdisabler disabler()
since 0.44.0
DESCRIPTION
Returns a disabler object.
environment()SYNOPSISenv environment([env], method:, separator:)
since 0.35.0
DESCRIPTION
Returns an empty env object.
OPTARGSenvstr|list[str]|dict[str]|dict[list[str]], since 0.52.0
If provided, each key/value pair is added into the env object as if env.set method was called for
each of them. Since 0.62.0 list of strings is allowed in dictionary values. In that case values
are joined using the separator.
KWARGSmethodstr, since 0.62.0
Must be one of 'set', 'prepend', or 'append' (defaults to 'set'). Controls if initial values
defined in the first positional argument are prepended, appended or replace the current value of
the environment variable.
separatorstr, since 0.62.0
The separator to use for the initial values defined in the first positional argument. If not
explicitly specified, the default path separator for the host operating system will be used, i.e.
';' for Windows and ':' for UNIX/POSIX systems.
error()SYNOPSISvoid error(message, msg...)
DESCRIPTION
Print the argument string and halts the build process.
POSARGSmessagestr, required
The message to print
VARARGSmsgstr, 0...N times, since 0.58.0
Additional parameters will be separated by spaces
executable()SYNOPSISexe executable(
target_name,
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
Creates a new executable. The first argument specifies its name and the remaining positional
arguments define the input files to use.
The lists for the kwargs (such as `sources`, `objects`, and `dependencies`) are always flattened,
which means you can freely nest and add lists while creating the final list.
The returned object also has methods that are documented in exe.
Since1.3.0 executable names can be the same across multiple targets as long as they each have a
different `name_suffix`.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
export_dynamicbool, since 0.45.0
when set to true causes the target's symbols to be
dynamically exported, allowing modules built using the
shared_module function to refer to functions,
variables and other symbols defined in the executable itself. Implies
the `implib` argument.
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implibbool|str, since 0.42.0
When set to true, an import library is generated for the executable (the name of the import library
is based on exe_name). Alternatively, when set to a string, that gives the base name for the
import library. The import library is used when the returned build target object appears in
`link_with:` elsewhere. Only has any effect on platforms where that is meaningful (e.g. Windows).
Implies the `export_dynamic` argument.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
piebool, since 0.49.0
Build a position-independent executable.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
vs_module_defsstr|file|custom_tgt|custom_idx, since 1.3.0
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
This can be used to expose which functions a shared_module loaded by an executable will be allowed
to use.
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
WARNINGS
The `link_language` kwarg was broken until 0.55.0
files()SYNOPSISlist[file] files(file...)
DESCRIPTION
This command takes the strings given to it in arguments and returns corresponding File objects that
you can use as sources for build targets. The difference is that file objects remember the
subdirectory they were defined in and can be used anywhere in the source tree.
VARARGSfilestr, 0...N times
Path to the file.
EXAMPLE
As an example suppose you have source file `foo.cpp` in subdirectory `bar1` and you would like to use
it in a build target that is defined in `bar2`. To make this happen you first create the object in
`bar1` like this:
foofile = files('foo.cpp')
Then you can use it in `bar2` like this:
executable('myprog', 'myprog.cpp', foofile, ...)
Meson will then do the right thing.
find_program()SYNOPSISexternal_program|exe find_program(
program_name,
fallback...,
default_options:,
dirs:,
disabler: false,
native: false,
required: true,
version:,
version_argument:,
)
DESCRIPTION
`program_name` here is a string that can be an executable or script to be searched for in `PATH` or
other places inside the project. The search order is:
1. Program overrides set via meson.override_find_program 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 mustnot manually add
the interpreter while using this script as part of a list of commands. Since 0.50.0 if the "python3"
program is requested and it is not found in the system, Meson will return its current interpreter.
If you need to check for a program in a non-standard location, you can just pass an absolute path to
`find_program`, e.g.
setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
It is also possible to pass an array to `find_program` in case you need to construct the set of paths
to search on the fly:
setcap = find_program(['setcap', '/usr/sbin/setcap', '/sbin/setcap'], required : false)
Since1.2.0 `find_program('meson')` is automatically overridden to the Meson command used to execute
the build script.
The returned external_program object also has documented methods.
POSARGSprogram_namestr|file, required
The name of the program to search, or a file object to be used without searching.
VARARGSfallbackstr|file, 0...N times, since 0.37.0
These parameters are used as fallback names to search for. This is meant to be used for cases
where the program may have many alternative names, such as `foo` and `foo.py`. The function will
check for the arguments one by one and the first one that is found is returned.
KWARGSdefault_optionslist[str]|dict[str|bool|int|list[str]], since 1.3.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)
dirslist[str], since 0.53.0
extra list of absolute paths where to look for program names.
disablerbool, default: false, since 0.49.0
If `true` and the program couldn't be found, return a disabler object instead of a not-found
object.
nativebool, default: false, since 0.43.0
Defines how this executable should be searched. By default it is set to `false`, which causes Meson
to first look for the executable in the cross file (when cross building) and if it is not defined
there, then from the system. If set to `true`, the cross file is ignored and the program is only
searched from the system.
requiredbool|feature, default: true
When `true`, Meson will abort if no program can be found. If `required` is set to `false`, Meson
continue even if none of the programs can be found. You can then use the `.found()` method on the
returned external_program to check whether it was found or not. (since0.47.0) The value of a
`feature`[0] option can also be passed to the `required` keyword argument.
versionlist[str], since 0.52.0
Specifies the required version, see dependency for argument format. By default, the version of the
program is determined by running `program_name --version` command. If stdout is empty it fallbacks
to stderr. If the output contains more text than simply a version number, only the first occurrence
of numbers separated by dots is kept. If the output is more complicated than that, the version
checking will have to be done manually using run_command.
version_argumentstr, since 1.5.0
Specifies the argument to pass when trying to find the version of the program. If this is
unspecified, `program_name --version` will be used.
generator()SYNOPSISgenerator generator(
exe,
arguments:,
capture: false,
depends:,
depfile:,
output:,
)
DESCRIPTION
See also: custom_target
This function creates a generator object that can be used to run custom compilation commands. The
only positional argument is the executable to use. It can either be a self-built executable or one
returned by find_program.
The template strings passed to all the keyword arguments accept the following special substitutions:
- `@PLAINNAME@`: the complete input file name, e.g: `foo.c` becomes `foo.c` (unchanged)
- `@BASENAME@`: the base of the input filename, e.g.: `foo.c.y` becomes `foo.c` (extension is
removed)
Each string passed to the `output` keyword argument must be constructed using one or both of these
two substitutions.
In addition to the above substitutions, the `arguments` keyword argument also accepts the following:
- `@OUTPUT@`: the full path to the output file
- `@INPUT@`: the full path to the input file
- `@DEPFILE@`: the full path to the depfile
- `@SOURCE_DIR@`: the full path to the root of the source tree
- `@CURRENT_SOURCE_DIR@`: this is the directory where the currently processed meson.build is located
in
- `@BUILD_DIR@`: the full path to the root of the build dir where the output will be placed
NOTE: Generators should only be used for outputs that will only be used as inputs for a build_target
or a custom_target. When you use the processed output of a generator in multiple targets, the
generator will be run multiple times to create outputs for each target. Each output will be created
in a target-private directory `@BUILD_DIR@`.
If you want to generate files for general purposes such as for generating headers to be used by
several sources, or data that will be installed, and so on, use a custom_target instead.
POSARGSexeexe|external_program, required
Executable for the command to run
KWARGSargumentslist[str]
A list of template strings that will be the command line arguments passed to the executable.
capturebool, default: false, since 0.43.0
When this argument is set to true, Meson captures `stdout` of the `executable` and writes it to the
target file specified as `output`.
dependslist[build_tgt|custom_tgt|custom_idx], since 0.51.0
An array of build targets that must be built before this generator can be run. This is used if you
have a generator that calls a second executable that is built in this project (custom_idx was not
available between 0.60 and 1.4.0).
depfilestr
A template string pointing to a dependency file that a generator can write listing all the
additional files this target depends on, for example a C compiler would list all the header files
it included, and a change in any one of these files triggers a recompilation,
outputlist[str]
Template string (or list of template strings) defining how an output file name is (or multiple
output names are) generated from a single source file name.
get_option()SYNOPSISstr|int|bool|feature|list[str|int|bool] get_option(
option_name,
)
DESCRIPTION
Obtains the value of the projectbuildoption[19] specified in the positional argument.
Note that the value returned for built-in options that end in `dir` such as `bindir` and `libdir` is
usually a path relative to (and inside) the `prefix` but you should not rely on that, as it can also
be an absolute path insomecases[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.
POSARGSoption_namestr, required
Name of the option to query
get_variable()SYNOPSISany get_variable(variable_name, [default])
DESCRIPTION
This function can be used to dynamically obtain a variable. `res = get_variable(varname, fallback)`
takes the value of `varname` (which must be a string) and stores the variable of that name into
`res`. If the variable does not exist, the variable `fallback` is stored to `res`instead. If a
fallback is not specified, then attempting to read a non-existing variable will cause a fatal error.
POSARGSvariable_namestr, required
Name of the variable to get
OPTARGSdefaultany
Fallback value to return when the variable does not exist
import()SYNOPSISmodule import(module_name, disabler:, required: true)
DESCRIPTION
Imports the given extension module. Returns an object that can be used to call the methods of the
module. Here's an example for a hypothetical `testmod` module.
POSARGSmodule_namestr, required
Name of the module to import.
KWARGSdisablerbool, since 0.59.0
Returns a disabler object when not found.
requiredbool|feature, default: true, since 0.59.0
When set to `false`, Meson will proceed with the build even if the module is not found. When set
to a `feature`[0] option, the feature will control if it is searched and whether to fail if not
found.
EXAMPLE
tmod = import('testmod')
tmod.do_something()
include_directories()SYNOPSISinc include_directories(includes..., is_system: false)
DESCRIPTION
Returns an opaque object which contains the directories (relative to the current directory) given in
the positional arguments. The result can then be passed to the `include_directories:` keyword
argument when building executables or libraries. You can use the returned object in any subdirectory
you want, Meson will make the paths work automatically.
Note that this function call itself does not add the directories into the search path, since there is
no global search path. For something like that, see `add_project_arguments()`.
See also `implicit_include_directories` parameter of executable, which adds current source and build
directories to include path.
Each directory given is converted to two include paths: one that is relative to the source root and
one relative to the build root.
VARARGSincludesstr, 0...N times
Include paths to add.
KWARGSis_systembool, default: false
If set to `true`, flags the specified directories as system directories. This means that they will
be used with the `-isystem` compiler argument rather than `-I` on compilers that support this flag
(in practice everything except Visual Studio).
EXAMPLE
For example, with the following source tree layout in `/home/user/project.git`:
`meson.build`:
project(...)
subdir('include')
subdir('src')
`include/meson.build`:
inc = include_directories('.')
`src/meson.build`:
sources = [...]
executable('some-tool', sources,
include_directories : inc,
...)
If the build tree is `/tmp/build-tree`, the following include paths will be added to the
`executable()` call: `-I/tmp/build-tree/include -I/home/user/project.git/include`.
install_data()SYNOPSISvoid install_data(
file...,
follow_symlinks: true,
install_dir:,
install_mode:,
install_tag:,
preserve_path: false,
rename:,
sources:,
)
DESCRIPTION
Installs files from the source tree that are listed as positional arguments.
See Installing[20] for more examples.
VARARGSfilefile|str, 0...N times
Files to install.
KWARGSfollow_symlinksbool, default: true, since 1.3.0
If true, dereferences links and copies their target instead. The default value will become false
in the future.
install_dirstr
The absolute or relative path to the installation directory. If this is a relative path, it is
assumed to be relative to the prefix.
If omitted, the directory defaults to `{datadir}/{projectname}` (since0.45.0).
install_modelist[str|int|bool], since 0.38.0
specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files. For example:
`install_mode: 'rw-r--r--'` for just the file mode
`install_mode: ['rw-r--r--', 'nobody', 'nogroup']` for the file mode and the user/group
`install_mode: ['rw-r-----', 0, 0]` for the file mode and uid/gid
To leave any of these three as the default, specify `false`.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default these files have no install tag which means they are not being installed when `--tags`
argument is specified.
preserve_pathbool, default: false, since 0.64.0
Disable stripping child-directories from data files when installing.
This is equivalent to GNU Automake's `nobase` option.
renamelist[str], since 0.46.0
If specified renames each source file into corresponding file from `rename` list. Nested paths are
allowed and they are joined with `install_dir`. Length of `rename` list must be equal to the number
of sources.
sourceslist[file|str]
Additional files to install.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.59.0 -- 1.1.0. an omitted `install_dir`
kwarg did not work correctly inside of a subproject until 1.3.0. an omitted `install_dir` kwarg did
not work correctly when combined with the `preserve_path` kwarg untill 1.3.0.
install_emptydir()SYNOPSISvoid install_emptydir(dirpath..., install_mode:, install_tag:)
since 0.60.0
DESCRIPTION
Installs a new directory entry to the location specified by the positional argument. If the directory
exists and is not empty, the contents are left in place.
VARARGSdirpathstr, 0...N times
Directory to create during installation.
KWARGSinstall_modelist[str|int|bool]
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the created
directory.
See the `install_mode` kwarg of install_data for more information.
install_tagstr
A string used by the `meson install --tags` command to install only a subset of the files. By
default this directory has no install tag which means it is not installed when the `--tags`
argument is specified.
WARNINGS
the `install_mode` kwarg ignored integer values before 1.1.0.
install_headers()SYNOPSISvoid install_headers(
file...,
follow_symlinks: true,
install_dir:,
install_mode:,
preserve_path: false,
subdir:,
)
DESCRIPTION
Installs the specified header files from the source tree into the system header directory (usually
`/{prefix}/include`) during the install step. This directory can be overridden by specifying it with
the `install_dir` keyword argument. If you just want to install into a subdirectory of the system
header directory, then use the `subdir` argument. As an example if this has the value `myproj` then
the headers would be installed to `/{prefix}/include/myproj`.
VARARGSfilefile|str, 0...N times
Header files to install.
KWARGSfollow_symlinksbool, default: true, since 1.3.0
If true, dereferences links and copies their target instead. The default value will become false
in the future.
install_dirstr
Where to install to.
install_modelist[str|int|bool], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
preserve_pathbool, default: false, since 0.63.0
Disable stripping child-directories from header files when installing.
This is equivalent to GNU Automake's `nobase` option.
subdirstr
Install to the `subdir` subdirectory of the default includedir.
Incompatible with the `install_dir` kwarg.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.59.0 -- 1.1.0.
EXAMPLE
For example, this will install `common.h` and `kola.h` into `/{prefix}/include`:
install_headers('common.h', 'proj/kola.h')
This will install `common.h` and `kola.h` into `/{prefix}/include/myproj`:
install_headers('common.h', 'proj/kola.h', subdir : 'myproj')
This will install `common.h` and `kola.h` into `/{prefix}/cust/myproj`:
install_headers('common.h', 'proj/kola.h', install_dir : 'cust', subdir : 'myproj')
This will install `common.h` into `/{prefix}/include` and `kola.h` into `/{prefix}/include/proj/`:
install_headers('common.h, 'proj/kola.h', preserve_path : true)
install_man()SYNOPSISvoid install_man(file..., install_dir:, install_mode:, locale:)
DESCRIPTION
Installs the specified man files from the source tree into system's man directory during the install
step. This directory can be overridden by specifying it with the `install_dir` keyword argument.
(since0.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
VARARGSfilefile|str, 0...N times
Man pages to install.
KWARGSinstall_dirstr
Where to install to.
install_modelist[str|int|bool], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
localestr, since 0.58.0
Can be used to specify the locale into which the man page will be installed within the manual page
directory tree. An example manual might be `foo.fr.1` with a locale of `fr`, such that
`{mandir}/{locale}/man{num}/foo.1` becomes the installed file.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.59.0 -- 1.1.0.
install_subdir()SYNOPSISvoid install_subdir(
subdir_name,
exclude_directories:,
exclude_files:,
follow_symlinks: true,
install_dir:,
install_mode:,
install_tag:,
strip_directory: false,
)
DESCRIPTION
Installs the entire given subdirectory and its contents from the source tree to the location
specified by the keyword argument `install_dir`.
(since0.45.0,deprecatedsince0.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.
POSARGSsubdir_namestr, required
The sub-directory to install
KWARGSexclude_directorieslist[str], since 0.47.0
A list of directory names that should not be installed. Names are interpreted as paths relative to
the `subdir_name` location.
exclude_fileslist[str]
A list of file names that should not be installed. Names are interpreted as paths relative to the
`subdir_name` location.
follow_symlinksbool, default: true, since 1.3.0
If true, dereferences links and copies their target instead. The default value will become false
in the future.
install_dirstr
Where to install to.
install_modelist[str|int|bool], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default these files have no install tag which means they are not being installed when `--tags`
argument is specified.
strip_directorybool, default: false, since 0.45.0
Install directory contents. If `strip_directory=true` only the last component of the source path
is used.
WARNINGS
the `install_mode` kwarg ignored integer values between 0.59.0 -- 1.1.0.
EXAMPLE
For a given directory `foo`:
text
foo/
bar/
file1
file2
`install_subdir('foo', install_dir : 'share', strip_directory : false)` creates
text
share/
foo/
bar/
file1
file2
`install_subdir('foo', install_dir : 'share', strip_directory : true)` creates
text
share/
bar/
file1
file2
`install_subdir('foo/bar', install_dir : 'share', strip_directory : false)` creates
text
share/
bar/
file1
`install_subdir('foo/bar', install_dir : 'share', strip_directory : true)` creates
text
share/
file1
`install_subdir('new_directory', install_dir : 'share')` creates
text
share/
new_directory/
install_symlink()SYNOPSISvoid install_symlink(
link_name,
install_dir:,
install_tag:,
pointing_to:,
)
since 0.61.0
DESCRIPTION
Installs a symbolic link to `pointing_to` target under install_dir.
POSARGSlink_namestr, required
Name of the created link under `install_dir`. It cannot contain path separators. Those should go
in `install_dir`.
KWARGSinstall_dirstr, required
The absolute or relative path to the installation directory for the links. If this is a relative
path, it is assumed to be relative to the prefix.
install_tagstr
A string used by the `meson install --tags` command to install only a subset of the files. By
default these files have no install tag which means they are not being installed when `--tags`
argument is specified.
pointing_tostr, required
Target to point the link to. Can be absolute or relative and that will be respected when creating
the link.
is_disabler()SYNOPSISbool is_disabler(var)
since 0.52.0
DESCRIPTION
Returns true if a variable is a disabler and false otherwise.
POSARGSvarany, required
The variable to test
is_variable()SYNOPSISbool is_variable(var)
since 0.52.0
DESCRIPTION
Returns true if a variable of the given name exists and false otherwise.
POSARGSvarstr, required
The variable to test
jar()SYNOPSISjar jar(
target_name,
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
Build a jar from the specified Java source files. Keyword arguments are the same as executable's,
with the addition of `main_class` which specifies the main class to execute when running the jar with
`java -jar file.jar`.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
java_resourcesstructured_src, since 0.62.0
Resources to be added to the jar
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
main_classstr
Main class for running the built jar
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
join_paths()SYNOPSISstr join_paths(part...)
since 0.36.0
DESCRIPTION
Joins the given strings into a file system path segment. For example `join_paths('foo', 'bar')`
results in `foo/bar`. If any one of the individual segments is an absolute path, all segments before
it are dropped. That means that `join_paths('foo', '/bar')` returns `/bar`.
(since0.49.0) Using the `/` operator on strings is equivalent to calling join_paths.
# res1 and res2 will have identical values
res1 = join_paths(foo, bar)
res2 = foo / bar
VARARGSpartstr, 1...N times
The path parts to join.
WARNINGS
Don't use join_paths for sources in library and executable. You should use files instead.
library()SYNOPSISlib library(
target_name,
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
Builds a library that is either static, shared or both depending on the value of `default_library`
user option[22]. You should use this instead of shared_library, static_library or both_libraries
most of the time. This allows you to toggle your entire project (including subprojects) from shared
to static with only one option. This option applies to libraries being built internal to the entire
project. For external dependencies, the default library type preferred is shared. This can be adapted
on a per library basis using the dependency `static` keyword.
The keyword arguments for this are the same as for build_targetPOSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
<lang>_shared_argslist[str], since 1.3.0
Arguments that are only passed to a shared library
<lang>_static_argslist[str], since 1.3.0
Arguments that are only passed to a static library
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
darwin_versionsstr|int|list[str], since 0.48.0
Defines the `compatibility version` and `current version` for the dylib on macOS. If a list is
specified, it must be either zero, one, or two elements. If only one element is specified or if
it's not a list, the specified value will be used for setting both compatibility version and
current version. If unspecified, the `soversion` will be used as per the aforementioned rules.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
picbool, since 0.36.0
Builds the library as positional independent code (so it can be linked into a shared library). This
option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be
disabled on OS X.
prelinkbool, since 0.57.0
If `true` the object files in the target will be prelinked, meaning that it will contain only one
prelinked object file rather than the individual object files.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "rlib" or
"dylib" crate depending on the library type being build.
- 'c': Create a "cdylib" or "staticlib" crate depending on the library type being build.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
soversionstr|int
A string or integer specifying the soversion of this shared library, such as `0`. On Linux and
Windows this is used to set the soversion (or equivalent) in the filename. For example, if
`soversion` is `4`, a Windows DLL will be called `foo-4.dll` and one of the aliases of the Linux
shared library would be `libfoo.so.4`. If this is not specified, the first part of `version` is
used instead (see below). For example, if `version` is `3.6.0` and `soversion` is not defined, it
is set to `3`.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
vala_shared_argslist[str|file], since 1.3.0
Arguments that are only passed to a shared library Like `vala_args`, files is allowed in addition
to string
vala_static_argslist[str|file], since 1.3.0
Arguments that are only passed to a static library Like `vala_args`, files is allowed in addition
to string
versionstr
A string specifying the version of this shared library, such as `1.1.0`. On Linux and OS X, this is
used to set the shared library version in the filename, such as `libfoo.so.1.1.0` and
`libfoo.1.1.0.dylib`. If this is not specified, `soversion` is used instead (see above).
vs_module_defsstr|file|custom_tgt|custom_idx
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
(Since1.3.0)custom_idx are supported
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
WARNINGS
using <lang>_shared_args and/or <lang>_static_args may lead to much higher compilation times with
both_library, as object files cannot be shared between the static and shared targets. It is
guaranteed to not duplicate the build if these arguments are empty arrays
message()SYNOPSISvoid message(text, more_text...)
DESCRIPTION
This function prints its argument to stdout.
POSARGStextstr|int|bool|list[str|int|bool]|dict[str|int|bool], required
The message to print.
VARARGSmore_textstr|int|bool|list[str|int|bool]|dict[str|int|bool], 0...N times, since
0.54.0
Additional text that will be printed separated by spaces.
project()SYNOPSISvoid project(
project_name,
language...,
default_options:,
license:,
license_files:,
meson_version:,
subproject_dir: 'subprojects',
version:,
)
DESCRIPTION
The first function called in each project, to initialize Meson.
The first argument to this function must be a string defining the name of this project.
The project name can be any string you want, it's not used for anything except descriptive purposes.
However since it is written to e.g. the dependency manifest is usually makes sense to have it be the
same as the project tarball or pkg-config name. So for example you would probably want to use the
name _libfoobar_ instead of _The Foobar Library_.
It may be followed by the list of programming languages that the project uses.
(since0.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. (since0.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`.
POSARGSproject_namestr, required
The name of the project.
VARARGSlanguagestr, 0...N times
The languages that Meson should initialize.
KWARGSdefault_optionslist[str]|dict[str|bool|int|list[str]]
Accepts strings in the form `key=value` which have the same format as options to `meson configure`.
For example to set the default project type you would set this: `default_options :
['buildtype=debugoptimized']`. Note that these settings are only used when running Meson for the
first time. Global options such as `buildtype` can only be specified in the master project,
settings in subprojects are ignored. Project specific options are used normally even in
subprojects.
Note that some options can override the default behavior; for example, using `c_args` here means
that the `CFLAGS` environment variable is not used. Consider using add_project_arguments() instead.
(since1.2.0): A dictionary may now be passed.
licensestr|list[str]
Takes a string or array of strings describing the license(s) the code is under.
This should be an SPDXlicenseexpression[23], using the standardized license identifier from the
SPDXlicenselist[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_filesstr|list[str], since 1.1.0
Takes a string or array of strings with the paths to the license file(s) the code is under.
This enhances the value of the `license` kwarg by allowing to specify both the short license name
and the full license text. Usually this would be something like `license_files: ['COPYING']`.
Note that the files are informal and are only installed with the dependency manifest. Meson does
not do any license validation, you are responsible for verifying that you abide by all licensing
terms. You can access the value in your Meson build files with meson.project_license_files.
meson_versionstr
Takes a string describing which Meson version the project requires. Usually something like
`>=0.28.0`.
subproject_dirstr, default: 'subprojects'
Specifies the top level directory name that holds Meson subprojects. This is only meant as a
compatibility option for existing code bases that house their embedded source code in a custom
directory. All new projects should not set this but instead use the default value. It should be
noted that this keyword argument is ignored inside subprojects. There can be only one subproject
dir and it is set in the top level Meson file.
versionstr|file
A free form string describing the version of this project. You can access the value in your Meson
build files with meson.project_version. (Since0.57.0) this can also be a file object pointing to a
file that contains exactly one line of text.
range()SYNOPSISrange range([start], [stop], [step])
since 0.58.0
DESCRIPTION
Return an opaque object that can be only be used in `foreach` statements.
<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.
OPTARGSstartint, default: 0
The start of the range
stopint
The end of the range
stepint, default: 1
The loop increment
EXAMPLE
# Loop 15 times with i from 0 to 14 included.
foreach i : range(15)
...
endforeach
The range object can also be assigned to a variable and indexed.
r = range(5, 10, 2)
assert(r[2] == 9)
run_command()SYNOPSISrunresult run_command(
command...,
capture: true,
check: false,
env:,
)
DESCRIPTION
Runs the command specified in positional arguments. `command` can be a string, or the output of
find_program, files or configure_file, or acompilerobject.
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 Externalcommands[25].
VARARGScommandstr|file|external_program|compiler, 0...N times
The command to execute during the setup process.
KWARGScapturebool, default: true, since 0.47.0
If `true`, any output generated on stdout will be captured and returned by the `.stdout()` method.
If it is false, then `.stdout()` will return an empty string.
checkbool, default: false, since 0.47.0
If `true`, the exit status code of the command will be checked, and the configuration will fail if
it is non-zero. Note that the default value will be `true` in future releases.
envenv|list[str]|dict[str], since 0.50.0
environment variables to set, such as `['NAME1=value1', 'NAME2=value2']`, or an env object which
allows more sophisticated environment juggling. (Since0.52.0) A dictionary is also accepted.
run_target()SYNOPSISrun_tgt run_target(target_name, command:, depends:, env:)
DESCRIPTION
This function creates a new top-level target that runs a specified command with the specified
arguments. Like all top-level targets, this integrates with the selected backend. For instance, you
can run it as `meson compile target_name`. Note that a run target produces no output as far as Meson
is concerned. It is only meant for tasks such as running a code formatter or flashing an external
device's firmware with a built file.
The command is run from an unspecified directory, and Meson will set three environment variables
`MESON_SOURCE_ROOT`, `MESON_BUILD_ROOT` and `MESON_SUBDIR` that specify the source directory, build
directory and subdirectory the target was defined in, respectively.
Since0.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@` Since0.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.
POSARGStarget_namestr, required
The name of the run target
KWARGScommandlist[exe|external_program|custom_tgt|file|str]
A list containing the command to run and the arguments to pass to it. Each list item may be a
string or a target. For instance, passing the return value of executable as the first item will run
that executable, or passing a string as the first item will find that command in `PATH` and run it.
dependslist[build_tgt|custom_tgt|custom_idx]
A list of targets that this target depends on but which are not listed in the command array
(because, for example, the script does file globbing internally, custom_idx was not possible as a
type between 0.60 and 1.4.0).
envenv|list[str]|dict[str], since 0.57.0
environment variables to set, such as `{'NAME1': 'value1', 'NAME2': 'value2'}` or `['NAME1=value1',
'NAME2=value2']`, or an env object which allows more sophisticated environment juggling.
set_variable()SYNOPSISvoid set_variable(variable_name, value)
DESCRIPTION
Assigns a value to the given variable name. Calling `set_variable('foo', bar)` is equivalent to `foo
= bar`.
(since0.46.1) The `value` parameter can be an array type.
POSARGSvariable_namestr, required
The name of the variable to set
valueany, required
The value to set the variable to
shared_library()SYNOPSISlib shared_library(
target_name,
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
Builds a shared library with the given sources.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
darwin_versionsstr|int|list[str], since 0.48.0
Defines the `compatibility version` and `current version` for the dylib on macOS. If a list is
specified, it must be either zero, one, or two elements. If only one element is specified or if
it's not a list, the specified value will be used for setting both compatibility version and
current version. If unspecified, the `soversion` will be used as per the aforementioned rules.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "dylib" crate.
- 'c': Create a "cdylib" crate.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
soversionstr|int
A string or integer specifying the soversion of this shared library, such as `0`. On Linux and
Windows this is used to set the soversion (or equivalent) in the filename. For example, if
`soversion` is `4`, a Windows DLL will be called `foo-4.dll` and one of the aliases of the Linux
shared library would be `libfoo.so.4`. If this is not specified, the first part of `version` is
used instead (see below). For example, if `version` is `3.6.0` and `soversion` is not defined, it
is set to `3`.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
versionstr
A string specifying the version of this shared library, such as `1.1.0`. On Linux and OS X, this is
used to set the shared library version in the filename, such as `libfoo.so.1.1.0` and
`libfoo.1.1.0.dylib`. If this is not specified, `soversion` is used instead (see above).
vs_module_defsstr|file|custom_tgt|custom_idx
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
(Since1.3.0)custom_idx are supported
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
shared_module()SYNOPSISbuild_tgt shared_module(
target_name,
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
Builds a shared module with the given sources.
This is useful for building modules that will be `dlopen()`ed and hence may contain undefined symbols
that will be provided by the library that is loading it.
If you want the shared module to be able to refer to functions and variables defined in the
executable it is loaded by, you will need to set the `export_dynamic` argument of the executable to
`true`.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "dylib" crate.
- 'c': Create a "cdylib" crate.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
vs_module_defsstr|file|custom_tgt|custom_idx, since 0.52.0
Specify a Microsoft module definition file for controlling symbol exports, etc., on platforms where
that is possible (e.g. Windows).
(Since1.3.0)custom_idx are supported
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
NOTES
*Linking to a shared module on platforms other than Android is deprecated, and will be an error in
the future*. It was previously allowed because it was the only way to have a shared-library-like
target that contained references to undefined symbols. However, since 0.40.0, the `override_options:`
build_target keyword argument can be used to create such a shared_library by passing
`override_options: 'b_lundef=false'`. Shared modules have other characteristics that make them
incompatible with linking, such as a lack of SONAME. On macOS and iOS, linking to shared modules is
disallowed by the linker, so we disallow it at configure time. On Android, if a shared module `foo`
uses symbols from another shared module `bar`, `foo` must also be linked to `bar`. Hence, linking one
shared module to another will always be allowed when building for Android.
static_library()SYNOPSISlib static_library(
target_name,
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
Builds a static library with the given sources.
POSARGStarget_namestr, required
The unique name of the build target
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to compile. The following types are supported:
- 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-onlydependency[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.
KWARGS<lang>_argslist[str]
compiler flags to use for the given language; eg: `cpp_args` for C++
<lang>_pchstr
precompiled header file to use for the given language
build_by_defaultbool, default: true, since 0.38.0
Causes, when set to `true`, to have this target be built by default. This means it will be built
when `meson compile` is called without any arguments. The default value is `true` for all built
target types.
build_rpathstr, since 0.42.0
A string to add to target's rpath definition in the build dir, but which will be removed on install
d_debuglist[str]
The Dversionidentifiers[5] to add during the compilation of D source files.
d_import_dirslist[str]
List of directories to look in for string imports used in the D programming language.
d_module_versionslist[str|int]
List of module version identifiers set when compiling D sources.
d_unittestbool, default: false
When set to true, the D modules are compiled in debug mode.
dependencieslist[dep]
one or more dependency objects created with dependency or compiler.find_library (for external deps)
or declare_dependency (for deps built by the project)
extra_filesstr|file|custom_tgt|custom_idx
Not used for the build itself but are shown as source files in IDEs that group files by targets
(such as Visual Studio)
gnu_symbol_visibilitystr, since 0.48.0
Specifies how symbols should be exported, see e.g theGCCWiki[6] for more information. This value
can either be an empty string or one of `default`, `internal`, `hidden`, `protected` or
`inlineshidden`, which is the same as `hidden` but also includes things like C++ implicit
constructors as specified in the GCC manual. Ignored on compilers that do not support GNU
visibility arguments.
gui_appbool, default: false, deprecated since 0.56.0
When set to true flags this target as a GUI application on platforms where this makes a difference,
deprecated since 0.56.0, use `win_subsystem` instead.
implicit_include_directoriesbool, default: true, since 0.42.0
Controls whether Meson adds the current source and build directories to the include path
include_directorieslist[inc|str]
one or more objects created with the include_directories function, or (since0.50.0) strings, which
will be transparently expanded to include directory objects
installbool, default: false
When set to true, this executable should be installed.
install_dirstr
override install directory for this file. If the value is a relative path, it will be considered
relative the `prefix` option. For example, if you want to install plugins into a subdir, you'd use
something like this: `install_dir : get_option('libdir') / 'projectname-1.0'`.
install_modelist[str|int], since 0.47.0
Specify the file mode in symbolic format and optionally the owner/uid and group/gid for the
installed files.
See the `install_mode` kwarg of install_data for more information.
install_rpathstr
A string to set the target's rpath to after install (but not before that). On Windows, this
argument has no effect.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default all build targets have the tag `runtime` except for static libraries that have the `devel`
tag.
link_argslist[str]
Flags to use during linking. You can use UNIX-style flags here for all platforms.
link_dependsstr|file|custom_tgt|custom_idx
Strings, files, or custom targets the link step depends on such as a symbol visibility map. The
purpose is to automatically trigger a re-link (but not a re-compile) of the target when this file
changes.
link_languagestr, since 0.51.0
Makes the linker for this target be for the specified language. It is generally unnecessary to set
this, as Meson will detect the right linker to use in most cases. There are only two cases where
this is needed. One, your main function in an executable is not in the language Meson picked, or
second you want to force a library to use only one ABI.
(brokenuntil0.55.0)link_wholelist[lib|custom_tgt|custom_idx], since 0.40.0
Links all contents of the given static libraries whether they are used or not, equivalent to the
`-Wl,--whole-archive` argument flag of GCC, or the ´/WHOLEARCHIVE' MSVC linker option. This allows
the linked target to re-export symbols from all objects in the static libraries.
(since0.41.0) If passed a list that list will be flattened.
(since0.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_withlist[lib|custom_tgt|custom_idx]
One or more shared or static libraries (built by this project) that this target should be linked
with. (since0.41.0) If passed a list this list will be flattened. (since0.51.0) The arguments can
also be custom targets. In this case Meson will assume that merely adding the output file in the
linker command line is sufficient to make linking work. If this is not sufficient, then the build
system writer must write all other steps manually.
name_prefixstr|list[void]
The string that will be used as the prefix for the target output filename by overriding the default
(only used for libraries). By default this is `lib` on all platforms and compilers, except for MSVC
shared libraries where it is omitted to follow convention, and Cygwin shared libraries where it is
`cyg`.
Set this to `[]`, or omit the keyword argument for the default behaviour.
name_suffixstr|list[void]
The string that will be used as the extension for the target by overriding the default. By default
on Windows this is `exe` for executables and on other platforms it is omitted.
For shared libraries, the default value is `dylib` on macOS, `dll` on Windows, and `so` everywhere
else. For static libraries, it is `a` everywhere. By convention MSVC static libraries use the
`lib` suffix, but we use `a` to avoid a potential name clash with shared libraries which also
generate import libraries with a `lib` suffix.
Set this to `[]`, or omit the keyword argument for the default behaviour.
nativebool, default: false
Controls whether the target is compiled for the build or host machines.
objectslist[extracted_obj|file|str]
List of object files that should be linked in this target.
Since 1.1.0 this can include generated files in addition to object files that you don't have source
to or that object files produced by other build targets. In earlier release, generated object
files had to be placed in `sources`.
override_optionslist[str]|dict[str|bool|int|list[str]], since 0.40.0
takes an array of strings in the same format as `project`'s `default_options` overriding the values
of these options for this target only. (since1.2.0): A dictionary may now be passed.
picbool, since 0.36.0
Builds the library as positional independent code (so it can be linked into a shared library). This
option has no effect on Windows and OS X since it doesn't make sense on Windows and PIC cannot be
disabled on OS X.
prelinkbool, since 0.57.0
If `true` the object files in the target will be prelinked, meaning that it will contain only one
prelinked object file rather than the individual object files.
rust_abistr, since 1.3.0
Set the specific ABI to compile (when compiling rust). - 'rust' (default): Create a "rlib" crate.
- 'c': Create a "staticlib" crate.
rust_crate_typestr, deprecated since 1.3.0, since 0.42.0
Set the specific type of rust crate to compile (when compiling rust).
If the target is an executable this defaults to "bin", the only allowed value.
If it is a static_library it defaults to "lib", and may be "lib", "staticlib", or "rlib". If "lib"
then Rustc will pick a default, "staticlib" means a C ABI library, "rlib" means a Rust ABI.
If it is a shared_library it defaults to "lib", and may be "lib", "dylib", "cdylib", or "proc-
macro". If "lib" then Rustc will pick a default, "cdylib" means a C ABI library, "dylib" means a
Rust ABI, and "proc-macro" is a special rust procedural macro crate.
"proc-macro" is new in 0.62.0.
Since1.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_mapdict[str], since 1.2.0
On rust targets this provides a map of library names to the crate name with which it would be
available inside the rust code.
This allows renaming similar to the dependency renaming feature of cargo or `extern crate foo as
bar` inside rust code.
sourcesstr|file|custom_tgt|custom_idx|generated_list|structured_src
Additional source files. Same as the source varargs.
vala_argslist[str|file]
Compiler flags for Vala. Unlike other languages this may contain Files
win_subsystemstr, default: 'console', since 0.56.0
Specifies the subsystem type to use on the Windows platform. Typical values include `console` for
text mode programs and `windows` for gui apps. The value can also contain version specification
such as `windows,6.0`. See MSDNdocumentation[8] for the full list.
structured_sources()SYNOPSISstructured_src structured_sources(root, [additional])
since 0.62.0
DESCRIPTION
Create a StructuredSource object, which is opaque and may be passed as a source to any build_target
(including static_library, shared_library, executable, etc.). This is useful for languages like Rust,
which use the filesystem layout to determine import names. This is only allowed in Rust targets, and
cannot be mixed with non structured inputs.
POSARGSrootlist[str|file|custom_tgt|custom_idx|generated_list], required
Sources to put at the root of the generated structure
OPTARGSadditionaldict[str|file|custom_tgt|custom_idx|generated_list]
Additional sources, where the key is the directory under the root to place the values
subdir()SYNOPSISvoid subdir(dir_name, if_found:)
DESCRIPTION
Enters the specified subdirectory and executes the `meson.build` file in it. Once that is done, it
returns and execution continues on the line following this `subdir()` command. Variables defined in
that `meson.build` file are then available for use in later parts of the current build file and in
all subsequent build files executed with `subdir()`.
Note that this means that each `meson.build` file in a source tree can and must only be executed
once.
POSARGSdir_namestr, required
Directory relative to the current `meson.build` to enter.
Cannot contain `..`
KWARGSif_foundlist[dep], since 0.44.0
Only enter the subdir if all dep.found methods return `true`.
subdir_done()SYNOPSISvoid subdir_done()
since 0.46.0
DESCRIPTION
Stops further interpretation of the Meson script file from the point of the invocation. All steps
executed up to this point are valid and will be executed by Meson. This means that all targets
defined before the call of subdir_done will be build.
If the current script was called by `subdir` the execution returns to the calling directory and
continues as if the script had reached the end. If the current script is the top level script Meson
configures the project as defined up to this point.
EXAMPLE
project('example exit', 'cpp')
executable('exe1', 'exe1.cpp')
subdir_done()
executable('exe2', 'exe2.cpp')
The executable `exe1` will be build, while the executable `exe2` is not build.
subproject()SYNOPSISsubproject subproject(
subproject_name,
default_options:,
required: true,
version:,
)
DESCRIPTION
Takes the project specified in the positional argument and brings that in the current build
specification by returning a subproject object. Subprojects must always be placed inside the
`subprojects` directory at the top source directory. So for example a subproject called `foo` must be
located in `${MESON_SOURCE_ROOT}/subprojects/foo`.
- `default_options` (since0.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).
(since0.54.0): `default_library` built-in option can also be overridden. (since1.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` (since0.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.
Seeadditionaldocumentation[26].
POSARGSsubproject_namestr, required
Name of the subproject. The subproject must exist in the `subprojects` directory (or the directory
specified in the `subproject_dir` of project) as a directory or wrap file.
KWARGSdefault_optionslist[str]|dict[str|bool|int|list[str]], 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). (since0.54.0):
`default_library` built-in option can also be overridden. (since1.2.0): A dictionary may now be
passed.
requiredbool|feature, default: true, since 0.48.0
Works just the same as in dependency.
versionstr|list[str]
Works just like the same as in dependency. It specifies what version the subproject should be, as
an example `>=1.0.1`.
summary()SYNOPSISvoid summary(
key_or_dict,
[value],
bool_yn: false,
list_sep:,
section:,
)
since 0.53.0
DESCRIPTION
This function is used to summarize build configuration at the end of the build process. This function
provides a way for projects (and subprojects) to report this information in a clear way.
The content is a series of key/value pairs grouped into sections. If the section keyword argument is
omitted, those key/value pairs are implicitly grouped into a section with no title. key/value pairs
can optionally be grouped into a dictionary, but keep in mind that dictionaries do not guarantee
ordering. `key` must be string, `value` can be:
- an integer, boolean or string
- since0.57.0 an external program or a dependency
- since0.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.
POSARGSkey_or_dictstr|dict[str|bool|int|dep|external_program|list[str|bool|int|dep|external_program]], required
The name of the new entry, or a dict containing multiple entries. If a dict is passed it is
equivalent to calling summary() once for each key-value pair. Keep in mind that dictionaries do
not guarantee ordering.
OPTARGSvaluestr|bool|int|dep|external_program|list[str|bool|int|dep|external_program]
The value to print for the `key`. Only valid if `key_or_dict` is a str.
KWARGSbool_ynbool, default: false
Convert bool values to yes and no
list_sepstr, since 0.54.0
The separator to use when printing list values in this summary. If no separator is given, each
list item will be printed on its own line.
sectionstr
The section to put this summary information under. If the section keyword argument is omitted,
key/value pairs are implicitly grouped into a section with no title.
EXAMPLE
Example `meson.build`:
project('My Project', version : '1.0')
summary({'bindir': get_option('bindir'),
'libdir': get_option('libdir'),
'datadir': get_option('datadir'),
}, section: 'Directories')
summary({'Some boolean': false,
'Another boolean': true,
'Some string': 'Hello World',
'A list': ['string', 1, true],
}, section: 'Configuration')
Output:
My Project 1.0
Directories
prefix : /opt/gnome
bindir : bin
libdir : lib/x86_64-linux-gnu
datadir : share
Configuration
Some boolean : False
Another boolean: True
Some string : Hello World
A list : string
1
True
test()SYNOPSISvoid test(
name,
executable,
args:,
depends:,
env:,
is_parallel: true,
priority: 0,
protocol: 'exitcode',
should_fail: false,
suite:,
timeout: 30,
verbose: false,
workdir:,
)
DESCRIPTION
Defines a test to run with the test harness. Takes two positional arguments, the first is the name of
the test and the second is the executable to run. The executable can be an exe object returned by
executable or an external_program object] returned by find_program.
(since0.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:
nomalloc = environment({'MALLOC_PERTURB_': '0'})
test(..., env: nomalloc, ...)
By default, the environment variables `ASAN_OPTIONS`, `UBSAN_OPTIONS`, and `MSAN_OPTIONS` are set to
enable aborting on detected violations and to give a backtrace. To suppress this, `ASAN_OPTIONS`,
`UBSAN_OPTIONS`, or `MSAN_OPTIONS` can be set in the environment.
In addition to running individual executables as test cases, `test()` can also be used to invoke an
external test harness. In this case, it is best to use `verbose: true` (since0.62.0) and, if
supported by the external harness, `protocol: 'tap'` (since0.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`.
POSARGSnamestr, required
The unique test id
executableexe|jar|external_program|file|custom_tgt|custom_idx, required
The program to execute. (Since1.4.0) A CustomTarget is also accepted.
KWARGSargslist[str|file|build_tgt|custom_tgt|custom_idx]
Arguments to pass to the executable
dependslist[build_tgt|custom_tgt], since 0.46.0
specifies that this test depends on the specified target(s), even though it does not take any of
them as a command line argument. This is meant for cases where test finds those targets internally,
e.g. plugins or globbing. Those targets are built before test is executed even if they have
`build_by_default : false`.
envenv|list[str]|dict[str]
environment variables to set, such as `['NAME1=value1', ´NAME2=value2']`, or an env object which
allows more sophisticated environment juggling. (Since0.52.0) A dictionary is also accepted.
is_parallelbool, default: true
when false, specifies that no other test must be running at the same time as this test
priorityint, default: 0, since 0.52.0
specifies the priority of a test. Tests with a higher priority are started before tests with a
lower priority. The starting order of tests with identical priorities is implementation-defined.
The default priority is 0, negative numbers are permitted.
protocolstr, default: 'exitcode', since 0.50.0
specifies how the test results are parsed and can be one of `exitcode`, `tap`, or `gtest`. For more
information about test harness protocol read UnitTests[1]. The following values are accepted:
- `exitcode`: the executable's exit code is used by the test harness to record the outcome of the
test).
- `tap`: TestAnythingProtocol[2].
- `gtest` (since0.55.0): for Google Tests.
- `rust` (since0.56.0): for native rust tests
should_failbool, default: false
when true the test is considered passed if the executable returns a non-zero return value (i.e.
reports an error)
suitestr|list[str]
`'label'` (or list of labels `['label1', 'label2']`) attached to this test. The suite name is
qualified by a (sub)project name resulting in `(sub)project_name:label`. In the case of a list of
strings, the suite names will be `(sub)project_name:label1`, `(sub)project_name:label2`, etc.
timeoutint, default: 30
the amount of seconds the test is allowed to run, a test that exceeds its time limit is always
considered failed, defaults to 30 seconds. Since0.57 if timeout is `<= 0` the test has infinite
duration, in previous versions of Meson the test would fail with a timeout immediately.
verbosebool, default: false, since 0.62.0
if true, forces the test results to be logged as if `--verbose` was passed to `meson test`.
workdirstr
absolute path that will be used as the working directory for the test
unset_variable()SYNOPSISvoid unset_variable(varname)
since 0.60.0
DESCRIPTION
Unsets a variable. Referencing a variable which has been unset is an error until it has been set
again.
POSARGSvarnamestr, required
The variable to unset.
vcs_tag()SYNOPSIScustom_tgt vcs_tag(
command:,
fallback: [[meson.project_version]],
input:,
output:,
replace_string: '@VCS_TAG@',
)
DESCRIPTION
This command detects revision control commit information at build time and places it in the specified
output file. This file is guaranteed to be up to date on every build. Keywords are similar to
custom_target.
Meson will read the contents of `input`, substitute the `replace_string` with the detected revision
number, and write the result to `output`. This method returns a custom_tgt object that (as usual)
should be used to signal dependencies if other targets use the file outputted by this.
For example, if you generate a header with this and want to use that in a build target, you must add
the return value to the sources of that build target. Without that, Meson will not know the order in
which to build the targets.
If you desire more specific behavior than what this command provides, you should use custom_target.
KWARGScommandlist[exe|external_program|custom_tgt|file|str]
The command to execute, see custom_target for details on how this command must be specified.
This parameter is optional. If it is absent, Meson will try its best to find a suitable default
command.
(since0.62.0)file is accepted.
(since0.63.0)custom_tgt, exe, and external_program are accepted.
fallbackstr, default: [[meson.project_version]]
Version number to use when no revision control information is present, such as when building from a
release tarball.
inputlist[build_tgt|custom_idx|custom_tgt|external_program|extracted_obj|file|generated_list|str], required
File to modify (e.g. `version.c.in`).
outputstr, required
File to write the results to (e.g. `version.c`).
replace_stringstr, default: '@VCS_TAG@'
String in the input file to substitute with the commit information.
warning()SYNOPSISvoid warning(text, more_text...)
since 0.44.0
DESCRIPTION
This function prints its argument to stdout prefixed with WARNING:.
POSARGStextstr|int|bool|list[str|int|bool]|dict[str|int|bool], required
The message to print.
VARARGSmore_textstr|int|bool|list[str|int|bool]|dict[str|int|bool], 0...N times, since
0.54.0
Additional text that will be printed separated by spaces.
bool.to_int()SYNOPSISint bool.to_int()
DESCRIPTION
Returns `1` if `true` and `0` if `false`
bool.to_string()SYNOPSISstr bool.to_string([true_str], [false_str])
DESCRIPTION
Returns the string `'true'` if the boolean is true or `'false'` otherwise. You can also pass it two
strings as positional arguments to specify what to return for true/false. For instance,
`bool.to_string('yes', 'no')` will return `yes` if the boolean is true and `no` if it is false.
OPTARGStrue_strstr, default: 'true'
The string to return when the boolean is `true`
false_strstr, default: 'false'
The string to return when the boolean is `false`
both_libs.get_shared_lib()SYNOPSISlib both_libs.get_shared_lib()
DESCRIPTION
Returns the stored shared library
both_libs.get_static_lib()SYNOPSISlib both_libs.get_static_lib()
DESCRIPTION
Returns the stored static library
build_machine.cpu()SYNOPSISstr build_machine.cpu()
DESCRIPTION
Returns a more specific CPU name, such as `i686`, `amd64`, etc.
build_machine.cpu_family()SYNOPSISstr build_machine.cpu_family()
DESCRIPTION
Returns the CPU family name. Thistable[28] contains all known CPU families. These are guaranteed to
continue working.
build_machine.endian()SYNOPSISstr build_machine.endian()
DESCRIPTION
returns `'big'` on big-endian systems and `'little'` on little-endian systems.
build_machine.system()SYNOPSISstr build_machine.system()
DESCRIPTION
Returns the operating system name. Thistable[29] Lists all of the currently known Operating System
names, these are guaranteed to continue working.
build_tgt.extract_all_objects()SYNOPSISextracted_obj build_tgt.extract_all_objects(
recursive: true,
)
DESCRIPTION
Acts the same as `extract_objects`, but returns all object files generated by this target.
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.
KWARGSrecursivebool, default: true, since 0.46.0
Also return objects passed to the `objects` argument of this target.
build_tgt.extract_objects()SYNOPSISextracted_obj build_tgt.extract_objects(source...)
DESCRIPTION
Returns an opaque value representing the object files generated for those source files. This is
typically used to take single object files and link them to unit tests or to compile some source
files with custom flags. To use the object file(s) in another build target, use the `objects:`
keyword argument to a build_target or declare_dependency, or include them in the command line of a
custom_target.
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 1...N times
Source filenames for which the built objects should be extracted.
build_tgt.found()SYNOPSISbool build_tgt.found()
since 0.59.0
DESCRIPTION
Always returns `true`. This function is meant to make executables objects feature compatible with
external_program objects. This simplifies use-cases where an executable is used instead of an
external_program.
build_tgt.full_path()SYNOPSISstr build_tgt.full_path()
DESCRIPTION
Returns a full path pointing to the result target file. NOTE: In most cases using the object itself
will do the same job as this and will also allow Meson to setup inter-target dependencies correctly.
Please file a bug if that doesn't work for you.
build_tgt.get_id()SYNOPSISstr build_tgt.get_id()
since 0.26.0
DESCRIPTION
Returns a unique id for the target
build_tgt.name()SYNOPSISstr build_tgt.name()
since 0.54.0
DESCRIPTION
Returns the name of the target.
build_tgt.outdir()SYNOPSISstr build_tgt.outdir()
since 0.26.0
DESCRIPTION
Returns the output directory relative to the build root of the target
build_tgt.path()SYNOPSISstr build_tgt.path()
deprecated since 0.59.0, since 0.59.0
DESCRIPTION
Does the exact same as build_tgt.full_path. NOTE: This function is solely kept for compatibility with
external_program objects. It will be removed once the, also deprecated, corresponding `path()`
function in the external_program object is removed.
build_tgt.private_dir_include()SYNOPSISinc build_tgt.private_dir_include()
DESCRIPTION
Returns a value that works like include_directories, but points to the private directory of this
target. Usually only needed if an another target needs to access some generated internal headers of
this target.
cfg_data.get()SYNOPSISstr|int|bool cfg_data.get(varname, [default_value])
since 0.38.0
DESCRIPTION
Returns the value of `varname`, if the value has not been set returns `default_value` if it is
defined (since0.38.0) and errors out if not
POSARGSvarnamestr, required
The name of the variable to query
OPTARGSdefault_valuestr|int|bool
The default value to return when `varname` does not exist
cfg_data.get_unquoted()SYNOPSISstr|int|bool cfg_data.get_unquoted(varname, [default_value])
since 0.44.0
DESCRIPTION
Returns the value of `varname` but without surrounding double quotes (`"`). If the value has not been
set returns `default_value` if it is defined and errors out if not.
POSARGSvarnamestr, required
The name of the variable to query
OPTARGSdefault_valuestr|int|bool
The default value to return when `varname` does not exist
cfg_data.has()SYNOPSISbool cfg_data.has(varname)
DESCRIPTION
returns `true` if the specified variable is set
POSARGSvarnamestr, required
The name of the variable to query
cfg_data.keys()SYNOPSISlist[str] cfg_data.keys()
since 0.57.0
DESCRIPTION
Returns an array of keys of the configuration data object.
You can iterate over this array with the `foreach`statement[30].
cfg_data.merge_from()SYNOPSISvoid cfg_data.merge_from(other)
since 0.42.0
DESCRIPTION
Takes as argument a different configuration data object and copies all entries from that object to
the current.
POSARGSothercfg_data, required
The other cfg_data object to merge into this one.
cfg_data.set()SYNOPSISvoid cfg_data.set(varname, value, description:)
DESCRIPTION
Sets a variable to a given value
POSARGSvarnamestr, required
The name of the variable to set
valuestr|int|bool, required
The value to set
KWARGSdescriptionstr
Message / Comment that will be written in the result file. The replacement assumes a file with C
syntax. If your generated file is source code in some other language, you probably don't want to
add a description field because it most likely will cause a syntax error.
cfg_data.set10()SYNOPSISvoid cfg_data.set10(varname, value, description:)
DESCRIPTION
Is the same as cfg_data.set but the value is either `true` or `false` and will be written as 1 or 0,
respectively
POSARGSvarnamestr, required
The name of the variable to set
valuebool|int, required
The value to set as either `1` or `0`
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.
KWARGSdescriptionstr
Message / Comment that will be written in the result file. The replacement assumes a file with C
syntax. If your generated file is source code in some other language, you probably don't want to
add a description field because it most likely will cause a syntax error.
WARNINGS
numeric values < 0 have the surprising behavior of being converted to `true`, values > 1 have the
more expected but unintentional behavior of being interpreted as `true`.
cfg_data.set_quoted()SYNOPSISvoid cfg_data.set_quoted(varname, value, description:)
DESCRIPTION
Is same as cfg_data.set but quotes the value in double quotes (`"`)
POSARGSvarnamestr, required
The name of the variable to set
valuestr|int|bool, required
The value to set
KWARGSdescriptionstr
Message / Comment that will be written in the result file. The replacement assumes a file with C
syntax. If your generated file is source code in some other language, you probably don't want to
add a description field because it most likely will cause a syntax error.
cmake.subproject_options()SYNOPSIScmake_options cmake.subproject_options()
DESCRIPTION
Returns an empty `cmake_options` object.
cmake_options.add_cmake_defines()SYNOPSISvoid cmake_options.add_cmake_defines(defines...)
DESCRIPTION
Add CMake defines (`-D<VAR>=<VAL>`) to the CMake commandline
VARARGSdefinesdict[str], 0...N times
A `key` `value` map of CMake defines to add (`-D<key>=<val>`)
compiler.alignment()SYNOPSISint compiler.alignment(typename, args:, dependencies:, prefix:)
DESCRIPTION
Returns the alignment of the specified type. For C-like languages, For C-like languages, the header
`stddef.h` and `stdio.h` are included implicitly for native compilation, only `stddef.h` is included
when cross-compiling.
POSARGStypenamestr, required
The name of the type to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
compiler.check_header()SYNOPSISbool compiler.check_header(
header_name,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
since 0.47.0
DESCRIPTION
Returns true if the specified header is usable with the specified prefix, dependencies, and
arguments.
POSARGSheader_namestr, required
The header to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 0.50.0
When set to `true`, Meson will halt if the header check fails. When set to a `feature`[0] option,
the feature will control if it is searched and whether to fail if not found.
compiler.cmd_array()SYNOPSISlist[str] compiler.cmd_array()
DESCRIPTION
Returns an array containing the command(s) for the compiler.
compiler.compiles()SYNOPSISbool compiler.compiles(
code,
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
)
DESCRIPTION
Returns true if the code compiles.
POSARGScodestr|file, required
The source code to check.
If a string is passed, the code is used directly. If a file object is passed, its content is used
for the compiler check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
namestr
The name to use for printing a message about the compiler check. If this keyword argument is not
passed, no message will be printed about the check.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
requiredbool|feature, default: false, since 1.5.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
werrorbool, default: false, since 1.3.0
When set to `true`, compiler warnings are treated as error.
compiler.compute_int()SYNOPSISint compiler.compute_int(
expr,
args:,
dependencies:,
guess:,
high: 1024,
include_directories:,
low: -1024,
no_builtin_args: false,
prefix:,
)
since 0.40.0
DESCRIPTION
Computes the value of the given expression (as an example `1 + 2`). When cross compiling this is
evaluated with an iterative algorithm, you can specify keyword arguments `low` (defaults to -1024),
`high` (defaults to 1024) and `guess` to specify max and min values for the search and the value to
try first. For C-like languages, the header `stddef.h` and `stdio.h` are included implicitly for
native compilation, only `stddef.h` is included when cross-compiling.
POSARGSexprstr, required
The expression to compute.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
guessint
The value to try first.
highint, default: 1024
The max value.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
lowint, default: -1024
The min value.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
compiler.find_library()SYNOPSISdep compiler.find_library(
libname,
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
Tries to find the library specified in the positional argument.
POSARGSlibnamestr, required
The library to find.
KWARGSdirslist[str]
Additional directories to search in.
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.
disablerbool, default: false, since 0.49.0
If `true`, this method will return a disabler on a failed check.
has_headerslist[str], since 0.50.0
List of headers that must be found as well. This check is equivalent to checking each header with
a compiler.has_header call.
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_argslist[str], since 0.51.0
When the `has_headers` kwarg is also used, this argument is passed to compiler.has_header as
`args`.
header_dependenciesdep|list[dep], since 0.51.0
When the `has_headers` kwarg is also used, this argument is passed to compiler.has_header as
`dependencies`.
header_include_directoriesinc|list[inc], since 0.51.0
When the `has_headers` kwarg is also used, this argument is passed to compiler.has_header as
`include_directories`.
header_no_builtin_argsbool, default: false, since 0.51.0
When the `has_headers` kwarg is also used, this argument is passed to compiler.has_header as
`no_builtin_args`.
header_prefixstr, since 0.51.0
When the `has_headers` kwarg is also used, this argument is passed to compiler.has_header as
`prefix`.
header_requiredbool|feature, since 0.50.0
When used in conjunction with the has_headers keyword, set the requirement of the headers.
requiredbool|feature, default: true
If set `true`, Meson will abort with an error if the library could not be found. Otherwise, Meson
will continue and the found method of the returned object will return `false`.
When set to a `feature`[0] option, the feature will control if it is searched and whether to fail
if not found.
(since0.47.0) The value of a `feature` option can also be passed here.
staticbool, default: false, since 0.51.0
If `true`, the search is limited to static libraries only. Setting this value to `false` (the
default) will search for both shared and static libraries.
compiler.first_supported_argument()SYNOPSISlist[str] compiler.first_supported_argument(arg...)
since 0.43.0
DESCRIPTION
Given a list of strings, returns a single-element list containing the first argument that passes the
compiler.has_argument test or an empty array if none pass.
VARARGSargstr, 0...N times
The arguments to check.
compiler.first_supported_link_argument()SYNOPSISlist[str] compiler.first_supported_link_argument(arg...)
since 0.46.0
DESCRIPTION
Given a list of strings, returns the first argument that passes the compiler.has_link_argument test
or an empty array if none pass.
VARARGSargstr, 0...N times
The link arguments to check.
compiler.get_argument_syntax()SYNOPSISstr compiler.get_argument_syntax()
since 0.49.0
DESCRIPTION
returns a string identifying the type of arguments the compiler takes. Can be one of `gcc`, `msvc`,
or an undefined string value. This method is useful for identifying compilers that are not gcc or
msvc, but use the same argument syntax as one of those two compilers such as clang or icc, especially
when they use different syntax on different operating systems.
compiler.get_define()SYNOPSISstr compiler.get_define(
definename,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
)
since 0.40.0
DESCRIPTION
Returns the given preprocessor symbol's value as a string or empty string if it is not defined.
(since0.47.0) This method will concatenate string literals as the compiler would. E.g. `"a" "b"`
will become `"ab"`.
POSARGSdefinenamestr, required
The define to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
compiler.get_id()SYNOPSISstr compiler.get_id()
DESCRIPTION
Returns a string identifying the compiler. For example, `gcc`, `msvc`, andmore[31].
compiler.get_linker_id()SYNOPSISstr compiler.get_linker_id()
since 0.53.0
DESCRIPTION
Returns a string identifying the linker. For example, `ld.bfd`, `link`, andmore[32].
compiler.get_supported_arguments()SYNOPSISlist[str] compiler.get_supported_arguments(
arg...,
checked: 'off',
)
since 0.43.0
DESCRIPTION
Returns an array containing only the arguments supported by the compiler, as if compiler.has_argument
were called on them individually.
VARARGSargstr, 0...N times
The arguments to check.
KWARGScheckedstr, default: 'off', since 0.59.0
Supported values:
- `'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()SYNOPSISlist[str] compiler.get_supported_function_attributes(name...)
since 0.48.0
DESCRIPTION
Returns an array containing any names that are supported GCC style attributes. Equivalent to
compiler.has_function_attribute was called on each of them individually.
VARARGSnamestr, 1...N times
The attribute names to check.
compiler.get_supported_link_arguments()SYNOPSISlist[str] compiler.get_supported_link_arguments(arg...)
since 0.46.0
DESCRIPTION
Returns an array containing only the arguments supported by the compiler, as if
compiler.has_link_argument were called on them individually.
VARARGSargstr, 0...N times
The link arguments to check.
compiler.has_argument()SYNOPSISbool compiler.has_argument(argument, required: false)
DESCRIPTION
Returns `true` if the compiler accepts the specified command line argument, that is, can compile code
without erroring out or printing a warning about an unknown flag.
POSARGSargumentstr, required
The argument to check.
KWARGSrequiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_define()SYNOPSISbool compiler.has_define(
definename,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
)
since 1.3.0
DESCRIPTION
Returns true if the given preprocessor symbol is defined.
POSARGSdefinenamestr, required
The define to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
compiler.has_function()SYNOPSISbool compiler.has_function(
funcname,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Returns true if the given function is provided by the standard library or a library passed in with
the `args` keyword.
POSARGSfuncnamestr, required
The function to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_function_attribute()SYNOPSISbool compiler.has_function_attribute(
name,
required: false,
)
since 0.48.0
DESCRIPTION
Returns `true` if the compiler supports the GNU style (`__attribute__(...)`) `name`. This is
preferable to manual compile checks as it may be optimized for compilers that do not support such
attributes. Thistable[33] lists all of the supported attributes.
POSARGSnamestr, required
The attribute name to check.
KWARGSrequiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_header()SYNOPSISbool compiler.has_header(
header_name,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Returns true if the specified header is exists with the specified prefix, dependencies, and
arguments.
This method is faster than compiler.check_header since it only does a pre-processor check.
POSARGSheader_namestr, required
The header to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 0.50.0
When set to `true`, Meson will halt if the header check fails. When set to a `feature`[0] option,
the feature will control if it is searched and whether to fail if not found.
compiler.has_header_symbol()SYNOPSISbool compiler.has_header_symbol(
header,
symbol,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Detects whether a particular symbol is declared in the specified header.
Symbols here include function, variable, `#define`, type definition, etc.
POSARGSheaderstr, required
The header to check.
symbolstr, required
The symbol to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 0.50.0
When set to `true`, Meson will halt if the header check fails. When set to a `feature`[0] option,
the feature will control if it is searched and whether to fail if not found.
compiler.has_link_argument()SYNOPSISbool compiler.has_link_argument(argument, required: false)
since 0.46.0
DESCRIPTION
Returns `true` if the linker accepts the specified command line argument, that is, can compile and
link code without erroring out or printing a warning about an unknown flag. Link arguments will be
passed to the compiler, so should usually have the `-Wl,` prefix. On VisualStudio a `/link` argument
will be prepended.
POSARGSargumentstr, required
The argument to check.
KWARGSrequiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_member()SYNOPSISbool compiler.has_member(
typename,
membername,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Returns true if the type has the specified member.
POSARGStypenamestr, required
The type to check.
membernamestr, required
The member to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_members()SYNOPSISbool compiler.has_members(
typename,
member...,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Returns `true` if the type has all the specified members.
POSARGStypenamestr, required
The type to check.
VARARGSmemberstr, 1...N times
The members to check
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_multi_arguments()SYNOPSISbool compiler.has_multi_arguments(arg..., required: false)
since 0.37.0
DESCRIPTION
the same as compiler.has_argument but takes multiple arguments and uses them all in a single compiler
invocation.
VARARGSargstr, 0...N times
The arguments to check.
KWARGSrequiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_multi_link_arguments()SYNOPSISbool compiler.has_multi_link_arguments(
arg...,
required: false,
)
since 0.46.0
DESCRIPTION
the same as compiler.has_link_argument but takes multiple arguments and uses them all in a single
compiler invocation.
VARARGSargstr, 0...N times
The link arguments to check.
KWARGSrequiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.has_type()SYNOPSISbool compiler.has_type(
typename,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
required: false,
)
DESCRIPTION
Returns `true` if the specified token is a type.
POSARGStypenamestr, required
The type to check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
requiredbool|feature, default: false, since 1.3.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
compiler.links()SYNOPSISbool compiler.links(
code,
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
)
DESCRIPTION
Returns true if the code compiles and links.
Since0.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.
POSARGScodestr|file, required
The source code to check.
If a string is passed, the code is used directly. If a file object is passed, its content is used
for the compiler check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
namestr
The name to use for printing a message about the compiler check. If this keyword argument is not
passed, no message will be printed about the check.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
requiredbool|feature, default: false, since 1.5.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
werrorbool, default: false, since 1.3.0
When set to `true`, compiler warnings are treated as error.
compiler.preprocess()SYNOPSISlist[custom_idx] compiler.preprocess(
source...,
compile_args:,
dependencies:,
depends:,
include_directories:,
output:,
)
since 0.64.0
DESCRIPTION
Preprocess a list of source files but do not compile them. The preprocessor will receive the same
arguments (include directories, defines, etc) as with normal compilation. That includes for example
args added with `add_project_arguments()`, or on the command line with `-Dc_args=-DFOO`.
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 0...N times
Input source to preprocess. The following types are supported:
- 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.processKWARGScompile_argslist[str]
Extra flags to pass to the preprocessor
dependenciesdep|list[dep], since 1.1.0
Additionally dependencies required.
dependslist[build_tgt|custom_tgt], since 1.4.0
Specifies that this target depends on the specified target(s). These targets should be built before
starting to preprocess an input.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
outputstr
Template for name of preprocessed files: `@PLAINNAME@` is replaced by the source filename and
`@BASENAME@` is replaced by the source filename without its extension.
compiler.run()SYNOPSISrunresult compiler.run(
code,
args:,
dependencies:,
include_directories:,
name:,
no_builtin_args: false,
required: false,
werror: false,
)
DESCRIPTION
Attempts to compile and execute the given code fragment.
POSARGScodestr|file, required
The source code to check.
If a string is passed, the code is used directly. If a file object is passed, its content is used
for the compiler check.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
namestr
The name to use for printing a message about the compiler check. If this keyword argument is not
passed, no message will be printed about the check.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
requiredbool|feature, default: false, since 1.5.0
When set to `true`, Meson will halt if the check fails. When set to a `feature`[0] option, the
feature will control if it is searched and whether to fail if not found.
werrorbool, default: false, since 1.3.0
When set to `true`, compiler warnings are treated as error.
compiler.sizeof()SYNOPSISint compiler.sizeof(
typename,
args:,
dependencies:,
include_directories:,
no_builtin_args: false,
prefix:,
)
DESCRIPTION
returns the size of the given type (e.g. `'int'`) or -1 if the type is unknown. For C-like
languages, the header `stddef.h` and `stdio.h` are included implicitly for native compilation, only
`stddef.h` is included when cross-compiling.
POSARGStypenamestr, required
The type to compute.
KWARGSargslist[str]
Used to pass a list of compiler arguments. Defining include paths for headers not in the default
include path via `-Isome/path/to/header` is generally supported, however, usually not recommended.
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`.
dependenciesdep|list[dep]
Additionally dependencies required for compiling and / or linking.
include_directoriesinc|list[inc], since 0.38.0
Extra directories for header searches.
no_builtin_argsbool, default: false
When set to `true`, the compiler arguments controlled by built-in configuration options are not
added.
prefixstr|list[str]
Used to add `#include`s and other things that are required for the symbol to be declared. Since
1.0.0 an array is accepted too. When an array is passed, the items are concatenated together
separated by a newline. System definitions should be passed via compiler args (eg: `_GNU_SOURCE`
is often required for some symbols to be exposed on Linux, and it should be passed via `args`
keyword argument).
compiler.symbols_have_underscore_prefix()SYNOPSISbool compiler.symbols_have_underscore_prefix()
since 0.37.0
DESCRIPTION
Returns `true` if the C symbol mangling is one underscore (`_`) prefixed to the symbol.
compiler.version()SYNOPSISstr compiler.version()
DESCRIPTION
Returns the compiler's version number as a string.
custom_idx.full_path()SYNOPSISstr custom_idx.full_path()
since 0.54.0
DESCRIPTION
Returns a full path pointing to the result target file NOTE: In most cases using the object itself
will do the same job as this and will also allow Meson to setup inter-target dependencies correctly.
Please file a bug if that doesn't work for you.
See custom_tgt.full_pathcustom_tgt.[index]()SYNOPSIScustom_idx custom_tgt.[index]()
DESCRIPTION
Returns an opaque object that references this target, and can be used as a source in other targets.
When it is used as such it will make that target depend on this custom target, but the only source
added will be the one that corresponds to the index of the custom target's output argument.
custom_tgt.full_path()SYNOPSISstr custom_tgt.full_path()
DESCRIPTION
Returns a full path pointing to the result target file NOTE: In most cases using the object itself
will do the same job as this and will also allow Meson to setup inter-target dependencies correctly.
Please file a bug if that doesn't work for you. (since0.54.0) It can be also called on indexes
objects: `custom_targets[i].full_path()`.
custom_tgt.to_list()SYNOPSISlist[custom_idx] custom_tgt.to_list()
since 0.54.0
DESCRIPTION
Returns a list of opaque objects that references this target, and can be used as a source in other
targets. This can be used to iterate outputs with `foreach` loop.
dep.as_link_whole()SYNOPSISdep dep.as_link_whole()
since 0.56.0
DESCRIPTION
Only dependencies created with declare_dependency, returns a copy of the dependency object with all
link_with arguments changed to link_whole. This is useful for example for fallback dependency from a
subproject built with `default_library=static`. Note that all `link_with` objects must be static
libraries otherwise an error will be raised when trying to `link_whole` a shared library.
dep.as_system()SYNOPSISdep dep.as_system([value])
since 0.52.0
DESCRIPTION
Returns a copy of the dependency object, which has changed the value of `include_type` to `value`.
The `value` argument is optional and defaults to `'system'`.
OPTARGSvaluestr
The new value. See dependency for supported values.
dep.found()SYNOPSISbool dep.found()
DESCRIPTION
Returns whether the dependency was found.
dep.get_configtool_variable()SYNOPSISstr dep.get_configtool_variable(var_name)
deprecated since 0.56.0, since 0.44.0
DESCRIPTION
Gets the command line argument from the config tool (with `--` prepended), or, if invoked on a non
config-tool dependency, error out.
POSARGSvar_namestr, required
Name of the variable to query
dep.get_pkgconfig_variable()SYNOPSISstr dep.get_pkgconfig_variable(
var_name,
default:,
define_variable:,
)
deprecated since 0.56.0, since 0.36.0
DESCRIPTION
Gets the pkg-config variable specified, or, if invoked on a non pkg-config dependency, error out.
POSARGSvar_namestr, required
Name of the variable to query
KWARGSdefaultstr, since 0.45.0
The value to return if the variable was not found. A warning is issued if the variable is not
defined and this kwarg is not set.
define_variablelist[str], since 0.44.0
You can also redefine a variable by passing a list to this kwarg that can affect the retrieved
variable: `['prefix', '/'])`.
(Since1.3.0) Multiple variables can be specified in pairs.
dep.get_variable()SYNOPSISstr dep.get_variable(
[varname],
cmake:,
configtool:,
default_value:,
internal:,
pkgconfig:,
pkgconfig_define:,
)
since 0.51.0
DESCRIPTION
A generic variable getter method, which replaces the `get_type_variable` methods. This allows one to
get the variable from a dependency without knowing specifically how that dependency was found. If
`default_value` is set and the value cannot be gotten from the object then `default_value` is
returned, if it is not set then an error is raised.
OPTARGSvarnamestr, since 0.58.0
This argument is used as a default value for `cmake`, `pkgconfig`, `configtool` and `internal`
keyword arguments. It is useful in the common case where `pkgconfig` and `internal` use the same
variable name, in which case it's easier to write `dep.get_variable('foo')` instead of
`dep.get_variable(pkgconfig: 'foo', internal: 'foo')`.
KWARGScmakestr
The CMake variable name
configtoolstr
The configtool variable name
default_valuestr
The default value to return when the variable does not exist
internalstr, since 0.54.0
The internal variable name
pkgconfigstr
The pkgconfig variable name
pkgconfig_definelist[str]
See dep.get_pkgconfig_variableWARNINGS
Before 1.3.0, specifying multiple pkgconfig_define pairs would silently malform the results. Only the
first variable would be redefined, but its value would contain both the second variable name, as well
as its value.
dep.include_type()SYNOPSISstr dep.include_type()
since 0.52.0
DESCRIPTION
Returns the value set by the `include_type` kwarg.
dep.name()SYNOPSISstr dep.name()
since 0.48.0
DESCRIPTION
Returns the name of the dependency that was searched. Returns `'internal'` for dependencies created
with declare_dependency.
NOTE: This was not implemented for dep objects returned by compiler.find_library until Meson 1.5.0
dep.partial_dependency()SYNOPSISdep dep.partial_dependency(
compile_args: false,
includes: false,
link_args: false,
links: false,
sources: false,
)
since 0.46.0
DESCRIPTION
Returns a new dependency object with the same name, version, found status, type name, and methods as
the object that called it. This new object will only inherit other attributes from its parent as
controlled by keyword arguments.
If the parent has any dependencies, those will be applied to the new partial dependency with the same
rules. So, given:
dep1 = declare_dependency(compile_args : '-Werror=foo', link_with : 'libfoo')
dep2 = declare_dependency(compile_args : '-Werror=bar', dependencies : dep1)
dep3 = dep2.partial_dependency(compile_args : true)
dep3 will add `['-Werror=foo', '-Werror=bar']` to the compiler args of any target it is added to, but
libfoo will not be added to the link_args.
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
KWARGScompile_argsbool, default: false
Whether to include compile_args
includesbool, default: false
Whether to include includes
link_argsbool, default: false
Whether to include link_args
linksbool, default: false
Whether to include links
sourcesbool, default: false
Whether to include sources
WARNINGS
A bug present until 0.50.1 results in the above behavior not working correctly.
dep.type_name()SYNOPSISstr dep.type_name()
DESCRIPTION
Returns a string describing the type of the dependency, the most common values are `internal` for
deps created with declare_dependency and `pkgconfig` for system dependencies obtained with Pkg-
config.
dep.version()SYNOPSISstr dep.version()
DESCRIPTION
the version number as a string, for example `1.2.8`. `unknown` if the dependency provider doesn't
support determining the version.
dict.get()SYNOPSISany dict.get(key, [fallback])
DESCRIPTION
returns the value for the key given as first argument if it is present in the dictionary, or the
optional fallback value given as the second argument. If a single argument was given and the key was
not found, causes a fatal error
POSARGSkeystr, required
The key to query.
OPTARGSfallbackany
Fallback value that is returned if the key is not in the dict.
dict.has_key()SYNOPSISbool dict.has_key(key)
DESCRIPTION
Returns `true` if the dictionary contains the key given as argument, `false` otherwise.
POSARGSkeystr, required
The key to query.
dict.keys()SYNOPSISlist[str] dict.keys()
DESCRIPTION
Returns an array of keys in the dictionary.
disabler.found()SYNOPSISbool disabler.found()
DESCRIPTION
Always returns `false`
env.append()SYNOPSISvoid env.append(variable, Value..., separator:)
DESCRIPTION
appends the given values to the old value of the environment variable, e.g. `env.append('FOO',
´BAR', 'BAZ', separator : ';')` produces `BOB;BAR;BAZ` if `FOO` had the value `BOB` and plain
`BAR;BAZ` if the value was not defined.
POSARGSvariablestr, required
The variable to modify
VARARGSValuestr, 0...N times
The values to append
KWARGSseparatorstr
The separator to use. If not explicitly specified, the default path separator for the host
operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems.
env.prepend()SYNOPSISvoid env.prepend(variable, Value..., separator:)
DESCRIPTION
Same as `append` except that it writes to the beginning of the variable.
POSARGSvariablestr, required
The variable to modify
VARARGSValuestr, 0...N times
The values to prepend
KWARGSseparatorstr
The separator to use. If not explicitly specified, the default path separator for the host
operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems.
env.set()SYNOPSISvoid env.set(variable, Value..., separator:)
DESCRIPTION
Sets the environment variable specified in the first argument to the values in the varargs joined by
the separator. For instance, `env.set('FOO', 'BAR'),` sets envvar `FOO` to value `BAR`.
POSARGSvariablestr, required
The variable to modify
VARARGSValuestr, 0...N times
The values to set
KWARGSseparatorstr
The separator to use. If not explicitly specified, the default path separator for the host
operating system will be used, i.e. ';' for Windows and ':' for UNIX/POSIX systems.
env.unset()SYNOPSISvoid env.unset()
since 1.4.0
DESCRIPTION
Unset the specified environment variable. If this variable does not exist, nothing happens.
external_program.found()SYNOPSISbool external_program.found()
DESCRIPTION
Returns whether the executable was found.
external_program.full_path()SYNOPSISstr external_program.full_path()
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:
run_command(find_program('foo'), 'arg1', 'arg2')
external_program.path()SYNOPSISstr external_program.path()
deprecated since 0.55.0
DESCRIPTIONDeprecated: Use external_program.full_path instead.
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:
run_command(find_program('foo'), 'arg1', 'arg2')
external_program.version()SYNOPSISstr external_program.version()
since 0.62.0
DESCRIPTION
The version number as a string, for example `1.2.8`.
`unknown` if the program cannot determine the version via a `--version` argument.
feature.allowed()SYNOPSISbool feature.allowed()
since 0.59.0
DESCRIPTION
Returns whether the feature was set to `'enabled'` or `'auto'`
feature.auto()SYNOPSISbool feature.auto()
DESCRIPTION
Returns whether the feature was set to `'auto'`
feature.disable_auto_if()SYNOPSISfeature feature.disable_auto_if(value)
since 0.59.0
DESCRIPTION
Returns the feature, with `'auto'` converted to `'disabled'` if value is true.
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | |
Auto | Disabled | Auto | | Enabled | Enabled | Enabled | |
Disabled | Disabled | Disabled |
POSARGSvaluebool, required
See the table above
EXAMPLE
`disable_auto_if` is useful to give precedence to mutually exclusive dependencies (that provide the
same API) if either or both are available:
# '-Dfoo=auto -Dbar=enabled' will not pick foo even if installed.
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()SYNOPSISfeature feature.disable_if(value, error_message: '')
since 1.1.0
DESCRIPTION
Returns the object itself if the value is false; an error if the object is `'enabled'` and the value
is true; a disabled feature if the object is `'auto'` or `'disabled'` and the value is true.
| 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`
POSARGSvaluebool, required
The value to check
KWARGSerror_messagestr, default: ''
The error message to print if the check fails
EXAMPLE
`disable_if` is useful to restrict the applicability of `'auto'` features, particularly when passing
them to dependency:
use_os_feature = get_option('foo') .br
.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()SYNOPSISbool feature.disabled()
DESCRIPTION
Returns whether the feature was set to `'disabled'`
feature.enable_auto_if()SYNOPSISfeature feature.enable_auto_if(value)
since 1.1.0
DESCRIPTION
Returns the feature, with `'auto'` converted to `'enabled'` if value is true.
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | |
Auto | Enabled | Auto | | Enabled | Enabled | Enabled | |
Disabled | Disabled | Disabled |
POSARGSvaluebool, required
See the table above
feature.enable_if()SYNOPSISfeature feature.enable_if(value, error_message: '')
since 1.1.0
DESCRIPTION
Returns the object itself if the value is false; an error if the object is `'disabled'` and the value
is true; an enabled feature if the object is `'auto'` or `'enabled'` and the value is true.
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | |
Auto | Enabled | Auto | | Enabled | Enabled | Enabled | |
Disabled | Error | Disabled |
POSARGSvaluebool, required
The value to check
KWARGSerror_messagestr, default: ''
The error message to print if the check fails
EXAMPLE
`enable_if` is useful to restrict the applicability of `'auto'` features, particularly when passing
them to dependency:
use_llvm = get_option('llvm').enable_if(with_clang).enable_if(with_llvm_libs)
dep_llvm = dependency('llvm', required: use_llvm)
feature.enabled()SYNOPSISbool feature.enabled()
DESCRIPTION
Returns whether the feature was set to `'enabled'`
feature.require()SYNOPSISfeature feature.require(value, error_message: '')
since 0.59.0
DESCRIPTION
Returns the object itself if the value is true; an error if the object is `'enabled'` and the value
is false; a disabled feature if the object is `'auto'` or `'disabled'` and the value is false.
| Feature | `value = true` | `value = false` | | -------- | -------------- | --------------- | |
Auto | Auto | Disabled | | Enabled | Enabled | Error | |
Disabled | Disabled | Disabled |
POSARGSvaluebool, required
The value to check
KWARGSerror_messagestr, default: ''
The error message to print if the check fails
EXAMPLE
`require` is useful to restrict the applicability of `'auto'` features, for example based on other
features or on properties of the host machine:
if get_option('directx').require(host_machine.system() == 'windows',
error_message: 'DirectX only available on Windows').allowed() then
src += ['directx.c']
config.set10('HAVE_DIRECTX', true)
endif
file.full_path()SYNOPSISstr file.full_path()
since 1.4.0
DESCRIPTION
Returns a full path pointing to the file. This is useful for printing the path with e.g message
function for debugging purpose. NOTE: In most cases using the object itself will do the same job as
this and will also allow Meson to setup dependencies correctly.
generator.process()SYNOPSISgenerated_list generator.process(
source...,
env:,
extra_args:,
preserve_path_from:,
)
DESCRIPTION
Takes a list of files, causes them to be processed and returns an object containing the result which
can then, for example, be passed into a build target definition.
VARARGSsourcestr|file|custom_tgt|custom_idx|generated_list, 1...N times
List of sources to process.
KWARGSenvenv|list[str]|dict[str], since 1.3.0
environment variables to set, such as `{'NAME1': 'value1', 'NAME2': 'value2'}` or `['NAME1=value1',
'NAME2=value2']`, or an env object which allows more sophisticated environment juggling.
extra_argslist[str]
If present, will be used to replace an entry `@EXTRA_ARGS@` in the argument list.
preserve_path_fromstr, since 0.45.0
If given, specifies that the output files need to maintain their directory structure inside the
target temporary directory. The most common value for this is `meson.current_source_dir()`. With
this value when a file called `subdir/one.input` is processed it generates a file `{target private
directory}/subdir/one.out` as opposed to `{target private directory}/one.out`.
int.is_even()SYNOPSISbool int.is_even()
DESCRIPTION
Returns true if the number is even.
int.is_odd()SYNOPSISbool int.is_odd()
DESCRIPTION
Returns true if the number is odd
int.to_string()SYNOPSISstr int.to_string([fill])
DESCRIPTION
Returns the value of the number as a string.
OPTARGSfillint
Left fill the string with zeros until it reaches the length specified by this argument. A leading
negative sign counts towards the length, and is handled by inserting the padding after the `-`
character rather than before. The original string is returned if the value provided is less than or
equal to the former's length.
list.contains()SYNOPSISbool list.contains(item)
DESCRIPTION
Returns `true` if the array contains the object given as argument, `false` otherwise
POSARGSitemany, required
The item to check
list.get()SYNOPSISany list.get(index, [fallback])
DESCRIPTION
returns the object at the given index, negative indices count from the back of the array, indexing
out of bounds returns the `fallback` value (since0.38.0) or, if it is not specified, causes a fatal
error
POSARGSindexint, required
Index of the list position to query. Negative values start at the end of the list
OPTARGSfallbackany
Fallback value that is returned if the index is out of range.
list.length()SYNOPSISint list.length()
DESCRIPTION
Returns the current size of the array / list.
meson.add_devenv()SYNOPSISvoid meson.add_devenv(env, method:, separator:)
since 0.58.0
DESCRIPTION
add an env object (returned by environment) to the list of environments that will be applied when
using `mesondevenv`[34] command line.
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 = environment()
devenv.set('PLUGINS_PATH', meson.current_build_dir())
meson.add_devenv(devenv)
After configuring and compiling that project, a terminal can be opened with the environment set:
sh
$ meson devenv -C <builddir>
$ echo $PLUGINS_PATH
/path/to/source/subdir
See `mesondevenv`[33] command documentation for a list of environment variables that are set by
default by Meson.
POSARGSenvenv|str|list[str]|dict[str]|dict[list[str]], required
The env object to add. Since 0.62.0 list of strings is allowed in dictionary values. In that case
values are joined using the separator.
KWARGSmethodstr, since 0.62.0
Must be one of 'set', 'prepend', or 'append' (defaults to 'set'). Controls if initial values
defined in the first positional argument are prepended, appended or replace the current value of
the environment variable.
separatorstr, since 0.62.0
The separator to use for the initial values defined in the first positional argument. If not
explicitly specified, the default path separator for the host operating system will be used, i.e.
';' for Windows and ':' for UNIX/POSIX systems.
meson.add_dist_script()SYNOPSISvoid meson.add_dist_script(script_name, arg...)
since 0.48.0
DESCRIPTION
Causes the script given as argument to run during `dist` operation after the distribution source has
been generated but before it is archived. Note that this runs the script file that is in the
_staging_ directory, not the one in the source directory. If the script file cannot be found in the
staging directory, it is a hard error. The `MESON_DIST_ROOT` environment variables is set when dist
scripts is run.
(since0.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.
(since0.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>`.
(since1.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.
POSARGSscript_namestr|file|external_program, required
The script to execute.
(since0.55.0) The output of find_program as well as strings are accepted.
(since0.57.0)file objects and the output of configure_file may be used.
VARARGSargstr|file|external_program, 0...N times, since 0.49.0
Additional arguments
(since0.55.0) The output of configure_file, files, and find_program as well as strings are
accepted.
meson.add_install_script()SYNOPSISvoid meson.add_install_script(
script_name,
arg...,
dry_run: false,
install_tag:,
skip_if_destdir: false,
)
DESCRIPTION
Causes the script given as an argument to be run during the install step, this script will have the
environment variables `MESON_SOURCE_ROOT`, `MESON_BUILD_ROOT`, `MESON_INSTALL_PREFIX`,
`MESON_INSTALL_DESTDIR_PREFIX`, and `MESONINTROSPECT` set. All positional arguments are passed as
parameters.
(since0.54.0) If `meson install` is called with the `--quiet` option, the environment variable
`MESON_INSTALL_QUIET` will be set.
(since1.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.
POSARGSscript_namestr|file|external_program|exe, required
The script to execute.
(since0.55.0) The output of find_program, executable, custom_target, as well as strings are
accepted.
(since0.57.0)file objects and the output of configure_file may be used.
VARARGSargstr|file|external_program|exe|custom_tgt|custom_idx, 0...N times, since 0.49.0
Additional arguments
(since0.55.0) The output of find_program, executable, custom_target, as well as strings are
accepted.
KWARGSdry_runbool, default: false, since 1.1.0
If `true` the script will be run even if `--dry-run` option is provided to the `meson install`
command. The script can use the `MESON_INSTALL_DRY_RUN` variable to determine if it is in dry run
mode or not.
install_tagstr, since 0.60.0
A string used by the `meson install --tags` command to install only a subset of the files. By
default the script has no install tag which means it is not being run when `meson install --tags`
argument is specified.
skip_if_destdirbool, default: false, since 0.57.0
If `true` the script will not be run if DESTDIR is set during installation. This is useful in the
case the script updates system wide cache that is only needed when copying files into final
destination.
meson.add_postconf_script()SYNOPSISvoid meson.add_postconf_script(script_name, arg...)
DESCRIPTION
Runs the given command after all project files have been generated. This script will have the
environment variables `MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT` set.
POSARGSscript_namestr|file|external_program, required
The script to execute.
(since0.55.0) The output of find_program as well as strings are accepted.
(since0.57.0)file objects and the output of configure_file may be used.
VARARGSargstr|file|external_program, 0...N times, since 0.49.0
Additional arguments
(since0.55.0) The output of configure_file, files, and find_program as well as strings are
accepted.
meson.backend()SYNOPSISstr meson.backend()
since 0.37.0
DESCRIPTION
Returns a string representing the current backend:
- `ninja`
- `vs2010`
- `vs2012`
- `vs2013`
- `vs2015`
- `vs2017`
- `vs2019`
- `vs2022`
- `xcode`
meson.build_options()SYNOPSISstr meson.build_options()
since 1.1.0
DESCRIPTION
Returns a string with the configuration line used to set the current project up.
NOTES
Do not try to parse this string!
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()SYNOPSISstr meson.build_root()
deprecated since 0.56.0
DESCRIPTION
Returns a string with the absolute path to the build root directory. This function will return the
build root of the parent project if called from a subproject, which is usually not what you want. Try
using meson.current_build_dir or meson.project_build_root. In the rare cases where the root of the
main project is needed, use meson.global_build_root that has the same behaviour but with a more
explicit name.
meson.can_run_host_binaries()SYNOPSISbool meson.can_run_host_binaries()
since 0.55.0
DESCRIPTION
Returns true if the build machine can run binaries compiled for the host. This returns `true` unless
you are cross compiling, need a helper to run host binaries, and don't have one. For example when
cross compiling from Linux to Windows, one can use `wine` as the helper.
meson.current_build_dir()SYNOPSISstr meson.current_build_dir()
DESCRIPTION
Returns a string with the absolute path to the current build directory.
meson.current_source_dir()SYNOPSISstr meson.current_source_dir()
DESCRIPTION
Returns a string to the current source directory.
NOTES
You do not need to use this function!
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()SYNOPSIScompiler meson.get_compiler(language, native: false)
DESCRIPTION
Returns a compiler object describing a compiler.
POSARGSlanguagestr, required
The language of the compiler to return.
See our listofsupportedlanguages[35].
KWARGSnativebool, default: false
When set to `true` Meson returns the compiler for the build machine (the "native" compiler) and
when `false` it returns the host compiler (the "cross" compiler). If `native` is omitted, Meson
returns the "cross" compiler if we're currently cross-compiling and the "native" compiler if we're
not.
meson.get_cross_property()SYNOPSISany meson.get_cross_property(propname, [fallback_value])
deprecated since 0.58.0
DESCRIPTION
Returns the given property from a cross file, the optional fallback_value is returned if not cross
compiling or the given property is not found.
This method is replaced by meson.get_external_property.
POSARGSpropnamestr, required
Name of the property in the cross / native file.
OPTARGSfallback_valueany
Value to return if `propname` is not set in the machine file.
meson.get_external_property()SYNOPSISany meson.get_external_property(
propname,
[fallback_value],
native:,
)
since 0.54.0
DESCRIPTION
Returns the given property from a native or cross file. The optional fallback_value is returned if
the given property is not found.
POSARGSpropnamestr, required
Name of the property in the cross / native file.
OPTARGSfallback_valueany
Value to return if `propname` is not set in the machine file.
KWARGSnativebool
Setting `native` to `true` forces retrieving a variable from the native file, even when cross-
compiling. If `native: false` or not specified, the variable is retrieved from the cross-file if
cross-compiling, and from the native-file when not cross-compiling.
meson.global_build_root()SYNOPSISstr meson.global_build_root()
since 0.58.0
DESCRIPTION
Returns a string with the absolute path to the build root directory. This function will return the
build root of the main project if called from a subproject, which is usually not what you want. It
is usually preferable to use meson.current_build_dir or meson.project_build_root.
meson.global_source_root()SYNOPSISstr meson.global_source_root()
since 0.58.0
DESCRIPTION
Returns a string with the absolute path to the source root directory. This function will return the
source root of the main project if called from a subproject, which is usually not what you want. It
is usually preferable to use meson.current_source_dir or meson.project_source_root.
meson.has_exe_wrapper()SYNOPSISbool meson.has_exe_wrapper()
deprecated since 0.55.0
DESCRIPTION
Use meson.can_run_host_binaries instead.
meson.has_external_property()SYNOPSISbool meson.has_external_property(propname, native:)
since 0.58.0
DESCRIPTION
Checks whether the given property exist in a native or cross file.
POSARGSpropnamestr, required
Name of the property in the cross / native file.
KWARGSnativebool
Setting `native` to `true` forces retrieving a variable from the native file, even when cross-
compiling. If `native: false` or not specified, the variable is retrieved from the cross-file if
cross-compiling, and from the native-file when not cross-compiling.
meson.install_dependency_manifest()SYNOPSISvoid meson.install_dependency_manifest(output_name)
DESCRIPTION
Installs a manifest file containing a list of all subprojects, their versions and license names to
the file name given as the argument.
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`.
POSARGSoutput_namestr, required
Name of the manifest file to install
meson.is_cross_build()SYNOPSISbool meson.is_cross_build()
DESCRIPTION
Returns `true` if the current build is a crossbuild[36] and `false` otherwise.
meson.is_subproject()SYNOPSISbool meson.is_subproject()
DESCRIPTION
Returns `true` if the current project is being built as a subproject of some other project and
`false` otherwise.
meson.is_unity()SYNOPSISbool meson.is_unity()
DESCRIPTION
Returns `true` when doing a unitybuild[37] (multiple sources are combined before compilation to
reduce build time) and `false` otherwise.
meson.override_dependency()SYNOPSISvoid meson.override_dependency(
name,
dep_object,
native: false,
static:,
)
since 0.54.0
DESCRIPTION
Specifies that whenever dependency with `name` is used, Meson should not look it up on the system but
instead return `dep_object`, which may either be the result of dependency or declare_dependency.
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)`.
POSARGSnamestr, required
The name of the dependency to override.
dep_objectdep, required
The dependency to set as the override for `name`.
KWARGSnativebool, default: false
If set to `true`, the dependency is always overwritten for the build machine. Otherwise, the
dependency is overwritten for the host machine, which differs from the build machine when cross-
compiling.
staticbool, since 0.60.0
Used to override static and/or shared dependencies separately. If not specified it is assumed
`dep_object` follows `default_library` option value.
meson.override_find_program()SYNOPSISvoid meson.override_find_program(progname, program)
since 0.46.0
DESCRIPTION
specifies that whenever find_program is used to find a program named `progname`, Meson should not
look it up on the system but instead return `program`, which may either be the result of
find_program, configure_file or executable.
(since0.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.
POSARGSprognamestr, required
The name of the program to override.
programexe|file|external_program, required
The program to set as the override for `progname`.
meson.project_build_root()SYNOPSISstr meson.project_build_root()
since 0.56.0
DESCRIPTION
Returns a string with the absolute path to the build root directory of the current (sub)project.
meson.project_license()SYNOPSISlist[str] meson.project_license()
since 0.45.0
DESCRIPTION
Returns the array of licenses specified in project function call.
meson.project_license_files()SYNOPSISlist[file] meson.project_license_files()
since 1.1.0
DESCRIPTION
Returns the array of license files specified in the project function call.
meson.project_name()SYNOPSISstr meson.project_name()
DESCRIPTION
Returns the project name specified in the project function call.
meson.project_source_root()SYNOPSISstr meson.project_source_root()
since 0.56.0
DESCRIPTION
Returns a string with the absolute path to the source root directory of the current (sub)project.
meson.project_version()SYNOPSISstr meson.project_version()
DESCRIPTION
Returns the version string specified in project function call.
meson.source_root()SYNOPSISstr meson.source_root()
deprecated since 0.56.0
DESCRIPTION
Returns a string with the absolute path to the source root directory.
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
You should use the files function to refer to files in the root source directory instead of
constructing paths manually with meson.source_root.
meson.version()SYNOPSISstr meson.version()
DESCRIPTION
Return a string with the version of Meson.
module.found()SYNOPSISbool module.found()
since 0.59.0
DESCRIPTION
Returns `true` if the module was successfully imported, otherwise `false`.
runresult.compiled()SYNOPSISbool runresult.compiled()
DESCRIPTION
If `true`, the compilation succeeded, if `false` it did not and the other methods return unspecified
data. This is only available for `compiler.run()` results.
runresult.returncode()SYNOPSISint runresult.returncode()
DESCRIPTION
The return code of executing the compiled binary
runresult.stderr()SYNOPSISstr runresult.stderr()
DESCRIPTION
The standard error produced when the command was run.
runresult.stdout()SYNOPSISstr runresult.stdout()
DESCRIPTION
The standard out produced when the command was run.
str.contains()SYNOPSISbool str.contains(fragment)
DESCRIPTION
Returns `true` if string contains the string specified as the argument.
POSARGSfragmentstr, required
The string fragment to check
EXAMPLE
target = 'x86_FreeBSD'
is_fbsd = target.to_lower().contains('freebsd')
# is_fbsd now has the boolean value 'true'
str.endswith()SYNOPSISbool str.endswith(fragment)
DESCRIPTION
Returns true if string ends with the string specified as the argument.
POSARGSfragmentstr, required
The string fragment to check
EXAMPLE
target = 'x86_FreeBSD'
is_bsd = target.to_lower().endswith('bsd') # boolean value 'true'
str.format()SYNOPSISstr str.format(fmt, value...)
DESCRIPTION
Strings can be built using the string formatting functionality.
See theMesonsyntaxentry[38] for more information.
Since1.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.
POSARGSfmtstr, required
The string to format.
The formatting works by replacing placeholders of type `@number@` with the corresponding varargs.
VARARGSvalueint|bool|str, 0...N times
The values to replace the @number@ placeholders in the format string.
EXAMPLE
template = 'string: @0@, number: @1@, bool: @2@'
res = template.format('text', 1, true)
# res now has value 'string: text, number: 1, bool: true'
str.join()SYNOPSISstr str.join(strings...)
DESCRIPTION
The opposite of split, for example `'.'.join(['a', 'b', 'c']` yields `'a.b.c'`.
VARARGSstringsstr, 0...N times, since 0.60.0
The strings to join with the current string.
Before Meson 0.60.0 this function only accepts a single positional argument of the type list[str].
EXAMPLE
# Similar to the Python str.join()
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()SYNOPSISstr str.replace(old, new)
since 0.58.0
DESCRIPTION
Search all occurrences of `old` and replace it with `new`
POSARGSoldstr, required
The substring to search
newstr, required
The replacement string
EXAMPLE
# Replaces all instances of one substring with another
s = 'semicolons;as;separators'
s = s.replace('as', 'are')
# 's' now has the value of 'semicolons;are;separators'
str.split()SYNOPSISlist[str] str.split([split_string])
DESCRIPTION
Splits the string at the specified character (or whitespace if not set) and returns the parts in an
array.
OPTARGSsplit_stringstr
Specifies the character / substring where to split the string.
EXAMPLE
# Similar to the Python str.split()
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()SYNOPSISlist[str] str.splitlines()
since 1.2.0
DESCRIPTION
Splits the string into an array of lines. Unlike .split('0), the empty string produced an empt'
array0 are alltconsideredenewlines.newline, splitlines() doesn't split on that last newline. ´0, '
and '
EXAMPLE
output = 'hello0orld0.splitlines()
# 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()SYNOPSISbool str.startswith(fragment)
DESCRIPTION
Returns true if string starts with the string specified as the argument.
POSARGSfragmentstr, required
The string fragment to check
EXAMPLE
target = 'x86_FreeBSD'
is_x86 = target.startswith('x86') # boolean value 'true'
str.strip()SYNOPSISstr str.strip([strip_chars])
DESCRIPTION
Removes leading/ending characters from the string.
By default the characters to remove are spaces and newlines.
OPTARGSstrip_charsstr, since 0.43.0
Instead of whitespace, strip all the characters in this string.
EXAMPLE
# Similar to the Python str.strip(). Removes leading/ending spaces and newlines
define = ' -Dsomedefine '
stripped_define = define.strip()
# 'stripped_define' now has the value '-Dsomedefine'
str.substring()SYNOPSISstr str.substring([start], [end])
since 0.56.0
DESCRIPTION
Returns a substring specified from `start` to `end`. Both `start` and `end` arguments are optional,
so, for example, `'foobar'.substring()` will return `'foobar'`.
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.
OPTARGSstartint
The start position
endint
The end position
EXAMPLE
# Similar to the Python str[start:end] syntax
target = 'x86_FreeBSD'
platform = target.substring(0, 3) # prefix string value 'x86'
system = target.substring(4) # suffix string value 'FreeBSD'
Example with negative values:
string = 'foobar'
string.substring(-5, -3) # => 'oo'
string.substring(1, -1) # => 'ooba'
Example with out of bound values:
string = 'foobar'
string.substring(64) # => ''
string.substring(0, 64) # => 'foobar'
string.substring(64, 0) # => ''
str.to_int()SYNOPSISint str.to_int()
DESCRIPTION
Converts the string to an int and throws an error if it can't be
EXAMPLE
version = '1'
# Converts the string to an int and throws an error if it can't be
ver_int = version.to_int()
str.to_lower()SYNOPSISstr str.to_lower()
DESCRIPTION
Converts all characters to lower case
EXAMPLE
target = 'x86_FreeBSD'
lower = target.to_lower() # t now has the value 'x86_freebsd'
str.to_upper()SYNOPSISstr str.to_upper()
DESCRIPTION
Converts all characters to upper case
EXAMPLE
target = 'x86_FreeBSD'
upper = target.to_upper() # t now has the value 'X86_FREEBSD'
str.underscorify()SYNOPSISstr str.underscorify()
DESCRIPTION
Creates a string where every non-alphabetical non-number character is replaced with `_`.
EXAMPLE
name = 'Meson Docs.txt#Reference-manual'
# 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()SYNOPSISbool str.version_compare(compare_string)
DESCRIPTION
Does semantic version comparison.
POSARGScompare_stringstr, required
The string to compare to.
EXAMPLE
version = '1.2.3'
# Compare version numbers semantically
is_new = version.version_compare('>=2.0')
# is_new now has the boolean value false
# Supports the following operators: '>', '<', '>=', '<=', '!=', '==', '='
Meson version comparison conventions include:
´3.6'.version_compare('>=3.6.0') == false
It is best to be unambiguous and specify the full revision level to compare.
subproject.found()SYNOPSISbool subproject.found()
since 0.48.0
DESCRIPTION
Returns whether the subproject was successfully setup.
subproject.get_variable()SYNOPSISany subproject.get_variable(var_name, [fallback])
DESCRIPTION
fetches the specified variable from inside the subproject. This is useful to, for instance, get a
declare_dependency from the subproject[25].
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.
POSARGSvar_namestr, required
The name of the variable to query
OPTARGSfallbackany
The fallback value to return if `var_name` does not exist.