Meson object (meson)

The meson object allows you to introspect various properties of the system. This object is always mapped in the meson variable.

Meson object methods

meson.add_devenv()

add an (追記) env (追記ここまで) object (returned by (追記) environment() (追記ここまで)) to the list of environments that will be applied when using meson devenv 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:

$ meson devenv -C <builddir>
$ echo $PLUGINS_PATH
/path/to/source/subdir

See meson devenv command documentation for a list of environment variables that are set by default by Meson.

Signature

(since 0.58.0)

# add an (追記) env (追記ここまで) object (returned by (追記) environment() (追記ここまで))
(追記) void (追記ここまで) add_devenv(
 (追記) env (追記ここまで) | (追記) str (追記ここまで) | (追記) array (追記ここまで)[(追記) str (追記ここまで)] | (追記) dict (追記ここまで)[(追記) str (追記ここまで)] | (追記) dict (追記ここまで)[(追記) array (追記ここまで)[(追記) str (追記ここまで)]] env, # The (追記) env (追記ここまで) object to add.
 # Keyword arguments:
 method : (追記) str (追記ここまで) # Must be one of 'set', 'prepend', or 'append'
 separator : (追記) str (追記ここまで) # The separator to use for the initial values defined in
)

Arguments

The method meson.add_devenv() accepts the following positional arguments:

Name Type Description Tags
env (追記) env (追記ここまで) | (追記) str (追記ここまで) | (追記) array (追記ここまで)[(追記) str (追記ここまで)] | (追記) dict (追記ここまで)[(追記) str (追記ここまで)] | (追記) dict (追記ここまで)[(追記) array (追記ここまで)[(追記) str (追記ここまで)]]

The (追記) env (追記ここまで) object to add. Since 0.62.0 array of strings is allowed in dictionary values. In that case values are joined using the separator.

Finally, meson.add_devenv() accepts the following keyword arguments:

Name Type Description Tags
method (追記) str (追記ここまで)

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

(since 0.62.0)

separator (追記) str (追記ここまで)

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

(since 0.62.0)


meson.add_dist_script()

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.

(since 0.54.0) The MESON_SOURCE_ROOT and MESON_BUILD_ROOT environment variables are set when dist scripts are run. They are path to the root source and build directory of the main project, even when the script comes from a subproject.

(since 0.58.0) This command can be invoked from a subproject, it was a hard error in earlier versions. Subproject dist scripts will only be executed when running meson dist --include-subprojects. MESON_PROJECT_SOURCE_ROOT, MESON_PROJECT_BUILD_ROOT and MESON_PROJECT_DIST_ROOT environment variables are set when dist scripts are run. They are identical to MESON_SOURCE_ROOT, MESON_BUILD_ROOT and MESON_DIST_ROOT for main project scripts, but for subproject scripts they have the path to the root of the subproject appended, usually subprojects/<subproject-name>.

(since 1.4.0) The MESONREWRITE environment variable contains the path to the rewrite command that corresponds to the meson executable that was used to configure the build. (This might be a different path than the first executable found in PATH.) It can be used to remove or replace any (追記) run_command() (追記ここまで) that depends on the revision control system from the build configuration. Note that the value will contain many parts. For example, it may be python3 /path/to/meson.py introspect. The user is responsible for splitting the string to an array if needed by splitting lexically like a UNIX shell would. If your script uses Python, shlex.split() is the easiest correct way to do this.

Signature

(since 0.48.0)

# Causes the script given as argument to run during `dist`
(追記) void (追記ここまで) add_dist_script(
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) script_name, # The script to execute
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) arg..., # Additional arguments
)

Arguments

The method meson.add_dist_script() accepts the following positional arguments:

Name Type Description Tags
script_name (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで)

The script to execute.

(since 0.55.0) The output of (追記) find_program() (追記ここまで) as well as strings are accepted.

(since 0.57.0) (追記) file (追記ここまで) objects and the output of (追記) configure_file() (追記ここまで) may be used.

Additionally, the method accepts between 0 and infinity variadic arguments (arg...) of type (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) .

Additional arguments

(since 0.55.0) The output of (追記) configure_file() (追記ここまで), (追記) files() (追記ここまで), and (追記) find_program() (追記ここまで) as well as strings are accepted.

(since 0.49.0)


meson.add_install_script()

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.

(since 0.54.0) If meson install is called with the --quiet option, the environment variable MESON_INSTALL_QUIET will be set.

(since 1.1.0) If meson install is called with the --dry-run option, the environment variable MESON_INSTALL_DRY_RUN will be set.

Meson uses the DESTDIR environment variable as set by the inherited environment to determine the (temporary) installation location for files. Your install script must be aware of this while manipulating and installing files. The correct way to handle this is with the MESON_INSTALL_DESTDIR_PREFIX variable which is always set and contains DESTDIR (if set) and prefix joined together. This is useful because both are usually absolute paths and there are platform-specific edge-cases in joining two absolute paths.

In case it is needed, MESON_INSTALL_PREFIX is also always set and has the value of the prefix option passed to Meson.

MESONINTROSPECT contains the path to the introspect command that corresponds to the meson executable that was used to configure the build. (This might be a different path than the first executable found in PATH.) It can be used to query build configuration. Note that the value will contain many parts, f.ex., it may be python3 /path/to/meson.py introspect. The user is responsible for splitting the string to an array if needed by splitting lexically like a UNIX shell would. If your script uses Python, shlex.split() is the easiest correct way to do this.

Signature

# Causes the script given as an argument to be run during the install step,
(追記) void (追記ここまで) add_install_script(
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) | (追記) exe (追記ここまで) | (追記) custom_tgt (追記ここまで) | (追記) custom_idx (追記ここまで) script_name, # The script to execute
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) | (追記) exe (追記ここまで) | (追記) custom_tgt (追記ここまで) | (追記) custom_idx (追記ここまで) arg..., # Additional arguments
 # Keyword arguments:
 dry_run : (追記) bool (追記ここまで) # If `true` the script will be run even if `--dry-run` option is provided to
 install_tag : (追記) str (追記ここまで) # A string used by the `meson install --tags` command
 skip_if_destdir : (追記) bool (追記ここまで) # If `true` the script will not be run if DESTDIR is set during installation
)

Arguments

The method meson.add_install_script() accepts the following positional arguments:

Name Type Description Tags
script_name (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) | (追記) exe (追記ここまで) | (追記) custom_tgt (追記ここまで) | (追記) custom_idx (追記ここまで)

The script to execute.

(since 0.55.0) The output of (追記) find_program() (追記ここまで), (追記) executable() (追記ここまで), (追記) custom_target() (追記ここまで), as well as strings are accepted.

(since 0.57.0) (追記) file (追記ここまで) objects and the output of (追記) configure_file() (追記ここまで) may be used.

Additionally, the method accepts between 0 and infinity variadic arguments (arg...) of type (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) | (追記) exe (追記ここまで) | (追記) custom_tgt (追記ここまで) | (追記) custom_idx (追記ここまで) .

Additional arguments

(since 0.55.0) The output of (追記) find_program() (追記ここまで), (追記) executable() (追記ここまで), (追記) custom_target() (追記ここまで), as well as strings are accepted.

(since 0.49.0)

Finally, meson.add_install_script() accepts the following keyword arguments:

Name Type Description Tags
dry_run (追記) bool (追記ここまで)

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.

(since 1.1.0)

default = false

install_tag (追記) str (追記ここまで)

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.

(since 0.60.0)

skip_if_destdir (追記) bool (追記ここまで)

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.

(since 0.57.0)

default = false


meson.add_postconf_script()

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.

Signature

# Runs the given command after all project files have been generated
(追記) void (追記ここまで) add_postconf_script(
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) script_name, # The script to execute
 (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) arg..., # Additional arguments
)

Arguments

The method meson.add_postconf_script() accepts the following positional arguments:

Name Type Description Tags
script_name (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで)

The script to execute.

(since 0.55.0) The output of (追記) find_program() (追記ここまで) as well as strings are accepted.

(since 0.57.0) (追記) file (追記ここまで) objects and the output of (追記) configure_file() (追記ここまで) may be used.

Additionally, the method accepts between 0 and infinity variadic arguments (arg...) of type (追記) str (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) .

Additional arguments

(since 0.55.0) The output of (追記) configure_file() (追記ここまで), (追記) files() (追記ここまで), and (追記) find_program() (追記ここまで) as well as strings are accepted.

(since 0.49.0)


meson.backend()

Returns a string representing the current backend:

  • ninja
  • vs2010
  • vs2012
  • vs2013
  • vs2015
  • vs2017
  • vs2019
  • vs2022
  • xcode

Signature

(since 0.37.0)

(追記) str (追記ここまで) backend()

meson.build_options()

Returns a string with the configuration line used to set the current project up.

Signature

(since 1.1.0)

(追記) str (追記ここまで) build_options()

meson.build_root()

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.

Signature

DEPRECATED

in 0.56.0

(追記) str (追記ここまで) build_root()

meson.can_run_host_binaries()

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.

Signature

(since 0.55.0)

(追記) bool (追記ここまで) can_run_host_binaries()

meson.current_build_dir()

Returns a string with the absolute path to the current build directory.

Signature

(追記) str (追記ここまで) current_build_dir()

meson.current_source_dir()

Returns a string to the current source directory.

Signature

(追記) str (追記ここまで) current_source_dir()

meson.get_compiler()

Returns a (追記) compiler (追記ここまで) object describing a compiler.

Signature

# Returns a (追記) compiler (追記ここまで) object describing a compiler.
(追記) compiler (追記ここまで) get_compiler(
 (追記) str (追記ここまで) language, # The language of the compiler to return
 # Keyword arguments:
 native : (追記) bool (追記ここまで) # When set to `true` Meson returns the compiler for the build
)

Arguments

The method meson.get_compiler() accepts the following positional arguments:

Name Type Description Tags
language (追記) str (追記ここまで)

The language of the compiler to return.

See our list of supported languages.

Finally, meson.get_compiler() accepts the following keyword arguments:

Name Type Description Tags
native (追記) bool (追記ここまで)

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.

default = false


meson.get_cross_property()

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() (追記ここまで).

Signature

DEPRECATED

in 0.58.0

# Returns the given property from a cross file, the optional fallback_value
(追記) any (追記ここまで) get_cross_property(
 (追記) str (追記ここまで) propname, # Name of the property in the cross / native file
 (追記) any (追記ここまで) [fallback_value], # Value to return if `propname` is not set in the machine file
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The method meson.get_cross_property() accepts the following positional arguments:

Name Type Description Tags
propname (追記) str (追記ここまで)

Name of the property in the cross / native file.

fallback_value (追記) any (追記ここまで)

Value to return if propname is not set in the machine file.

[optional]


meson.get_external_property()

Returns the given property from a native or cross file. The optional fallback_value is returned if the given property is not found.

Signature

(since 0.54.0)

# Returns the given property from a native or cross file
(追記) any (追記ここまで) get_external_property(
 (追記) str (追記ここまで) propname, # Name of the property in the cross / native file
 (追記) any (追記ここまで) [fallback_value], # Value to return if `propname` is not set in the machine file
 # Keyword arguments:
 native : (追記) bool (追記ここまで) # Setting `native` to `true` forces retrieving a variable from the
)

Arguments

Argument flattening is NOT SUPPORTED by this function.

The method meson.get_external_property() accepts the following positional arguments:

Name Type Description Tags
propname (追記) str (追記ここまで)

Name of the property in the cross / native file.

fallback_value (追記) any (追記ここまで)

Value to return if propname is not set in the machine file.

[optional]

Finally, meson.get_external_property() accepts the following keyword arguments:

Name Type Description Tags
native (追記) bool (追記ここまで)

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()

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() (追記ここまで).

Signature

(since 0.58.0)

(追記) str (追記ここまで) global_build_root()

meson.global_source_root()

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() (追記ここまで).

Signature

(since 0.58.0)

(追記) str (追記ここまで) global_source_root()

meson.has_exe_wrapper()

Use (追記) meson.can_run_host_binaries() (追記ここまで) instead.

Signature

DEPRECATED

in 0.55.0

(追記) bool (追記ここまで) has_exe_wrapper()

meson.has_external_property()

Checks whether the given property exist in a native or cross file.

Signature

(since 0.58.0)

# Checks whether the given property exist in a native or cross file
(追記) bool (追記ここまで) has_external_property(
 (追記) str (追記ここまで) propname, # Name of the property in the cross / native file
 # Keyword arguments:
 native : (追記) bool (追記ここまで) # Setting `native` to `true` forces retrieving a variable from the
)

Arguments

The method meson.has_external_property() accepts the following positional arguments:

Name Type Description Tags
propname (追記) str (追記ここまで)

Name of the property in the cross / native file.

Finally, meson.has_external_property() accepts the following keyword arguments:

Name Type Description Tags
native (追記) bool (追記ここまで)

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()

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.

Signature

# Installs a manifest file
(追記) void (追記ここまで) install_dependency_manifest(
 (追記) str (追記ここまで) output_name, # Name of the manifest file to install
)

Arguments

The method meson.install_dependency_manifest() accepts the following positional arguments:

Name Type Description Tags
output_name (追記) str (追記ここまで)

Name of the manifest file to install


meson.is_cross_build()

Returns true if the current build is a cross build and false otherwise.

Signature

(追記) bool (追記ここまで) is_cross_build()

meson.is_subproject()

Returns true if the current project is being built as a subproject of some other project and false otherwise.

Signature

(追記) bool (追記ここまで) is_subproject()

meson.is_unity()

Returns true when doing a unity build (multiple sources are combined before compilation to reduce build time) and false otherwise.

Signature

(追記) bool (追記ここまで) is_unity()

meson.override_dependency()

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).

Signature

(since 0.54.0)

# Specifies that whenever (追記) dependency() (追記ここまで) with `name` is used, Meson should not
(追記) void (追記ここまで) override_dependency(
 (追記) str (追記ここまで) name, # The name of the dependency to override
 (追記) dep (追記ここまで) dep_object, # The dependency to set as the override for `name`
 # Keyword arguments:
 native : (追記) bool (追記ここまで) # If set to `true`, the dependency is always overwritten for the build machine
 static : (追記) bool (追記ここまで) # Used to override static and/or shared dependencies separately
)

Arguments

The method meson.override_dependency() accepts the following positional arguments:

Name Type Description Tags
name (追記) str (追記ここまで)

The name of the dependency to override.

dep_object (追記) dep (追記ここまで)

The dependency to set as the override for name.

Finally, meson.override_dependency() accepts the following keyword arguments:

Name Type Description Tags
native (追記) bool (追記ここまで)

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.

default = false

static (追記) bool (追記ここまで)

Used to override static and/or shared dependencies separately. If not specified it is assumed dep_object follows default_library option value.

(since 0.60.0)


meson.override_find_program()

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() (追記ここまで).

(since 0.55.0) If a version check is passed to (追記) find_program() (追記ここまで) for a program that has been overridden with an executable, the current project version is used.

Signature

(since 0.46.0)

# specifies that whenever (追記) find_program() (追記ここまで) is used to find a program
(追記) void (追記ここまで) override_find_program(
 (追記) str (追記ここまで) progname, # The name of the program to override
 (追記) exe (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで) program, # The program to set as the override for `progname`
 (追記) bool (追記ここまで) native, # If set to `true`, the override is for the build machine, and will be returned
)

Arguments

The method meson.override_find_program() accepts the following positional arguments:

Name Type Description Tags
progname (追記) str (追記ここまで)

The name of the program to override.

program (追記) exe (追記ここまで) | (追記) file (追記ここまで) | (追記) program (追記ここまで)

The program to set as the override for progname.

native (追記) bool (追記ここまで)

If set to true, the override is for the build machine, and will be returned by find_program(..., native : true), otherwise for the host machine. This is an important distinction when cross compiling.

(since 1.12.0)

default = false


meson.project_build_root()

Returns a string with the absolute path to the build root directory of the current (sub)project.

Signature

(since 0.56.0)

(追記) str (追記ここまで) project_build_root()

meson.project_license()

Returns the array of licenses specified in (追記) project() (追記ここまで) function call.

Signature

(since 0.45.0)

(追記) array (追記ここまで)[(追記) str (追記ここまで)] project_license()

meson.project_license_files()

Returns the array of license files specified in the (追記) project() (追記ここまで) function call.

Signature

(since 1.1.0)

(追記) array (追記ここまで)[(追記) file (追記ここまで)] project_license_files()

meson.project_name()

Returns the project name specified in the (追記) project() (追記ここまで) function call.

Signature

(追記) str (追記ここまで) project_name()

meson.project_source_root()

Returns a string with the absolute path to the source root directory of the current (sub)project.

Signature

(since 0.56.0)

(追記) str (追記ここまで) project_source_root()

meson.project_version()

Returns the version string specified in (追記) project() (追記ここまで) function call.

Signature

(追記) str (追記ここまで) project_version()

meson.source_root()

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.

Signature

DEPRECATED

in 0.56.0

(追記) str (追記ここまで) source_root()

meson.version()

Return a string with the version of Meson.

Signature

(追記) str (追記ここまで) version()

The results of the search are

AltStyle によって変換されたページ (->オリジナル) /