custom_target()
Create a custom top level build target. The only positional argument
is the name of this target and cannot contain path separators (/ or \).
The name of custom target might not be used by every backends, for instance with
the Ninja backend, subdir/meson.build containing the example below,
ninja -C builddir foo or ninja -C builddir subdir/foo won't work,
it is instead ninja -C builddir subdir/file.txt. However, meson compile subdir/foo
is accepted.
custom_target('foo', output: 'file.txt', ...)
The files passed to output: cannot contain path separators. See the
manual on custom build targets for
an explanation on where output files should be placed.
You can install the outputted files with the install_dir: kwarg, see below.
Since 0.60.0 the name argument is optional and defaults to the basename of the first
output (file.txt in the example above).
The array of strings passed to the command keyword argument accept
the following special string substitutions:
-
@INPUT@: the full path to the input passed toinput. 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 tooutput. 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 ininput -
@OUTPUT0@@OUTPUT1@...: the full path to the output with the specified array index inoutput -
@OUTDIR@: the full path to the directory where the output(s) must be written -
@DEPFILE@: the full path to the dependency file passed todepfile -
@PLAINNAME@: the input filename, without a path -
@PLAINNAME0@@PLAINNAME1@...(since 1.5.0): the input filename without a path, with the specified array index ininput -
@BASENAME@: the input filename, with extension removed -
@BASENAME0@@BASENAME1@...(since 1.5.0): the input filename with extension removed, with the specified array index ininput -
@PRIVATE_DIR@(since 0.50.1): path to a directory where the custom target must store all its intermediate files. -
@SOURCE_ROOT@: the path to the root of the source tree. Depending on the backend, this may be an absolute or a relative to current workdir path. -
@BUILD_ROOT@: the path to the root of the build tree. Depending on the backend, this may be an absolute or a relative to current workdir path. -
@CURRENT_SOURCE_DIR@: this is the directory where the currently processed meson.build is located in. Depending on the backend, this may be an absolute or a relative to current workdir path.
(since 0.47.0) The depfile keyword argument also accepts the
@BASENAME@ and @PLAINNAME@ substitutions.
The returned object also has methods that are documented in custom_tgt.
Signature
# Create a custom top level build target
custom_tgt custom_target(
str [name], # The *unique* id of the custom target
# Keyword arguments:
build_always : bool # If `true` this target is always considered out of
build_always_stale : bool # If `true` the target is always considered out of date
build_by_default : bool # Causes, when set to true, to
capture : bool # There are some compilers that can't be told to write
command : array[str | file | exe | external_program] # Command to run to create outputs from inputs
console : bool # Keyword argument conflicts with `capture`, and is meant
depend_files : array[str | file] # files (str,
depends : array[build_tgt | custom_tgt | custom_idx] # Specifies that this target depends on the specified
depfile : str # A dependency file that the command can write listing
env : env | array[str] | dict[str] # environment variables to set, such as
feed : bool # There are some compilers that can't be told to read
input : array[str | file] # Array of source files
install : bool # When true, one or more files of this target are installed during the install step (see `install_dir` for details)
install_dir : str | array[str | bool] # If only one install_dir is provided, all outputs are installed there
install_mode : array[str | int] # The file mode and optionally the owner/uid and group/gid
install_tag : array[str] # An array of strings, one per output, used by the `meson install --tags` command
output : array[str] # Array of output files
)
Arguments
The function custom_target() accepts the following positional arguments:
| Name | Type | Description | Tags |
|---|---|---|---|
name |
str |
The unique id of the custom target This posarg is optional since 0.60.0. It defaults to the basename of the first output. |
[optional] |
Finally, custom_target()
accepts the following keyword arguments:
| Name | Type | Description | Tags |
|---|---|---|---|
build_always |
bool |
If |
DEPRECATED in 0.47.0 |
build_always_stale |
bool |
If |
(since 0.47.0)
|
build_by_default |
bool |
Causes, when set to true, to
have this target be built by default. This means it will be built when
(since 0.50.0) If |
(since 0.38.0) |
capture |
bool |
There are some compilers that can't be told to write
their output to a file but instead write it to standard output. When
this argument is set to true, Meson captures |
|
command |
array[str | file | exe | external_program] |
Command to run to create outputs from inputs. The command
may be strings or the return value of functions that return file-like
objects such as |
|
console |
bool |
Keyword argument conflicts with |
(since 0.48.0) |
depend_files |
array[str | file] |
files ( |
|
depends |
array[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). |
|
depfile |
str |
A dependency file that the command can write listing all the additional files this target depends on, for example a C compiler would list all the header files it included, and a change in any one of these files triggers a recompilation. (since 0.47.0) the |
|
env |
env | array[str] | dict[str] |
environment variables to set, such as
|
(since 0.57.0) |
feed |
bool |
There are some compilers that can't be told to read
their input from a file and instead read it from standard input. When this
argument is set to |
(since 0.59.0)
|
input |
array[str | file] |
Array of source files. (since 0.41.0) the array is flattened. |
|
install |
bool |
When true, one or more files of this target are installed during the install step (see |
|
install_dir |
str | array[str | bool] |
If only one install_dir is provided, all outputs are installed there. Since 0.40.0 Allows you to specify the installation directory for each corresponding output. For example:
This would install To only install some outputs, pass
This would install |
|
install_mode |
array[str | int] |
The file mode and optionally the owner/uid and group/gid.
See the |
(since 0.47.0) |
install_tag |
array[str] |
An array of strings, one per output, used by the By default all outputs have no install tag which means they are not being
installed when |
(since 0.60.0) |
output |
array[str] |
Array of output files. These cannot contain path separators. |
|
The results of the search are