find_program()
program_name here is a string that can be an executable or script
to be searched for in PATH or other places inside the project.
The search order is:
- Program overrides set via
meson.override_find_program() -
[provide]sections in subproject wrap files, ifwrap_modeis set toforcefallback -
[binaries]section in your machine files - Directories provided using the
dirs:kwarg (see below) - 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
- If you use the return value of
-
PATHenvironment variable -
[provide]sections in subproject wrap files, ifwrap_modeis set to anything other thannofallback
Meson will also autodetect scripts with a shebang line and run them with the executable/interpreter specified in it both on Windows (because the command invocator will reject the command otherwise) and Unixes (if the script file does not have the executable bit set). Hence, you must not manually add the interpreter while using this script as part of an array of commands. Since 0.50.0 if the "python3" program is requested and it is not found in the system, Meson will return its current interpreter.
If you need to check for a program in a non-standard location, you can
just pass an absolute path to find_program, e.g.
setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
It is also possible to pass an array to find_program in case you
need to construct the set of paths to search on the fly:
setcap = find_program(['setcap', '/usr/sbin/setcap', '/sbin/setcap'], required : false)
Since 1.2.0 find_program('meson') is automatically overridden to the Meson
command used to execute the build script.
The returned external_program object also has documented methods.
Signature
# `program_name` here is a string that can be an executable or script
external_program find_program(
str | file program_name, # The name of the program to search, or a file object to be used
str | file fallback..., # These parameters are used as fallback names to search for
# Keyword arguments:
default_options : array[str] | dict[str | bool | int | array[str]] # An array of default option values
dirs : array[str] # extra array of absolute paths where to look for program names
disabler : bool # If `true` and the program couldn't be found, return a disabler object
native : bool # Defines how this executable should be searched
required : bool | feature # When `true`, Meson will abort if no program can be found
version : str | array[str] # Specifies the required version, see
version_argument : str # Specifies the argument to pass when trying to find the version of the program
)
Arguments
The function find_program() accepts the following positional arguments:
| Name | Type | Description | Tags |
|---|---|---|---|
program_name |
str | file
|
The name of the program to search, or a |
|
Additionally, the
function accepts between 0 and infinity variadic
arguments (fallback...) of type .str | file
These parameters are used as fallback names to search for.
This is meant to be used for cases where the
program may have many alternative names, such as foo and
foo.py. The function will check for the arguments one by one and the
first one that is found is returned.
(since 0.37.0)
Finally, find_program()
accepts the following keyword arguments:
| Name | Type | Description | Tags |
|---|---|---|---|
default_options |
array[str] | dict[str | bool | int | array[str]] |
An array of default option values
that override those set in the subproject's |
(since 1.3.0) |
dirs |
array[str] |
extra array of absolute paths where to look for program names. |
(since 0.53.0) |
disabler |
bool |
If |
(since 0.49.0)
|
native |
bool |
Defines how this executable should be searched. By default
it is set to |
(since 0.43.0)
|
required |
bool | feature
|
When |
|
version |
str | array[str] |
Specifies the required version, see
|
(since 0.52.0) |
version_argument |
str |
Specifies the argument to pass when trying to find the version of the program.
If this is unspecified, |
(since 1.5.0) |
The results of the search are