函数
本文档列出了 meson.build 文件中可用的所有函数。有关所有功能的概述,请参见 根手册文档。
add_global_arguments()
向编译器命令行添加全局参数。
签名
# Adds global arguments to the compiler command line
void add_global_arguments(
str Compiler argument..., # The compiler arguments to add
# Keyword arguments:
language : list[str] [required] # Specifies the language(s) that the arguments should be
native : bool # A boolean specifying whether the arguments should be
)
通常您应该使用 add_project_arguments(),因为即使您的项目用作子项目,它也能正常工作。
您必须始终单独传递参数 arg1, arg2, ...,而不是作为字符串 'arg1 arg2', ...
参数
该函数接受 0 到 无穷大 之间的可变参数 (编译器参数...),类型为 。str
要添加的编译器参数
函数 add_global_arguments() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
语言 |
list[str] |
指定应将参数应用于的语言。如果给定语言列表,则将参数添加到每个相应的编译器命令行。请注意,无法以这种方式删除已设置的参数。如果您的参数仅用于目标子集,则必须在每个目标标志中指定它。 |
|
本机 |
布尔值 |
一个布尔值,指定是否应将参数应用于本机或交叉编译。如果为 |
(从 0.48.0 开始)
|
add_global_link_arguments()
向链接器命令行添加全局参数。
类似于 add_global_arguments(),但参数传递给链接器。
签名
# Adds global arguments to the linker command line
void add_global_link_arguments(
str Linker argument..., # The linker arguments to add
# Keyword arguments:
language : list[str] [required] # Specifies the language(s) that the arguments should be
native : bool # A boolean specifying whether the arguments should be
)
通常您应该使用 add_project_link_arguments(),因为即使您的项目用作子项目,它也能正常工作。
您必须始终单独传递参数 arg1, arg2, ...,而不是作为字符串 'arg1 arg2', ...
参数
该函数接受 0 到 无穷大 之间的可变参数 (链接器参数...),类型为 。str
要添加的链接器参数
函数 add_global_link_arguments() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
语言 |
list[str] |
指定应将参数应用于的语言。如果给定语言列表,则将参数添加到每个相应的编译器命令行。请注意,无法以这种方式删除已设置的参数。如果您的参数仅用于目标子集,则必须在每个目标标志中指定它。 |
|
本机 |
布尔值 |
一个布尔值,指定是否应将参数应用于本机或交叉编译。如果为 |
(从 0.48.0 开始)
|
add_languages()
添加项目使用的编程语言。
这等效于在 project 声明中包含它们。此函数通常用于添加仅在某些条件下使用的语言。
如果找到所有指定的语言,则返回 true,否则返回 false。
如果省略 native,则语言可用于构建或主机机器,但绝不强制用于构建机器。 (即它等效于 add_languages(*langs*, native: false, required: *required*) and add_languages(*langs*, native: true, required: false)。此默认行为可能会更改为 native: false 在未来的 Meson 版本中。
签名
# Add programming languages used by the project
bool add_languages(
str Language..., # The languages to add
# Keyword arguments:
native : bool # If set to `true`, the language will be used to compile for the build
required : bool | feature # If set to `true`, Meson will halt if any of the languages
)
示例
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...
参数
该函数接受 0 到 无穷大 之间的可变参数 (语言...),类型为 。str
要添加的语言
函数 add_languages() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
本机 |
布尔值 |
如果设置为 |
(从 0.54.0 开始) |
必需 |
bool | feature |
如果设置为 |
|
add_project_arguments()
向编译器命令行添加特定于项目的参数。
此函数的行为与 add_global_arguments() 相同,只是参数仅用于当前项目,不会用于任何其他子项目。
签名
# Adds project specific arguments to the compiler command line
void add_project_arguments(
str Compiler argument..., # The compiler arguments to add
# Keyword arguments:
language : list[str] [required] # Specifies the language(s) that the arguments should be
native : bool # A boolean specifying whether the arguments should be
)
您必须始终单独传递参数 arg1, arg2, ...,而不是作为字符串 'arg1 arg2', ...
参数
该函数接受 0 到 无穷大 之间的可变参数 (编译器参数...),类型为 。str
要添加的编译器参数
函数 add_project_arguments() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
语言 |
list[str] |
指定应将参数应用于的语言。如果给定语言列表,则将参数添加到每个相应的编译器命令行。请注意,无法以这种方式删除已设置的参数。如果您的参数仅用于目标子集,则必须在每个目标标志中指定它。 |
|
本机 |
布尔值 |
一个布尔值,指定是否应将参数应用于本机或交叉编译。如果为 |
(从 0.48.0 开始)
|
add_project_dependencies()
向编译器和链接器命令行添加参数,以便将给定的依赖项集包含在此项目的 tất cả 产品构建中。
签名
(从 0.63.0 开始)
# Adds arguments to the compiler and linker command line, so that the
void add_project_dependencies(
dep dependencies..., # The dependencies to add; if internal dependencies are included, they must not include any built object
# Keyword arguments:
language : list[str] [required] # Specifies the language(s) that the arguments should be
native : bool # A boolean specifying whether the arguments should be
)
参数
该函数接受 0 到 无穷大 之间的可变参数 (依赖项...),类型为 。dep
要添加的依赖项;如果包含内部依赖项,则它们不能包含任何构建对象。
函数 add_project_dependencies() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
语言 |
list[str] |
指定应将参数应用于的语言。如果给定语言列表,则将参数添加到每个相应的编译器命令行。请注意,无法以这种方式删除已设置的参数。如果您的参数仅用于目标子集,则必须在每个目标标志中指定它。 |
|
本机 |
布尔值 |
一个布尔值,指定是否应将参数应用于本机或交叉编译。如果为 |
(从 0.48.0 开始)
|
add_project_link_arguments()
向链接器命令行添加特定于项目的参数。
类似于 add_project_arguments(),但参数传递给链接器。
签名
# Adds project specific arguments to the linker command line
void add_project_link_arguments(
str Linker argument..., # The linker arguments to add
# Keyword arguments:
language : list[str] [required] # Specifies the language(s) that the arguments should be
native : bool # A boolean specifying whether the arguments should be
)
您必须始终单独传递参数 arg1, arg2, ...,而不是作为字符串 'arg1 arg2', ...
参数
该函数接受 0 到 无穷大 之间的可变参数 (链接器参数...),类型为 。str
要添加的链接器参数
函数 add_project_link_arguments() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
语言 |
list[str] |
指定应将参数应用于的语言。如果给定语言列表,则将参数添加到每个相应的编译器命令行。请注意,无法以这种方式删除已设置的参数。如果您的参数仅用于目标子集,则必须在每个目标标志中指定它。 |
|
本机 |
布尔值 |
一个布尔值,指定是否应将参数应用于本机或交叉编译。如果为 |
(从 0.48.0 开始)
|
add_test_setup()
添加自定义测试设置。此设置可用于使用自定义设置运行测试,例如在 Valgrind 下。
要使用测试设置,请在构建目录中运行 meson test --setup=*name*。
请注意,所有这些选项在运行 meson test 脚本以运行测试时也可用,而不是 ninja test 或 msbuild RUN_TESTS.vcxproj 等,具体取决于后端。
签名
# Add a custom test setup
void add_test_setup(
str name, # The name of the test setup
# Keyword arguments:
env : env | list[str] | dict[str] # environment variables to set
exclude_suites : list[str] # A list of test suites that should be excluded when using this setup
exe_wrapper : list[str | external_program] # The command or script followed by the arguments to it
gdb : bool # If `true`, the tests are also run under `gdb`
is_default : bool # Set whether this is the default test setup
timeout_multiplier : int # A number to multiply the test timeout with
)
参数
函数 add_test_setup() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
名称 |
str |
测试设置的名称 |
|
最后,add_test_setup() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
|
排除套件 |
list[str] |
使用此设置时应排除的测试套件列表。在 |
(从 0.57.0 开始) |
exe_wrapper |
list[str | external_program] |
该命令或脚本后跟其参数 |
|
gdb |
布尔值 |
如果为 |
|
is_default |
布尔值 |
设置这是否是默认测试设置。如果为 |
(从 0.49.0 开始)
|
timeout_multiplier |
int |
一个用于乘以测试超时的数字。从 0.57 开始,如果 timeout_multiplier 为 |
|
alias_target()
此函数创建了一个新的顶层目标。与所有顶层目标一样,这与所选后端集成。例如,您可以使用它作为 meson compile target_name 运行。这是一个不执行任何命令的虚拟目标,但确保构建所有依赖项。依赖项可以是任何构建目标。从 0.60.0 开始,这包括 run_tgt。
从 1.6.0 开始,传递 both_libs 对象将构建共享库和静态库。
签名
(从 0.52.0 开始)
# This function creates a new top-level target
alias_tgt alias_target(
str target_name, # The name of the alias target
tgt Dep..., # The targets to depend on
)
参数
函数 alias_target() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
别名目标的名称 |
|
此外,该函数还接受 1 到 无穷大 之间的可变参数 (Dep...),类型为 。tgt
要依赖的目标
assert()
如果 condition 评估为 false,则以错误消息中止。
签名
# Abort with an error message if `condition` evaluates to `false`
void assert(
bool condition, # Abort if this evaluates to `false`
str [message], # The error message to print
)
从 0.53.0 开始,message 参数是可选的,默认值为打印条件语句。
参数
函数 assert() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
条件 |
布尔值 |
如果此评估结果为 |
|
信息 |
str |
要打印的错误消息。 |
[可选] |
benchmark()
创建一个基准项目,该项目将在运行基准目标时运行。此函数的行为与 test() 相同,除了
- benchmark() 没有
is_parallel关键字,因为基准测试不会并行运行 - benchmark() 不会自动添加
MALLOC_PERTURB_环境变量
可以通过在构建目录中调用 meson test --benchmark 或使用特定于后端的命令(例如 ninja benchmark 或 msbuild RUN_TESTS.vcxproj)以独立于后端的方式运行已定义的基准测试。
签名
# Creates a benchmark item that will be run when the benchmark target is
void benchmark(
str name, # The *unique* test id
exe | jar | external_program | file | custom_tgt | custom_idx executable, # The program to execute
# Keyword arguments:
args : list[str | file | tgt | external_program] # Arguments to pass to the executable
depends : list[build_tgt | custom_tgt] # specifies that this test depends on the specified
env : env | list[str] | dict[str] # environment variables to set, such as `['NAME1=value1',
priority : int # specifies the priority of a test
protocol : str # specifies how the test results are parsed and can
should_fail : bool # when true the test is considered passed if the
suite : str | list[str] # `'label'` (or list of labels `['label1', 'label2']`)
timeout : int # the amount of seconds the test is allowed to run, a test
verbose : bool # if true, forces the test results to be logged as if `--verbose` was passed
workdir : str # absolute path that will be used as the working directory
)
在 0.52.0 之前,benchmark 会警告说 depends 和 priority 不受支持,这是不正确的。
参数
函数 benchmark() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
名称 |
str |
唯一 测试 ID |
|
可执行文件 |
exe | jar | external_program | file | custom_tgt | custom_idx |
要执行的程序。(从 1.4.0 开始) 也接受 CustomTarget。 |
|
最后,benchmark() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
args |
list[str | file | tgt | external_program] |
传递给可执行文件的参数 |
|
取决于 |
list[build_tgt | custom_tgt] |
指定此测试依赖于指定的目标,即使它没有将任何目标作为命令行参数。这适用于测试在内部找到这些目标的情况,例如插件或通配符。即使它们具有 |
(从 0.46.0 开始) |
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
|
优先级 |
int |
指定测试的优先级。优先级较高的测试会在优先级较低的测试之前启动。优先级相同的测试的启动顺序是实现定义的。默认优先级为 0,允许使用负数。 |
(从 0.52.0 开始)
|
协议 |
str |
指定如何解析测试结果,可以是
|
(自 0.50.0 版本起)
|
should_fail |
布尔值 |
如果可执行文件返回非零返回值(即报告错误),则测试将被视为通过,当此值为真时。 |
|
suite |
str | list[str] |
附加到此测试的 |
|
timeout |
int |
测试允许运行的秒数,超过时间限制的测试始终被视为失败,默认为 30 秒。自 0.57 版本起,如果超时为 |
|
verbose |
布尔值 |
如果为真,则强制将测试结果记录为 |
(自 0.62.0 版本起)
|
workdir |
str |
将用作测试工作目录的绝对路径 |
|
both_libraries()
使用给定的源代码构建静态库和共享库。位置参数和关键字参数与 library() 相同。源文件将仅编译一次,并且对象文件将被重用以构建静态库和共享库,除非 b_staticpic 用户选项或 pic 参数设置为 false,在这种情况下,源文件将被编译两次。
签名
(从 0.46.0 开始)
# Builds both a static and shared library with the given sources
both_libs both_libraries(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
<lang>_shared_args : list[str] # Arguments that are only passed to a shared library
<lang>_static_args : list[str] # Arguments that are only passed to a static library
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
darwin_versions : str | int | list[str] # Defines the `compatibility version` and `current version` for the dylib on macOS
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
pic : bool # Builds the library as positional independent code
prelink : bool # If `true` the object files in the target will be prelinked,
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
soversion : str | int # A string or integer specifying the soversion of this shared library,
vala_args : list[str | file] # Compiler flags for Vala
vala_shared_args : list[str | file] # Arguments that are only passed to a shared library
vala_static_args : list[str | file] # Arguments that are only passed to a static library
version : str # A string specifying the version of this shared library,
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
参数
both_libraries() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,both_libraries() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
<lang>_shared_args |
list[str] |
仅传递给共享库的参数 |
(自 1.3.0 版本起) |
<lang>_static_args |
list[str] |
仅传递给静态库的参数 |
(自 1.3.0 版本起) |
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
darwin_versions |
str | int | list[str] |
定义 macOS 上 dylib 的 |
(从 0.48.0 开始) |
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
pic |
布尔值 |
将库构建为位置无关代码(因此可以链接到共享库)。此选项对 Windows 和 OS X 没有影响,因为在 Windows 上没有意义,并且在 OS X 上无法禁用 PIC。 |
(自 0.36.0 起) |
预链接 |
布尔值 |
如果为 |
(从 0.57.0 开始) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
soversion |
str | int |
指定此共享库的 soversion 的字符串或整数,例如 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
vala_shared_args |
list[str | file] |
仅传递给共享库的参数,例如 |
(自 1.3.0 版本起) |
vala_static_args |
list[str | file] |
仅传递给静态库的参数,例如 |
(自 1.3.0 版本起) |
版本 |
str |
指定此共享库版本的字符串,例如 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 (自 1.3.0 起) 支持 |
|
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
build_target()
创建一个构建目标,其类型可以使用 target_type 关键字参数动态设置。
target_type 可以设置为以下之一
-
executable(参见executable()) -
shared_library(参见shared_library()) -
shared_module(参见shared_module()) -
static_library(参见static_library()) -
both_libraries(参见both_libraries()) -
library(参见library()) -
jar(参见jar())*
此声明
executable(<arguments and keyword arguments>)
等效于此
build_target(<arguments and keyword arguments>, target_type : 'executable')
kwargs(例如 sources、objects 和 dependencies)的列表始终被展平,这意味着您可以在创建最终列表时自由地嵌套和添加列表。
返回的对象还具有在 build_tgt 中记录的方法。
*"jar" 已弃用,因为它从根本上与其他 build_target 类型不同。
签名
# Creates a build target whose type can be set dynamically with the
build_tgt build_target(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
<lang>_shared_args : list[str] # Arguments that are only passed to a shared library
<lang>_static_args : list[str] # Arguments that are only passed to a static library
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
darwin_versions : str | int | list[str] # Defines the `compatibility version` and `current version` for the dylib on macOS
dependencies : list[dep] # one or more dependency objects
export_dynamic : bool # when set to true causes the target's symbols to be
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implib : bool | str # When set to true, an import library is generated for the
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
java_resources : structured_src # Resources to be added to the jar
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
main_class : str # Main class for running the built jar
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
pic : bool # Builds the library as positional independent code
pie : bool # Build a position-independent executable
prelink : bool # If `true` the object files in the target will be prelinked,
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
soversion : str | int # A string or integer specifying the soversion of this shared library,
target_type : str # The actual target type to build
vala_args : list[str | file] # Compiler flags for Vala
vala_shared_args : list[str | file] # Arguments that are only passed to a shared library
vala_static_args : list[str | file] # Arguments that are only passed to a static library
version : str # A string specifying the version of this shared library,
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
参数
build_target() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,build_target() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
<lang>_shared_args |
list[str] |
仅传递给共享库的参数 |
(自 1.3.0 版本起) |
<lang>_static_args |
list[str] |
仅传递给静态库的参数 |
(自 1.3.0 版本起) |
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
darwin_versions |
str | int | list[str] |
定义 macOS 上 dylib 的 |
(从 0.48.0 开始) |
dependencies |
list[dep] |
一个或多个使用 |
|
export_dynamic |
布尔值 |
设置为 true 时,将导致目标的符号被动态导出,允许使用 |
(自 0.45.0 起) |
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implib |
bool | str |
设置为 true 时,将为可执行文件生成一个导入库(导入库的名称基于 exe_name)。或者,当设置为字符串时,它将提供导入库的基名称。当返回的构建目标对象出现在其他地方的 |
(自 0.42.0 版本起) |
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
java_resources |
structured_src |
要添加到 jar 的资源 |
(自 0.62.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
main_class |
str |
运行构建的 jar 的主类 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
pic |
布尔值 |
将库构建为位置无关代码(因此可以链接到共享库)。此选项对 Windows 和 OS X 没有影响,因为在 Windows 上没有意义,并且在 OS X 上无法禁用 PIC。 |
(自 0.36.0 起) |
pie |
布尔值 |
构建位置无关可执行文件。 |
(从 0.49.0 开始) |
预链接 |
布尔值 |
如果为 |
(从 0.57.0 开始) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
soversion |
str | int |
指定此共享库的 soversion 的字符串或整数,例如 |
|
target_type |
str |
要构建的实际目标类型 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
vala_shared_args |
list[str | file] |
仅传递给共享库的参数,例如 |
(自 1.3.0 版本起) |
vala_static_args |
list[str | file] |
仅传递给静态库的参数,例如 |
(自 1.3.0 版本起) |
版本 |
str |
指定此共享库版本的字符串,例如 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 这可用于公开可执行文件加载的 shared_module 允许使用的函数。 |
(自 1.3.0 版本起) |
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
configuration_data()
创建一个空配置对象。您应该使用 cfg_data 方法调用添加配置,最后在调用 configure_file() 时使用它。
签名
# Creates an empty configuration object
cfg_data configuration_data(
dict[str | bool | int] [data], # Optional dictionary to specify an initial data set
)
参数
configuration_data() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
数据 |
dict[str | bool | int] |
指定初始数据集的可选字典。如果提供,每个键值对都将添加到 |
(从 0.49.0 开始) [可选] |
configure_file()
此函数可以根据传递给它的关键字参数以三种模式运行。
当 cfg_data 对象传递给 configuration: 关键字参数时,它将采用模板文件作为 input:(可选)并生成 output:(必需),方法是根据配置数据中详细介绍的值进行替换 配置 文件文档。(自 0.49.0 起) 可以传递字典而不是 cfg_data 对象。
当字符串列表传递给 command: 关键字参数时,它将采用任何源文件或配置的文件作为 input:,并假设运行指定的命令后将生成 output:。
(自 0.47.0 起) 当 copy: 关键字参数设置为 true 时,此函数会将 input: 中提供的文件复制到构建目录中的一个文件中,该文件在当前目录中具有 output: 名称。
签名
# This function can run in three modes depending on the keyword arguments
file configure_file(
capture : bool # When this argument is set to true,
command : list[str | file] # As explained above, if specified, Meson does not create
configuration : cfg_data | dict[str | int | bool] # As explained above, when passed this will provide the replacement
copy : bool # As explained above, if specified Meson only
depfile : str # A dependency file that the command can write listing
encoding : str # Set the file encoding for the input and output file
format : str # The format of defines
input : str | file # The input file name
install : bool # When true, this generated file is installed during
install_dir : str # The subdirectory to install the generated file to
install_mode : list[str | int] # Specify the file mode in symbolic format
install_tag : str # A string used by the `meson install --tags` command
macro_name : str # When specified, macro guards will be used instead of '#pragma once'
output : str # The output file name
output_format : str # The format of the output to generate when no input
)
install_mode kwarg 忽略 0.62 -- 1.1.0 之间的整数值。
参数
configure_file() 函数接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
捕获 |
布尔值 |
当此参数设置为 true 时,Meson 会捕获 |
(自 0.41.0 起)
|
命令 |
list[str | file] |
如上所述,如果指定了,Meson 不会自己创建文件,而是运行指定的命令,这允许您进行完全自定义的文件生成。(从 0.52.0 版本开始) 命令可以包含文件对象,并且可以将多个文件传递给 |
|
配置 |
cfg_data | dict[str | int | bool] |
如上所述,当传递此参数时,它将为输入文件(如果提供)提供替换数据,或提供要写入输出文件的键值对。 |
|
复制 |
布尔值 |
如上所述,如果指定了,Meson 只会将文件从输入复制到输出。 |
(自 0.47.0 版本起)
|
依赖文件 |
str |
命令可以写入的依赖文件,列出此目标依赖的所有其他文件。其中任何一个文件的更改都会触发重新配置。 |
(从 0.52.0 开始) |
编码 |
str |
设置输入和输出文件的编码。支持的编码是 python3 的编码,请参阅 standard-encodings。 |
(自 0.47.0 版本起)
|
格式 |
str |
定义的格式。它默认设置为 |
(从 0.46.0 开始)
|
输入 |
str | file |
输入文件名。如果它在配置模式中未指定,则 |
|
install |
布尔值 |
当为真时,此生成的文件将在安装步骤中安装,并且 |
(自 0.50.0 版本起)
|
install_dir |
str |
要安装生成文件的子目录(例如 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_tag |
str |
|
(自 0.60.0 版本起) |
宏名称 |
str |
当指定时,将使用宏保护而不是 '#pragma once'。宏保护名称将是指定的名称。 |
(自 1.3.0 版本起) |
输出 |
str |
输出文件名。(从 0.41.0 版本开始) 可以包含 |
|
输出格式 |
str |
当没有指定输入时生成的输出格式。它默认设置为 |
(自 0.47.0 版本起) |
custom_target()
创建一个自定义的顶级构建目标。唯一的定位参数是此目标的名称,不能包含路径分隔符(/ 或 \)。自定义目标的名称可能不会被所有后端使用,例如,使用 Ninja 后端,subdir/meson.build 包含以下示例,ninja -C builddir foo 或 ninja -C builddir subdir/foo 将不起作用,而是 ninja -C builddir subdir/file.txt。但是,meson compile subdir/foo 是可以接受的。
custom_target('foo', output: 'file.txt', ...)
从 0.60.0 版本开始,名称参数是可选的,默认为第一个输出的基名(以上示例中的 file.txt)。
传递给 command 关键字参数的字符串列表接受以下特殊字符串替换
-
@INPUT@:传递给input的输入的完整路径。如果指定了多个输入,则只有当命令使用'@INPUT@'作为独立参数时,所有输入才会被替换为单独的参数。例如,以下方法将不起作用:command : ['cp', './@INPUT@'],但以下方法会起作用:command : ['cp', '@INPUT@']。 -
@OUTPUT@:传递给output的输出的完整路径。如果指定了多个输出,则行为与@INPUT@相同。 -
@INPUT0@@INPUT1@...:input中指定数组索引的输入的完整路径 -
@OUTPUT0@@OUTPUT1@...:output中指定数组索引的输出的完整路径 -
@OUTDIR@:必须将输出写入的目录的完整路径 -
@DEPFILE@:传递给depfile的依赖文件的完整路径 -
@PLAINNAME@:输入文件名,不含路径 -
@PLAINNAME0@@PLAINNAME1@...(从 1.5.0 版本开始):不含路径的输入文件名,带有input中指定的数组索引 -
@BASENAME@:输入文件名,已去除扩展名 -
@BASENAME0@@BASENAME1@...(从 1.5.0 版本开始):已去除扩展名的输入文件名,带有input中指定的数组索引 -
@PRIVATE_DIR@(从 0.50.1 版本开始):自定义目标必须将所有中间文件存储在其中的目录的路径。 -
@SOURCE_ROOT@:源树根目录的路径。根据后端,这可能是绝对路径或相对于当前工作目录的路径。 -
@BUILD_ROOT@:构建树根目录的路径。根据后端,这可能是绝对路径或相对于当前工作目录的路径。 -
@CURRENT_SOURCE_DIR@:这是当前处理的 meson.build 所在的目录。根据后端,这可能是绝对路径或相对于当前工作目录的路径。
(从 0.47.0 版本开始) depfile 关键字参数也接受 @BASENAME@ 和 @PLAINNAME@ 替换。
返回的对象还具有在 custom_tgt 中记录的方法。
签名
# 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 : list[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 : list[str | file] # files (str,
depends : list[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 | list[str] | dict[str] # environment variables to set, such as
feed : bool # There are some compilers that can't be told to read
input : list[str | file] # List 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 | list[str | bool] # If only one install_dir is provided, all outputs are installed there
install_mode : list[str | int] # The file mode and optionally the owner/uid and group/gid
install_tag : list[str] # A list of strings, one per output, used by the `meson install --tags` command
output : list[str] # List of output files
)
假设 command: 由 POSIX sh shell 执行是不便携的,尤其是在 Windows 上。相反,请考虑使用 native: true 的 executable(),或使用 python 脚本。
install_mode kwarg 在 0.60.0 - 1.1.0 版本之间忽略整数。
参数
custom_target() 函数接受以下定位参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
名称 |
str |
自定义目标的唯一 ID 此定位参数是可选的,从 0.60.0 版本开始。它默认为第一个输出的基名。 |
[可选] |
最后,custom_target() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
build_always |
布尔值 |
如果为 |
已弃用 在 0.47.0 版本中 |
build_always_stale |
布尔值 |
如果为 |
(自 0.47.0 版本起)
|
build_by_default |
布尔值 |
当设置为 true 时,会导致默认情况下构建此目标。这意味着在不带任何参数调用 (从 0.50.0 版本开始) 如果 |
(自 0.38.0 版本起) |
捕获 |
布尔值 |
有一些编译器无法被告知将它们的输出写入文件,而是将它们写入标准输出。当此参数设置为 true 时,Meson 会捕获 |
|
命令 |
list[str | file | exe | external_program] |
要运行以从输入创建输出的命令。命令可以是字符串,也可以是返回文件类对象的函数的返回值,例如 |
|
控制台 |
布尔值 |
关键字参数与 |
(从 0.48.0 开始) |
依赖文件 |
list[str | file] |
此目标依赖的文件( |
|
取决于 |
list[build_tgt | custom_tgt | custom_idx] |
指定此目标依赖于指定的目标,即使它没有将任何目标作为命令行参数。这适用于您有一个工具在内部执行 glob 匹配的情况。通常,您只需将生成的源文件作为输入,Meson 会自动设置所有依赖项(custom_idx 在 0.60 到 1.4.0 版本之间不可用为类型)。 |
|
依赖文件 |
str |
命令可以写入的依赖文件,列出此目标依赖的所有其他文件,例如,C 编译器将列出它包含的所有头文件,其中任何一个文件的更改都会触发重新编译。 (从 0.47.0 版本开始) |
|
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
(从 0.57.0 开始) |
馈送 |
布尔值 |
有一些编译器无法被告知从文件读取它们的输入,而是从标准输入读取。当此参数设置为 |
(从 0.59.0 版本开始)
|
输入 |
list[str | file] |
源文件列表。(从 0.41.0 版本开始) 列表将被扁平化。 |
|
install |
布尔值 |
当为 true 时,此目标的一个或多个文件将在安装步骤中安装(有关详细信息,请参阅 |
|
install_dir |
str | list[str | bool] |
如果只提供一个 install_dir,则所有输出都将安装到该目录。从 0.40.0 版本开始,允许您为每个相应的输出指定安装目录。例如
这将安装 要仅安装某些输出,请对不想安装的输出传递
这将安装 |
|
install_mode |
list[str | int] |
文件模式以及可选的拥有者/uid 和组/gid。有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_tag |
list[str] |
字符串列表,每个输出一个,由 默认情况下,所有输出都没有安装标签,这意味着在指定 |
(自 0.60.0 版本起) |
输出 |
list[str] |
输出文件列表。 |
|
debug()
将参数字符串写入 meson 构建日志。
签名
(从 0.63.0 开始)
# Write the argument string to the meson build log
void debug(
str | int | bool | list[str | int | bool] | dict[str | int | bool] message, # The message to print
str | int | bool | list[str | int | bool] | dict[str | int | bool] msg..., # Additional parameters will be separated by spaces
)
参数
函数 debug() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
信息 |
str | int | bool | list[str | int | bool] | dict[str | int | bool] |
要打印的消息 |
|
此外,该函数接受 0 到 infinity 之间的可变参数 (msg...),类型为 。str | int | bool | list[str | int | bool] | dict[str | int | bool]
其他参数将用空格隔开
declare_dependency()
此函数返回一个 dep 对象,其行为类似于 dependency() 的返回值,但它在当前构建内部。这在子项目中的主要用例是。这允许子项目轻松指定其使用方式。这使得它与系统外部提供的相同依赖项可以互换使用。
签名
# This function returns a dep object that
dep declare_dependency(
compile_args : list[str] # Compile arguments to use
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : str | int | list[str | int] # The [D version identifiers](https://dlang
dependencies : list[dep] # Other dependencies needed to use this dependency
extra_files : list[str | file] # extra files to add to targets
include_directories : list[inc | str] # the directories to add to header search path,
link_args : list[str] # Link arguments to use
link_whole : list[lib] # Libraries to link fully, same as executable().
link_with : list[lib] # Libraries to link against
objects : list[extracted_obj] # a list of object files, to be linked directly into the targets that use the
sources : list[str | file | custom_tgt | custom_idx | generated_list] # sources to add to targets
variables : dict[str] | list[str] # a dictionary of arbitrary strings,
version : str # the version of this dependency,
)
参数
函数 declare_dependency() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
compile_args |
list[str] |
要使用的编译参数。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
str | int | list[str | int] |
在编译 D 源文件时要添加的 D 版本标识符。 |
(自 0.62.0 版本起) |
dependencies |
list[dep] |
使用此依赖项所需的其他依赖项。 |
|
extra_files |
list[str | file] |
要添加到目标的额外文件。主要用于 IDE 集成。 |
(自 1.2.0 起) |
include_directories |
list[inc | str] |
要添加到头文件搜索路径的目录,必须是 |
|
link_args |
list[str] |
要使用的链接参数。 |
|
link_whole |
list[lib] |
要完全链接的库,与 |
(从 0.46.0 开始) |
link_with |
list[lib] |
要链接到的库。 |
|
对象 |
list[extracted_obj] |
对象文件列表,将直接链接到使用该依赖项的目标。 |
(从 1.1.0 开始) |
来源 |
list[str | file | custom_tgt | custom_idx | generated_list] |
要添加到目标的源代码(或在包含它们的源代码构建之前应构建的生成的标题文件) |
|
variables |
dict[str] | list[str] |
任意字符串的字典,这旨在用于子项目,其中特殊变量将通过 cmake 或 pkg-config 提供。从 0.56.0 开始,它也可以是 |
(从 0.54.0 开始) |
版本 |
str |
此依赖项的版本,例如 |
|
dependency()
使用 pkg-config 查找具有给定名称的外部依赖项(通常是安装在系统上的库),如果 pkg-config 失败,则使用 CMake。此外,框架(仅限 OSX)和 特定于库的回退检测逻辑 也受支持。
从 0.60.0 开始,可以提供多个名称,它们将按顺序尝试,找到的第一个名称将被使用。只有当系统上没有找到任何名称时,才会使用回退子项目。一旦找到一个名称,所有其他名称都将被添加到缓存中,因此对任何这些名称的后续调用都将返回相同的值。这在依赖项可能具有不同名称(例如 png 和 libpng)的情况下非常有用。
- 从 0.64.0 开始,WrapDB 可以提供依赖项回退。只需使用
meson wrap update-db命令在本地下载数据库,Meson 就会在系统上找不到依赖项并且项目没有提供自己的.wrap文件时,自动回退到 WrapDB 提供的子项目。
依赖项也可以通过两种其他方式解决
-
如果在调用
dependency之前在meson.override_dependency中使用了相同的名称,则将无条件返回覆盖依赖项;也就是说,覆盖依赖项将被使用,无论系统中是否安装了外部依赖项。通常,meson.override_dependency将由子项目使用。 -
通过回退子项目,如果需要,它将被引入当前构建规范中,就像调用了
subproject()一样。可以使用fallback参数指定子项目。或者,如果缺少fallback参数,从 0.55.0 开始,如果一个包装文件 提供 依赖项,或者如果子项目的名称与依赖项相同,Meson 可以自动识别子项目作为回退。在后一种情况下,子项目必须使用meson.override_dependency指定要替换的依赖项,否则 Meson 将报告一个严重错误。有关更多详细信息,请参阅 Wrap 文档。可以使用allow_fallback关键字参数控制此自动搜索。
如果 dependency_name 为 '',则始终找不到依赖项。因此,使用 required: false,这将始终返回一个依赖项对象,其 found() 方法返回 false,并且可以像任何其他依赖项一样传递给 build_target 的 dependencies: 关键字参数。这可以用来实现一个有时不需要的依赖关系,例如在条件的某些分支中,或者使用 fallback: 关键字参数,可以用来声明一个可选的依赖关系,它只在指定的子项目中查找,并且只有在 --wrap-mode 允许的情况下才查找。
返回的对象 dep 还具有其他方法。
签名
# Finds an external dependency (usually a library installed on your
dep dependency(
str names..., # The names of the dependency to look up
# Keyword arguments:
allow_fallback : bool # Specifies whether Meson should automatically pick a fallback subproject
default_options : list[str] | dict[str | bool | int | list[str]] # An array of default option values
disabler : bool # Returns a disabler() object instead of a not-found dependency
fallback : list[str] | str # Manually specifies a subproject fallback
include_type : str # An enum flag, marking how the dependency
language : str # Defines what language-specific dependency to find
method : str # Defines the way the dependency is detected, the default is
native : bool # If set to `true`, causes Meson to find the dependency on
not_found_message : str # An optional string that will be printed as a message() if the dependency was not found.
required : bool | feature # When set to `false`, Meson will proceed with the build
static : bool # Tells the dependency provider to try to get static
version : list[str] | str # Specifies the required version,
)
此函数支持其他 特定于库的 关键字参数,这些参数也可能被接受(例如 modules 指定要使用的子模块,例如 Qt5 或 Boost。components 允许用户手动为 find_package 查找添加 CMake COMPONENTS)
参数
该函数接受 1 到 infinity 之间的可变参数 (names...),类型为 。str
要查找的依赖项的名称。将按此处提供的顺序查找依赖项。然后将使用找到的第一个依赖项。只有当系统上没有找到任何名称时,才会使用回退子项目。一旦找到一个名称,所有其他名称都将被添加到缓存中,因此对任何这些名称的后续调用都将返回相同的值。这在依赖项可能具有不同名称(例如 png 和 libpng)的情况下非常有用。
注意:在 0.60.0 之前,只允许一个依赖项名称。
(自 0.60.0 版本起)
函数 dependency() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
allow_fallback |
布尔值 |
指定 Meson 是否应该在系统中找不到依赖项的情况下自动选择回退子项目。如果为 |
(自 0.56.0 起) |
default_options |
list[str] | dict[str | bool | int | list[str]] |
覆盖子项目 |
(自 0.38.0 版本起) |
disabler |
布尔值 |
如果此关键字参数设置为 |
(从 0.49.0 开始)
|
fallback |
list[str] | str |
手动指定一个子项目回退,以便在系统中找不到依赖项的情况下使用。如果自动搜索不适用,或者您想支持早于 0.55.0 的 Meson 版本,这将非常有用。如果该值是一个数组 |
|
include_type |
str |
枚举标志,标记应如何转换依赖项标志。支持的值是 |
(从 0.52.0 开始)
|
语言 |
str |
定义如果它可用于多种语言,则要查找哪种特定于语言的依赖项。 |
(自 0.42.0 版本起) |
method |
str |
定义依赖项的检测方式,默认值为 |
(自 0.40.0 版本起)
|
本机 |
布尔值 |
如果设置为 |
|
not_found_message |
str |
如果未找到依赖项,则将作为 |
(自 0.50.0 版本起) |
必需 |
bool | feature |
如果设置为 如果设置为 (从 0.47.0 开始) |
|
static |
布尔值 |
指示依赖项提供者尝试获取静态库而不是动态库(请注意,并非所有依赖项后端都支持此功能)。 从 0.60.0 开始,如果未在 从 0.63.0 开始,当 |
|
版本 |
list[str] | str |
指定所需的版本,一个包含比较运算符和版本字符串的字符串,例如 |
(从 0.37.0 开始) |
disabler()
返回一个 disabler 对象。
签名
(从 0.44.0 开始)
disabler disabler()
environment()
返回一个空的 env 对象。
签名
(从 0.35.0 开始)
# Returns an empty env object.
env environment(
str | list[str] | dict[str] | dict[list[str]] [env], # If provided, each key/value pair is added into the env object
# Keyword arguments:
method : str # Must be one of 'set', 'prepend', or 'append'
separator : str # The separator to use for the initial values defined in
)
参数
参数扁平化 不支持 此函数。
environment() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
env |
str | list[str] | dict[str] | dict[list[str]] |
如果提供,每个键值对都将添加到 |
(从 0.52.0 开始) [可选] |
最后,environment() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
method |
str |
必须是 'set'、'prepend' 或 'append' 之一(默认为 'set')。控制第一个位置参数中定义的初始值是追加、附加还是替换环境变量的当前值。 |
(自 0.62.0 版本起) |
separator |
str |
用于第一个位置参数中定义的初始值的分割符。如果未显式指定,将使用主机操作系统的默认路径分割符,即 Windows 的 ';' 和 UNIX/POSIX 系统的 ':'。 |
(自 0.62.0 版本起) |
error()
打印参数字符串并停止构建过程。
签名
# Print the argument string and halts the build process
void error(
str message, # The message to print
str msg..., # Additional parameters will be separated by spaces
)
参数
参数扁平化 不支持 此函数。
error() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
信息 |
str |
要打印的消息 |
|
此外,该函数接受 0 到 infinity 个可变参数(msg...),其类型为 。str
其他参数将用空格隔开
(从 0.58.0 开始)
executable()
创建一个新的可执行文件。第一个参数指定其名称,其余位置参数定义要使用的输入文件。
kwargs(例如 sources、objects 和 dependencies)的列表始终被展平,这意味着您可以在创建最终列表时自由地嵌套和添加列表。
返回的对象还具有在 exe 中记录的方法。
从 1.3.0 开始,只要每个可执行文件都具有不同的 name_suffix,多个目标中的可执行文件名称就可以相同。
签名
# Creates a new executable
exe executable(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
dependencies : list[dep] # one or more dependency objects
export_dynamic : bool # when set to true causes the target's symbols to be
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implib : bool | str # When set to true, an import library is generated for the
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
pie : bool # Build a position-independent executable
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
vala_args : list[str | file] # Compiler flags for Vala
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
link_language 关键字参数在 0.55.0 之前存在问题。
参数
executable() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,executable() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
dependencies |
list[dep] |
一个或多个使用 |
|
export_dynamic |
布尔值 |
设置为 true 时,将导致目标的符号被动态导出,允许使用 |
(自 0.45.0 起) |
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implib |
bool | str |
设置为 true 时,将为可执行文件生成一个导入库(导入库的名称基于 exe_name)。或者,当设置为字符串时,它将提供导入库的基名称。当返回的构建目标对象出现在其他地方的 |
(自 0.42.0 版本起) |
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
pie |
布尔值 |
构建位置无关可执行文件。 |
(从 0.49.0 开始) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 这可用于公开可执行文件加载的 shared_module 允许使用的函数。 |
(自 1.3.0 版本起) |
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
files()
此命令获取传递给它的参数中的字符串,并返回相应的 File 对象,您可以将其用作构建目标的源。不同之处在于文件对象会记住它们定义的子目录,并且可以在源代码树中的任何位置使用。
签名
# This command takes the strings given to it in arguments and returns
list[file] files(
str file..., # Path to the file
)
示例
例如,假设您在子目录 bar1 中有源文件 foo.cpp,并且您想在定义在 bar2 中的构建目标中使用它。要实现这一点,您首先需要在 bar1 中创建该对象,如下所示:
foofile = files('foo.cpp')
然后您可以在 bar2 中使用它,如下所示:
executable('myprog', 'myprog.cpp', foofile, ...)
Meson 随后将执行正确操作。
参数
该函数接受 0 到 infinity 个可变参数(file...),其类型为 。str
文件的路径。
find_program()
program_name 这里是一个字符串,可以是可执行文件或脚本,在 PATH 或项目中的其他位置进行搜索。搜索顺序为:
- 通过
meson.override_find_program()设置的程序覆盖 -
子项目包装文件中
[provide]部分,如果wrap_mode设置为forcefallback -
机器文件中
[binaries]部分 - 使用
dirs:关键字参数提供的目录(见下文) - 相对于当前子目录的项目的源代码树
- 如果使用
configure_file()的返回值,则使用构建树中的当前子目录。
- 如果使用
-
PATH环境变量 -
子项目包装文件中
[provide]部分,如果wrap_mode设置为除nofallback以外的任何值
Meson 还会自动检测带有 shebang 行的脚本,并在 Windows(因为命令调用程序将拒绝该命令)和 Unixes(如果脚本文件没有设置可执行位)上使用其中指定的可执行文件/解释器运行它们。因此,您必须不要在将此脚本用作命令列表的一部分时手动添加解释器。从 0.50.0 开始,如果请求 "python3" 程序且系统中未找到它,则 Meson 将返回其当前解释器。
如果需要在非标准位置检查程序,只需将绝对路径传递给 find_program,例如:
setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
也可以将数组传递给 find_program,以防您需要动态构建要搜索的路径集
setcap = find_program(['setcap', '/usr/sbin/setcap', '/sbin/setcap'], required : false)
从 1.2.0 开始,find_program('meson') 自动覆盖为用于执行构建脚本的 Meson 命令。
返回的 external_program 对象也具有记录的方法。
签名
# `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 : list[str] | dict[str | bool | int | list[str]] # An array of default option values
dirs : list[str] # extra list 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 | list[str] # Specifies the required version, see
version_argument : str # Specifies the argument to pass when trying to find the version of the program
)
参数
find_program() 函数接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
program_name |
str | file |
要搜索的程序的名称,或一个 |
|
此外,该函数接受 0 到 infinity 个可变参数(fallback...),其类型为 。str | file
这些参数用作要搜索的回退名称。这旨在用于程序可能具有许多替代名称的情况,例如 foo 和 foo.py。该函数将逐个检查参数,找到第一个参数后就会返回。
(从 0.37.0 开始)
最后,find_program() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
default_options |
list[str] | dict[str | bool | int | list[str]] |
一组默认选项值,覆盖子项目 |
(自 1.3.0 版本起) |
dirs |
list[str] |
要查找程序名称的其他绝对路径列表。 |
(从 0.53.0 开始) |
disabler |
布尔值 |
如果为 |
(从 0.49.0 开始)
|
本机 |
布尔值 |
定义如何搜索此可执行文件。默认情况下,它设置为 |
(从 0.43.0 开始)
|
必需 |
bool | feature |
当 |
|
版本 |
str | list[str] |
指定所需的版本,有关参数格式,请参见 |
(从 0.52.0 开始) |
version_argument |
str |
指定在尝试查找程序版本时要传递的参数。如果未指定此参数,则将使用 |
(从 1.5.0 开始) |
generator()
此函数创建一个 generator 对象,可用于运行自定义编译命令。唯一的参数是要使用的可执行文件。它可以是自建可执行文件,也可以是 find_program 返回的可执行文件。
传递给所有关键字参数的模板字符串接受以下特殊替换:
-
@PLAINNAME@:完整的输入文件名,例如:foo.c变成foo.c(不变) -
@BASENAME@:输入文件名的基础,例如:foo.c.y变成foo.c(扩展名被删除)
传递给 output 关键字参数的每个字符串必须使用这两个替换之一或两者构建。
除了上述替换外,arguments 关键字参数还接受以下内容:
-
@OUTPUT@:输出文件的完整路径 -
@INPUT@:输入文件的完整路径 -
@DEPFILE@:依赖文件的完整路径 -
@SOURCE_DIR@:源代码树根的完整路径 -
@CURRENT_SOURCE_DIR@:这是当前处理的 meson.build 所在的目录 -
@BUILD_DIR@:构建目录根的完整路径,输出文件将放置在该目录中
注意:生成器仅应用于仅用作 build_target() 或 custom_target() 输入的输出。当您在多个目标中使用生成器的处理后的输出时,生成器将被多次运行以创建每个目标的输出。每个输出将在目标私有目录 @BUILD_DIR@ 中创建。
如果您想为一般用途生成文件,例如生成要由多个源文件使用的头文件,或要安装的数据等,请使用 custom_target()。
签名
# See also: custom_target()
generator generator(
exe | external_program exe, # Executable for the command to run
# Keyword arguments:
arguments : list[str] # A list of template strings that will be the command line arguments passed to the executable
capture : bool # When this argument is set to true, Meson captures `stdout`
depends : list[build_tgt | custom_tgt | custom_idx] # An array of build targets that must be built before
depfile : str # A template string pointing to a dependency file that a
output : list[str] # Template string (or list of template strings) defining
)
参数
函数 generator() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
exe |
exe | external_program |
要运行的命令的可执行文件 |
|
最后,generator() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
arguments |
list[str] |
将作为命令行参数传递给可执行文件的模板字符串列表。 |
|
捕获 |
布尔值 |
当此参数设置为 true 时,Meson 会捕获 |
(从 0.43.0 开始)
|
取决于 |
list[build_tgt | custom_tgt | custom_idx] |
必须在此生成器可以运行之前构建的构建目标数组。如果您有一个调用本项目中构建的第二个可执行文件的生成器,则使用此参数(在 0.60 到 1.4.0 之间不可用 custom_idx)。 |
(自 0.51.0 版本起) |
依赖文件 |
str |
指向依赖文件的模板字符串,生成器可以写入该文件,列出此目标依赖的所有其他文件,例如,C 编译器将列出它包含的所有头文件,并且任何一个文件的更改都会触发重新编译, |
|
输出 |
list[str] |
定义如何从单个源文件名生成输出文件名(或多个输出文件名)的模板字符串(或模板字符串列表)。 |
|
get_option()
获取位置参数中指定 项目构建选项 的值。
请注意,以 dir 结尾的内置选项(如 bindir 和 libdir)返回的值通常是相对于(并在)prefix 中的路径,但您不应该依赖于此,因为它也可能是绝对路径 在某些情况下。 install_dir 参数 按预期处理,但如果您需要绝对路径,例如在定义中使用等,您应该使用路径连接运算符,如下所示:get_option('prefix') / get_option('localstatedir')。切勿像处理字符串一样手动连接路径。
对于类型为 feature 的选项,将返回 feature 选项对象而不是字符串。有关更多详细信息,请参阅 feature 选项 文档。
签名
# Obtains the value of the [project build option](Build-options
str | int | bool | feature | list[str | int | bool] get_option(
str option_name, # Name of the option to query
)
参数
函数 get_option() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
option_name |
str |
要查询的选项的名称 |
|
get_variable()
此函数可用于动态获取变量。res = get_variable(varname, fallback) 获取 varname(必须是字符串)的值并将该名称的变量存储到 res 中。如果变量不存在,则将变量 fallback 存储到 res 中。如果没有指定回退,则尝试读取不存在的变量将导致致命错误。
签名
# This function can be used to dynamically obtain a variable
any get_variable(
str variable_name, # Name of the variable to get
any [default], # Fallback value to return when the variable does not exist
)
参数
参数扁平化 不支持 此函数。
函数 get_variable() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
variable_name |
str |
要获取的变量的名称 |
|
default |
any |
当变量不存在时要返回的回退值 |
[可选] |
import()
导入给定的扩展模块。返回一个对象,该对象可用于调用模块的方法。以下是一个假设的 testmod 模块的示例。
签名
# Imports the given extension module
module import(
str module_name, # Name of the module to import
# Keyword arguments:
disabler : bool # Returns a disabler object when not found.
required : bool | feature # When set to `false`, Meson will proceed with the build even if the module is not found
)
示例
tmod = import('testmod')
tmod.do_something()
参数
函数 import() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
module_name |
str |
要导入的模块的名称。 |
|
最后,import() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
disabler |
布尔值 |
找不到时返回 |
(从 0.59.0 版本开始) |
必需 |
bool | feature |
当设置为 |
(从 0.59.0 版本开始)
|
include_directories()
返回一个不透明对象,该对象包含位置参数中给出的目录(相对于当前目录)。然后,该结果可以传递给构建可执行文件或库时的 include_directories: 关键字参数。您可以在想要的任何子目录中使用返回的对象,Meson 将自动使路径正常工作。
请注意,此函数调用本身不会将目录添加到搜索路径中,因为没有全局搜索路径。对于类似的东西,请参阅 add_project_arguments()。
另请参阅 executable() 的 implicit_include_directories 参数,该参数将当前源目录和构建目录添加到包含路径中。
给定的每个目录都将转换为两个包含路径:一个相对于源根目录,一个相对于构建根目录。
签名
# Returns an opaque object which contains the directories (relative to
inc include_directories(
str includes..., # Include paths to add
# Keyword arguments:
is_system : bool # If set to `true`, flags the specified directories as system directories
)
示例
例如,在 /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,
...)
...
如果构建树是 /tmp/build-tree,则以下包含路径将被添加到 executable() 调用中:-I/tmp/build-tree/include -I/home/user/project.git/include。
参数
该函数接受 0 到 无穷大 之间的可变参数(includes...),类型为 。str
要添加的包含路径。
函数 include_directories() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
is_system |
布尔值 |
如果设置为 |
|
install_data()
从源树中安装列为位置参数的文件。
有关更多示例,请参阅 安装。
签名
# Installs files from the source tree that are listed as positional arguments
void install_data(
file | str file..., # Files to install
# Keyword arguments:
follow_symlinks : bool # If true, dereferences links and copies their target instead
install_dir : str # The absolute or relative path to the installation directory
install_mode : list[str | int] # specify the file mode in symbolic format and
install_tag : str # A string used by the `meson install --tags` command
preserve_path : bool # Disable stripping child-directories from data files when installing
rename : list[str] # If specified renames each source file into corresponding file from `rename` list
sources : list[file | str] # Additional files to install
)
install_mode kwarg 在 0.59.0 -- 1.1.0 之间的整数值被忽略。
省略的 install_dir kwarg 在 1.3.0 之前在子项目内部无法正常工作。
省略的 install_dir kwarg 在 1.3.0 之前与 preserve_path kwarg 结合使用时无法正常工作。
参数
该函数接受 0 到 无穷大 之间的可变参数(file...),类型为 。file | str
要安装的文件。
函数 install_data() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
follow_symlinks |
布尔值 |
如果为 true,则取消引用链接并复制其目标。默认值将在将来变为 false。 |
(自 1.3.0 版本起)
|
install_dir |
str |
安装目录的绝对路径或相对路径。如果这是一个相对路径,则假定它是相对于前缀的。 如果省略,目录默认为 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为已安装文件指定所有者/uid 和组/gid。例如
要将这三者中的任何一个保留为默认值,请指定 |
(自 0.38.0 版本起) |
install_tag |
str |
|
(自 0.60.0 版本起) |
preserve_path |
布尔值 |
在安装时禁用从数据文件中剥离子目录。 这等效于 GNU Automake 的 |
(自 0.64.0 起)
|
rename |
list[str] |
如果指定,则将每个源文件重命名为 |
(从 0.46.0 开始) |
来源 |
list[file | str] |
要安装的额外文件。 |
|
install_emptydir()
将新的目录条目安装到位置参数指定的位置。如果目录存在且不为空,则其内容将保留在原位。
签名
(自 0.60.0 版本起)
# Installs a new directory entry to the location specified by the positional
void install_emptydir(
str dirpath..., # Directory to create during installation
# Keyword arguments:
install_mode : list[str | int] # Specify the file mode in symbolic format and optionally the owner/uid and
install_tag : str # A string used by the `meson install --tags` command to install only a
)
install_mode kwarg 在 1.1.0 之前忽略整数值。
参数
该函数接受 0 到 无穷大 之间的可变参数(dirpath...),类型为 。str
在安装期间要创建的目录。
函数 install_emptydir() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为创建的目录指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
|
install_tag |
str |
|
|
install_headers()
在安装步骤期间,将源树中的指定头文件安装到系统头文件目录(通常为 /{prefix}/include)。此目录可以通过使用 install_dir 关键字参数指定来覆盖。如果您只想安装到系统头文件目录的子目录中,请使用 subdir 参数。例如,如果此参数的值为 myproj,则头文件将被安装到 /{prefix}/include/myproj。
签名
# Installs the specified header files from the source tree into the
void install_headers(
file | str file..., # Header files to install
# Keyword arguments:
follow_symlinks : bool # If true, dereferences links and copies their target instead
install_dir : str # Where to install to
install_mode : list[str | int] # Specify the file mode in symbolic format
preserve_path : bool # Disable stripping child-directories from header files when installing
subdir : str # Install to the `subdir` subdirectory of the default includedir
)
示例
例如,这将把 common.h 和 kola.h 安装到 /{prefix}/include
install_headers('common.h', 'proj/kola.h')
这将把 common.h 和 kola.h 安装到 /{prefix}/include/myproj
install_headers('common.h', 'proj/kola.h', subdir : 'myproj')
这将把 common.h 和 kola.h 安装到 /{prefix}/cust/myproj
install_headers('common.h', 'proj/kola.h', install_dir : 'cust', subdir : 'myproj')
这将把 common.h 安装到 /{prefix}/include,并将 kola.h 安装到 /{prefix}/include/proj/
install_headers('common.h, 'proj/kola.h', preserve_path : true)
install_mode kwarg 在 0.59.0 -- 1.1.0 之间的整数值被忽略。
参数
该函数接受 0 到 无穷大 之间的可变参数(file...),类型为 。file | str
要安装的头文件。
函数 install_headers() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
follow_symlinks |
布尔值 |
如果为 true,则取消引用链接并复制其目标。默认值将在将来变为 false。 |
(自 1.3.0 版本起)
|
install_dir |
str |
要安装到哪里。 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
preserve_path |
布尔值 |
在安装时禁用从头文件中剥离子目录。 这等效于 GNU Automake 的 |
(从 0.63.0 开始)
|
subdir |
str |
安装到默认 includedir 的 与 |
|
install_man()
在安装步骤期间,将源树中的指定手册文件安装到系统的 man 目录中。此目录可以通过使用 install_dir 关键字参数指定来覆盖。
(自 0.49.0 起) 手册页不再被隐式压缩。
签名
# Installs the specified man files from the source tree into system's man directory
void install_man(
file | str file..., # Man pages to install
# Keyword arguments:
install_dir : str # Where to install to
install_mode : list[str | int] # Specify the file mode in symbolic format
locale : str # Can be used to specify the locale
)
install_mode kwarg 在 0.59.0 -- 1.1.0 之间的整数值被忽略。
参数
该函数接受 0 到 无穷大 之间的可变参数(file...),类型为 。file | str
要安装的手册页。
函数 install_man() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
install_dir |
str |
要安装到哪里。 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
locale |
str |
可用于指定手册页将在手册页目录树中安装到的区域设置。例如,一个手册可能是 |
(从 0.58.0 开始) |
install_subdir()
将给定的整个子目录及其内容从源树安装到关键字参数 install_dir 指定的位置。
(自 0.45.0 起,自 0.60.0 起已弃用) 如果子目录不存在于源树中,则会在指定位置创建一个空目录。新创建的子目录只能在关键字参数 install_dir 中创建。此方法存在许多缺陷,并且它从未被有意设计为以这种方式工作,请改用 install_emptydir()。
签名
# Installs the entire given subdirectory and its contents from the
void install_subdir(
str subdir_name, # The sub-directory to install
# Keyword arguments:
exclude_directories : list[str] # A list of directory names that should not be installed
exclude_files : list[str] # A list of file names that should not be installed
follow_symlinks : bool # If true, dereferences links and copies their target instead
install_dir : str # Where to install to
install_mode : list[str | int] # Specify the file mode in symbolic format
install_tag : str # A string used by the `meson install --tags` command
strip_directory : bool # Install directory contents
)
示例
对于给定的目录 foo
foo/
bar/
file1
file2
install_subdir('foo', install_dir : 'share', strip_directory : false) 创建
share/
foo/
bar/
file1
file2
install_subdir('foo', install_dir : 'share', strip_directory : true) 创建
share/
bar/
file1
file2
install_subdir('foo/bar', install_dir : 'share', strip_directory : false) 创建
share/
bar/
file1
install_subdir('foo/bar', install_dir : 'share', strip_directory : true) 创建
share/
file1
install_subdir('new_directory', install_dir : 'share') 创建
share/
new_directory/
install_mode kwarg 在 0.59.0 -- 1.1.0 之间的整数值被忽略。
参数
函数 install_subdir() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
subdir_name |
str |
要安装的子目录 |
|
最后,install_subdir() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
exclude_directories |
list[str] |
不应该安装的目录名称列表。名称被解释为相对于 |
(自 0.47.0 版本起) |
exclude_files |
list[str] |
不应该安装的文件名称列表。名称被解释为相对于 |
|
follow_symlinks |
布尔值 |
如果为 true,则取消引用链接并复制其目标。默认值将在将来变为 false。 |
(自 1.3.0 版本起)
|
install_dir |
str |
要安装到哪里。 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_tag |
str |
|
(自 0.60.0 版本起) |
strip_directory |
布尔值 |
安装目录内容。如果 |
(自 0.45.0 起)
|
install_symlink()
在 install_dir 下安装指向 pointing_to 目标的符号链接。
签名
(自 0.61.0 起)
# Installs a symbolic link to `pointing_to` target under install_dir
void install_symlink(
str link_name, # Name of the created link under `install_dir`
# Keyword arguments:
install_dir : str [required] # The absolute or relative path to the installation directory for the links
install_tag : str # A string used by the `meson install --tags` command
pointing_to : str [required] # Target to point the link to
)
参数
函数 install_symlink() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
link_name |
str |
在 |
|
最后,install_symlink() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
install_dir |
str |
链接的安装目录的绝对或相对路径。如果这是一个相对路径,则假定它相对于前缀。 |
|
install_tag |
str |
|
|
pointing_to |
str |
指向链接的目标。可以是绝对路径或相对路径,创建链接时将予以保留。 |
|
is_disabler()
如果一个变量是禁用器则返回 true,否则返回 false。
签名
(从 0.52.0 开始)
# Returns true if a variable is a disabler and false otherwise
bool is_disabler(
any var, # The variable to test
)
参数
函数 is_disabler() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
var |
any |
要测试的变量 |
|
is_variable()
如果给定名称的变量存在则返回 true,否则返回 false。
签名
(从 0.52.0 开始)
# Returns true if a variable of the given name exists and false otherwise
bool is_variable(
str var, # The variable to test
)
参数
函数 is_variable() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
var |
str |
要测试的变量 |
|
jar()
从指定的 Java 源文件构建一个 jar。关键字参数与 executable() 的相同,并添加了 main_class,它指定了使用 java -jar file.jar 运行 jar 时要执行的主类。
签名
# Build a jar from the specified Java source files
jar jar(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
java_resources : structured_src # Resources to be added to the jar
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
main_class : str # Main class for running the built jar
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
vala_args : list[str | file] # Compiler flags for Vala
win_subsystem : str # Specifies the subsystem type to use
)
参数
函数 jar() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,jar() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
java_resources |
structured_src |
要添加到 jar 的资源 |
(自 0.62.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
main_class |
str |
运行构建的 jar 的主类 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
join_paths()
将给定的字符串连接成一个文件系统路径段。例如 join_paths('foo', 'bar') 的结果为 foo/bar。如果其中一个段是绝对路径,则前面的所有段都会被删除。这意味着 join_paths('foo', '/bar') 返回 /bar。
(自 0.49.0 起) 在字符串上使用 / 运算符等效于调用 join_paths()。
# res1 and res2 will have identical values
res1 = join_paths(foo, bar)
res2 = foo / bar
签名
(自 0.36.0 起)
# Joins the given strings into a file system path segment
str join_paths(
str part..., # The path parts to join
)
不要在 library() 和 executable() 中使用 join_paths() 来获取源代码。你应该使用 files() 来代替。
参数
该函数接受 1 到 infinity 个可变参数 (part...) 类型为 。str
要连接的路径部分。
library()
构建一个库,它可以是静态的、共享的或两者兼而有之,具体取决于 default_library 用户 选项 的值。你应该使用它而不是 shared_library()、static_library() 或 both_libraries(),因为它们在大多数情况下都适用。这使你能够仅通过一个选项来切换整个项目(包括子项目)从共享库到静态库。此选项适用于在整个项目内部构建的库。对于外部依赖项,首选的默认库类型是共享库。可以使用 dependency() 的 static 关键字来根据每个库进行调整。
此处的关键字参数与 build_target() 相同
签名
# Builds a library that is either static, shared or both depending on
lib library(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
<lang>_shared_args : list[str] # Arguments that are only passed to a shared library
<lang>_static_args : list[str] # Arguments that are only passed to a static library
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
darwin_versions : str | int | list[str] # Defines the `compatibility version` and `current version` for the dylib on macOS
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
pic : bool # Builds the library as positional independent code
prelink : bool # If `true` the object files in the target will be prelinked,
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
soversion : str | int # A string or integer specifying the soversion of this shared library,
vala_args : list[str | file] # Compiler flags for Vala
vala_shared_args : list[str | file] # Arguments that are only passed to a shared library
vala_static_args : list[str | file] # Arguments that are only passed to a static library
version : str # A string specifying the version of this shared library,
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
使用
参数
函数 library() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,library() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
<lang>_shared_args |
list[str] |
仅传递给共享库的参数 |
(自 1.3.0 版本起) |
<lang>_static_args |
list[str] |
仅传递给静态库的参数 |
(自 1.3.0 版本起) |
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
darwin_versions |
str | int | list[str] |
定义 macOS 上 dylib 的 |
(从 0.48.0 开始) |
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
pic |
布尔值 |
将库构建为位置无关代码(因此可以链接到共享库)。此选项对 Windows 和 OS X 没有影响,因为在 Windows 上没有意义,并且在 OS X 上无法禁用 PIC。 |
(自 0.36.0 起) |
预链接 |
布尔值 |
如果为 |
(从 0.57.0 开始) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
soversion |
str | int |
指定此共享库的 soversion 的字符串或整数,例如 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
vala_shared_args |
list[str | file] |
仅传递给共享库的参数,例如 |
(自 1.3.0 版本起) |
vala_static_args |
list[str | file] |
仅传递给静态库的参数,例如 |
(自 1.3.0 版本起) |
版本 |
str |
指定此共享库版本的字符串,例如 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 (自 1.3.0 起) 支持 |
|
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
message()
此函数将它的参数打印到标准输出。
签名
# This function prints its argument to stdout
void message(
str | int | bool | list[str | int | bool] | dict[str | int | bool] text, # The message to print
str | int | bool | list[str | int | bool] | dict[str | int | bool] more_text..., # Additional text that will be printed separated by spaces
)
参数
参数扁平化 不支持 此函数。
函数 message() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
text |
str | int | bool | list[str | int | bool] | dict[str | int | bool] |
要打印的消息。 |
|
此外,该函数接受 0 到 infinity 个可变参数 (more_text...) 类型为 。str | int | bool | list[str | int | bool] | dict[str | int | bool]
将打印的附加文本,用空格分隔。
(从 0.54.0 开始)
project()
每个项目中调用的第一个函数,用于初始化 Meson。
此函数的第一个参数必须是一个字符串,用于定义此项目的名称。
项目名称可以是任何你想要的字符串,它除了描述性目的以外没有其他用途。但是,由于它被写入例如依赖项清单,因此通常有意义的是使其与项目压缩包或 pkg-config 名称相同。因此,例如,你可能希望使用名称 libfoobar 而不是 The Foobar Library。
它后面可以是项目使用的编程语言列表。
(自 0.40.0 起) 语言列表是可选的。
这些语言既可用于 native: false(默认值)(主机)目标,也可用于 native: true(构建机器)目标。(自 0.56.0 起) 不需要为指定的语言构建机器编译器。
语言支持的值为 c、cpp(用于 C++)、cuda、cython、d、objc、objcpp、fortran、java、cs(用于 C#)、vala 和 rust。
签名
# The first function called in each project, to initialize Meson
void project(
str project_name, # The name of the project
str language..., # The languages that Meson should initialize
# Keyword arguments:
default_options : list[str] | dict[str | bool | int | list[str]] # Accepts strings in the form `key=value`
license : str | list[str] # Takes a string or array of strings describing the license(s) the code is under
license_files : str | list[str] # Takes a string or array of strings with the paths to the license file(s)
meson_version : str # Takes a string describing which Meson version the project requires
subproject_dir : str # Specifies the top level directory name that holds Meson subprojects
version : str | file # A free form string describing the version of this project
)
参数
函数 project() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
project_name |
str |
项目的名称。 |
|
此外,该函数接受 0 到 infinity 个可变参数 (language...) 类型为 。str
Meson 应该初始化的语言。
最后,project() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
default_options |
list[str] | dict[str | bool | int | list[str]] |
接受 请注意,某些选项可能会覆盖默认行为;例如,在此处使用 (自 1.2.0 起):现在可以传入字典。 |
|
license |
str | list[str] |
接受一个字符串或字符串数组,用于描述代码所采用的许可证。 这应该是 SPDX 许可证表达式,使用来自 SPDX 许可证列表 的标准化许可证标识符。通常,这应该是类似于 为了向后兼容,你也可以在此处传入许可证数组。不建议这样做,因为它很模糊: 请注意,该文本是非正式的,只写入依赖项清单。Meson 不会进行任何许可证验证,你负责验证你是否遵守所有许可条款。你可以在 Meson 构建文件中使用 |
|
license_files |
str | list[str] |
接受一个字符串或字符串数组,其中包含代码所采用的许可证文件路径。 这通过允许指定简短的许可证名称和完整的许可证文本来增强 请注意,这些文件是非正式的,只与依赖项清单一起安装。Meson 不会进行任何许可证验证,你负责验证你是否遵守所有许可条款。你可以在 Meson 构建文件中使用 |
(从 1.1.0 开始) |
meson_version |
str |
接受一个字符串,用于描述项目需要的 Meson 版本。通常是类似于 |
|
subproject_dir |
str |
指定包含 Meson 子项目的顶层目录名称。这仅用作对现有代码库的兼容性选项,这些代码库将它们嵌入的源代码保存在自定义目录中。所有新项目都不应该设置此选项,而是使用默认值。需要注意的是,此关键字参数在子项目中会被忽略。只能有一个子项目目录,它是在顶层 Meson 文件中设置的。 |
|
版本 |
str | file |
一个自由格式的字符串,用于描述此项目的版本。你可以在 Meson 构建文件中使用 |
|
range()
返回一个不透明对象,该对象只能在 foreach 语句中使用。
range range(int stop)
range range(int start, int stop[, int step])
-
start必须是大于或等于 0 的整数。默认为 0。 -
stop必须是大于或等于start的整数。 -
step必须是大于或等于 1 的整数。默认为 1。
它使 foreach 循环在每次循环后使用从 start(包含)到 stop(不包含)的值,以 step 为增量。
签名
(从 0.58.0 开始)
# Return an opaque object that can be only be used in `foreach` statements
range range(
int [start], # The start of the range
int [stop], # The end of the range
int [step], # The loop increment
)
示例
# Loop 15 times with i from 0 to 14 included.
foreach i : range(15)
...
endforeach
range 对象也可以分配给变量并进行索引。
r = range(5, 10, 2)
assert(r[2] == 9)
参数
函数 range() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
start |
int |
范围的起点 |
[可选]
|
stop |
int |
范围的终点 |
[可选] |
step |
int |
循环增量 |
[可选]
|
run_command()
运行位置参数中指定的命令。command 可以是字符串,也可以是 find_program()、files() 或 configure_file() 的输出,或 编译器对象。
返回一个 runresult 对象,其中包含调用结果。命令从未指定的目录运行,Meson 将设置三个环境变量 MESON_SOURCE_ROOT、MESON_BUILD_ROOT 和 MESON_SUBDIR,分别指定目标定义的源目录、构建目录和子目录。
另请参阅 外部命令。
签名
# Runs the command specified in positional arguments
runresult run_command(
str | file | external_program command..., # The command to execute during the setup process
# Keyword arguments:
capture : bool # If `true`, any output generated on stdout will be captured and returned by
check : bool # If `true`, the exit status code of the command will be checked,
env : env | list[str] | dict[str] # environment variables to set,
)
参数
该函数接受 0 到 无穷大 个可变参数(command...),类型为 。str | file | external_program
在设置过程中要执行的命令。
函数 run_command() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
捕获 |
布尔值 |
如果为 |
(自 0.47.0 版本起)
|
check |
布尔值 |
如果为 |
(自 0.47.0 版本起)
|
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
(自 0.50.0 版本起) |
run_target()
此函数创建一个新的顶级目标,该目标以指定参数运行指定命令。与所有顶级目标一样,它与所选后端集成。例如,您可以将其运行为 meson compile target_name。请注意,运行目标不生成 Meson 所关心的任何输出。它仅用于运行代码格式化程序或使用构建文件刷新外部设备的固件等任务。
命令从未指定的目录运行,Meson 将设置三个环境变量 MESON_SOURCE_ROOT、MESON_BUILD_ROOT 和 MESON_SUBDIR,分别指定目标定义的源目录、构建目录和子目录。
自 0.57.0 起 传递给 command 关键字参数的模板字符串接受以下特殊替换
-
@SOURCE_ROOT@:源树根目录的路径。根据后端,这可能是绝对路径或相对于当前工作目录的路径。 -
@BUILD_ROOT@:构建树根目录的路径。根据后端,这可能是绝对路径或相对于当前工作目录的路径。 -
@CURRENT_SOURCE_DIR@自 0.57.1 起:这是当前处理的 meson.build 所在的目录。根据后端,这可能是绝对路径或相对于当前工作目录的路径。
签名
# This function creates a new top-level target that runs a specified
run_tgt run_target(
str target_name, # The name of the run target
# Keyword arguments:
command : list[exe | external_program | custom_tgt | file | str] # A list containing the command to run and the arguments
depends : list[build_tgt | custom_tgt | custom_idx] # A list of targets that this target depends on but which
env : env | list[str] | dict[str] # environment variables to set, such as
)
参数
函数 run_target() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
运行目标的名称 |
|
最后,run_target() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
命令 |
list[exe | external_program | custom_tgt | file | str] |
包含要运行的命令和要传递给它的参数的列表。每个列表项可以是字符串或目标。例如,将 |
|
取决于 |
list[build_tgt | custom_tgt | custom_idx] |
此目标依赖的但未列在命令数组中的目标列表(因为,例如,脚本在内部执行文件通配符,custom_idx 在 0.60 到 1.4.0 之间无法作为类型)。 |
|
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
(从 0.57.0 开始) |
set_variable()
将值分配给给定的变量名。调用 set_variable('foo', bar) 等效于 foo = bar。
(自 0.46.1 起) value 参数可以是数组类型。
签名
# Assigns a value to the given variable name
void set_variable(
str variable_name, # The name of the variable to set
any value, # The value to set the variable to
)
参数
参数扁平化 不支持 此函数。
函数 set_variable() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
variable_name |
str |
要设置的变量的名称 |
|
value |
any |
要设置的变量的值 |
|
shared_library()
使用给定的源构建共享库。
签名
# Builds a shared library with the given sources
lib shared_library(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
darwin_versions : str | int | list[str] # Defines the `compatibility version` and `current version` for the dylib on macOS
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
soversion : str | int # A string or integer specifying the soversion of this shared library,
vala_args : list[str | file] # Compiler flags for Vala
version : str # A string specifying the version of this shared library,
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
参数
函数 shared_library() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,shared_library() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
darwin_versions |
str | int | list[str] |
定义 macOS 上 dylib 的 |
(从 0.48.0 开始) |
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
soversion |
str | int |
指定此共享库的 soversion 的字符串或整数,例如 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
版本 |
str |
指定此共享库版本的字符串,例如 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 (自 1.3.0 起) 支持 |
|
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
shared_module()
使用给定的源构建共享模块。
这对于构建将被 dlopen() 并且因此可能包含未定义符号的模块很有用,这些符号将由加载它的库提供。
如果您希望共享模块能够引用由加载它的 executable() 定义的函数和变量,则需要将可执行文件的 export_dynamic 参数设置为 true。
签名
(从 0.37.0 开始)
# Builds a shared module with the given sources
build_tgt shared_module(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
vala_args : list[str | file] # Compiler flags for Vala
vs_module_defs : str | file | custom_tgt | custom_idx # Specify a Microsoft module definition file for controlling symbol exports,
win_subsystem : str # Specifies the subsystem type to use
)
在 Android 以外的平台上链接到共享模块已弃用,将来将成为错误。它以前被允许是因为它是具有对未定义符号的引用的共享库式目标的唯一方法。但是,自 0.40.0 起,override_options: build_target() 关键字参数可用于通过传递 override_options: 'b_lundef=false' 来创建这样的 shared_library()。共享模块具有其他特性,使其与链接不兼容,例如缺乏 SONAME。在 macOS 和 iOS 上,链接器不允许链接到共享模块,因此我们在配置时禁止这样做。在 Android 上,如果共享模块 foo 使用另一个共享模块 bar 中的符号,则 foo 还必须链接到 bar。因此,在为 Android 构建时,将始终允许将一个共享模块链接到另一个共享模块。
参数
函数 shared_module() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,shared_module() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
vs_module_defs |
str | file | custom_tgt | custom_idx |
指定一个 Microsoft 模块定义文件,用于在支持该功能的平台(例如 Windows)上控制符号导出等。 (自 1.3.0 起) 支持 |
(从 0.52.0 开始) |
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
static_library()
使用给定的源构建静态库。
签名
# Builds a static library with the given sources
lib static_library(
str target_name, # The *unique* name of the build target
str | file | custom_tgt | custom_idx | generated_list source..., # Input source to compile
# Keyword arguments:
<lang>_args : list[str] # compiler flags to use for the given language;
<lang>_pch : str # precompiled header file to use for the given language
build_by_default : bool # Causes, when set to `true`, to have this target be built by default
build_rpath : str # A string to add to target's rpath definition in the build dir,
d_debug : list[str] # The [D version identifiers](https://dlang
d_import_dirs : list[inc | str] # the directories to add to the string search path (i
d_module_versions : list[str | int] # List of module version identifiers set when compiling D sources
d_unittest : bool # When set to true, the D modules are compiled in debug mode
dependencies : list[dep] # one or more dependency objects
extra_files : str | file | custom_tgt | custom_idx # Not used for the build itself but are shown as source files in IDEs
gnu_symbol_visibility : str # Specifies how symbols should be exported, see
gui_app : bool # When set to true flags this target as a GUI application
implicit_include_directories : bool # Controls whether Meson adds the current source and build directories to the include path
include_directories : list[inc | str] # one or more objects created with the include_directories() function,
install : bool # When set to true, this executable should be installed
install_dir : str # override install directory for this file
install_mode : list[str | int] # Specify the file mode in symbolic format
install_rpath : str # A string to set the target's rpath to after install
install_tag : str # A string used by the `meson install --tags` command
link_args : list[str] # Flags to use during linking
link_depends : str | file | custom_tgt | custom_idx # Strings, files, or custom targets the link step depends on
link_language : str # Makes the linker for this target be for the specified language
link_whole : list[lib | custom_tgt | custom_idx] # Links all contents of the given static libraries whether they are used or
link_with : list[lib | custom_tgt | custom_idx] # One or more shared or static libraries
name_prefix : str | list[void] # The string that will be used as the prefix for the
name_suffix : str | list[void] # The string that will be used as the extension for the
native : bool # Controls whether the target is compiled for the build or host machines
objects : list[extracted_obj | file | str] # List of object files that should be linked in this target
override_options : list[str] | dict[str | bool | int | list[str]] # takes an array of strings in the same format as `project`'s `default_options`
pic : bool # Builds the library as positional independent code
prelink : bool # If `true` the object files in the target will be prelinked,
rust_abi : str # Set the specific ABI to compile (when compiling rust)
rust_crate_type : str # Set the specific type of rust crate to compile (when compiling rust)
rust_dependency_map : dict[str] # On rust targets this provides a map of library names to the crate name
sources : str | file | custom_tgt | custom_idx | generated_list | structured_src # Additional source files
vala_args : list[str | file] # Compiler flags for Vala
win_subsystem : str # Specifies the subsystem type to use
)
参数
函数 static_library() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
目标名称 |
str |
构建目标的唯一名称 |
|
此外,该函数接受 0 到 infinity 之间的可变参数(source...),其类型为 。str | file | custom_tgt | custom_idx | generated_list
要编译的输入源。支持以下类型
- 相对于当前源目录的字符串
-
在任何前面的构建文件中定义的
file对象 - 配置时生成器(如
configure_file())的返回值 - 构建时生成器(如
custom_target()或generator.process())的返回值
这些输入文件可以是源代码、对象、库或任何其他文件。Meson 会根据扩展名自动对它们进行分类并相应地使用它们。例如,源代码 (.c, .cpp, .vala, .rs 等) 将被编译,而对象 (.o, .obj) 和库 (.so, .dll 等) 将被链接。
使用 Ninja 后端时,Meson 将在构建时为所有生成的输入文件(包括未知文件)创建 顺序依赖项。这是在 依赖文件 中生成真正的依赖项所需的,该依赖文件由编译器生成,以确定何时重建源代码。Ninja 依靠此依赖文件来处理所有输入文件(生成的和未生成的)。其他后端的行为类似。
最后,static_library() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
<lang>_args |
list[str] |
要为给定语言使用的编译器标志;例如: |
|
<lang>_pch |
str |
要为给定语言使用的预编译头文件 |
|
build_by_default |
布尔值 |
当设置为 |
(自 0.38.0 版本起)
|
build_rpath |
str |
要添加到构建目录中目标的 rpath 定义中的字符串,但在安装时会删除 |
(自 0.42.0 版本起) |
d_debug |
list[str] |
在编译 D 源文件时要添加的 D 版本标识符。 |
|
d_import_dirs |
list[inc | str] |
要添加到字符串搜索路径(即 DMD 的 |
(自 0.62.0 版本起) |
d_module_versions |
list[str | int] |
编译 D 源代码时设置的模块版本标识符列表。 |
|
d_unittest |
布尔值 |
设置为 true 时,D 模块将在调试模式下编译。 |
|
dependencies |
list[dep] |
一个或多个使用 |
|
extra_files |
str | file | custom_tgt | custom_idx |
本身不用于构建,但会显示为 IDE 中按目标分组的文件(例如 Visual Studio)的源文件 |
|
gnu_symbol_visibility |
str |
指定如何导出符号,例如参阅 GCC Wiki 以获取更多信息。此值可以为空字符串,也可以是 |
(从 0.48.0 开始) |
gui_app |
布尔值 |
当设置为 true 时,在平台上有区别的地方,将此目标标记为 GUI 应用程序,已弃用,自 0.56.0 版本起,请使用 |
已弃用 在 0.56.0 版本中
|
implicit_include_directories |
布尔值 |
控制 Meson 是否将当前源目录和构建目录添加到包含路径 |
(自 0.42.0 版本起)
|
include_directories |
list[inc | str] |
一个或多个使用 |
|
install |
布尔值 |
当设置为 true 时,应安装此可执行文件。 |
|
install_dir |
str |
覆盖此文件的安装目录。如果值为相对路径,则该路径将被视为相对于 |
|
install_mode |
list[str | int] |
以符号格式指定文件模式,并可选地为安装的文件指定所有者/uid 和组/gid。 有关更多信息,请参阅 |
(自 0.47.0 版本起) |
install_rpath |
str |
在安装后(但不是之前)设置目标的 rpath 的字符串。在 Windows 上,此参数无效。 |
|
install_tag |
str |
|
(自 0.60.0 版本起) |
link_args |
list[str] |
链接期间要使用的标志。您可以在此处对所有平台使用类 UNIX 标志。 |
|
link_depends |
str | file | custom_tgt | custom_idx |
链接步骤依赖的字符串、文件或自定义目标,例如符号可见性映射。目的是在该文件更改时自动触发目标的重新链接(但不重新编译)。 |
|
link_language |
str |
使此目标的链接器成为指定语言的链接器。通常不需要设置此选项,因为 Meson 会在大多数情况下检测到要使用的正确链接器。只有两种情况下需要设置此选项。第一种情况是,可执行文件中的主函数不在 Meson 选择的语言中,第二种情况是,要强制库仅使用一种 ABI。 (在 0.55.0 版本之前已损坏) |
(自 0.51.0 版本起) |
link_whole |
list[lib | custom_tgt | custom_idx] |
链接给定静态库的所有内容,无论它们是否被使用,等效于 GCC 的 (自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。 (自 0.51.0 版本起) 此参数也接受自定义目标产生的输出。用户必须确保输出是正确格式的库。 |
(自 0.40.0 版本起) |
link_with |
list[lib | custom_tgt | custom_idx] |
一个或多个应与该目标链接的共享库或静态库(由该项目构建)。(自 0.41.0 版本起) 如果传递了一个列表,则该列表将被扁平化。(自 0.51.0 版本起) 参数也可以是自定义目标。在这种情况下,Meson 将假定,仅仅在链接器命令行中添加输出文件就足以使链接工作。如果这还不够,则构建系统编写者必须手动编写所有其他步骤。 |
|
name_prefix |
str | list[void] |
将用作目标输出文件名的前缀的字符串,通过覆盖默认值(仅用于库)。默认情况下,在所有平台和编译器上,此值为 将其设置为 |
|
name_suffix |
str | list[void] |
将用作目标扩展名的字符串,通过覆盖默认值。默认情况下,在 Windows 上,可执行文件为 对于共享库,默认值为 macOS 上的 将其设置为 |
|
本机 |
布尔值 |
控制目标是为构建机器还是主机编译。 |
|
对象 |
list[extracted_obj | file | str] |
应在此目标中链接的对象文件列表。 自 1.1.0 起,这可以包括除了您没有源代码的对象文件或其他构建目标生成的对象文件以外的生成文件。在早期版本中,生成的 对象文件必须放置在 |
|
覆盖选项 |
list[str] | dict[str | bool | int | list[str]] |
采用与 |
(自 0.40.0 版本起) |
pic |
布尔值 |
将库构建为位置无关代码(因此可以链接到共享库)。此选项对 Windows 和 OS X 没有影响,因为在 Windows 上没有意义,并且在 OS X 上无法禁用 PIC。 |
(自 0.36.0 起) |
预链接 |
布尔值 |
如果为 |
(从 0.57.0 开始) |
rust_abi |
str |
设置要编译的特定 ABI(在编译 rust 时)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
设置要编译的特定类型的 rust crate(在编译 rust 时)。 如果目标是 如果它是 如果它是 "proc-macro" 是在 0.62.0 中新增的。 自 1.3.0 起,这已弃用,并被 "rust_abi" 关键字参数替换。 |
(自 0.42.0 版本起) 已弃用 在 1.3.0 中 |
rust_dependency_map |
dict[str] |
在 rust 目标上,它提供了库名称到它在 rust 代码中可用的 crate 名称的映射。 这允许重命名,类似于 cargo 的依赖项重命名功能或 rust 代码中的 |
(自 1.2.0 起) |
来源 |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
额外的源文件。与源可变参数相同。 |
|
vala_args |
list[str | file] |
Vala 的编译器标志。与其他语言不同,它可以包含文件 |
|
win_subsystem |
str |
指定在 Windows 平台上使用的子系统类型。典型值包括用于文本模式程序的 |
(自 0.56.0 起)
|
structured_sources()
创建一个 StructuredSource 对象,该对象是不透明的,可以作为源传递给任何 build_target(包括 static_library、shared_library、executable 等)。这对 Rust 等使用文件系统布局确定导入名称的语言很有用。这仅在 Rust 目标中允许,不能与非结构化输入混合使用。
签名
(自 0.62.0 版本起)
# Create a StructuredSource object, which is opaque and may be passed as a source
structured_src structured_sources(
list[str | file | custom_tgt | custom_idx | generated_list] root, # Sources to put at the root of the generated structure
dict[str | file | custom_tgt | custom_idx | generated_list] [additional], # Additional sources, where the key is the directory under the root to place
)
参数
函数 structured_sources() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
root |
list[str | file | custom_tgt | custom_idx | generated_list] |
要放在生成的结构根目录下的源 |
|
additional |
dict[str | file | custom_tgt | custom_idx | generated_list] |
其他源,其中键是要将值放置在根目录下的目录 |
[可选] |
subdir()
进入指定的子目录并在其中执行 meson.build 文件。完成后,它将返回,执行将在此 subdir() 命令后的下一行继续。然后,在该 meson.build 文件中定义的变量可供在当前构建文件的后续部分以及使用 subdir() 执行的所有后续构建文件中使用。
请注意,这意味着源树中的每个 meson.build 文件只能并且必须执行一次。
签名
# Enters the specified subdirectory and executes the `meson
void subdir(
str dir_name, # Directory relative to the current `meson
# Keyword arguments:
if_found : list[dep] # Only enter the subdir if all dep.found() methods return `true`.
)
参数
函数 subdir() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
dir_name |
str |
相对于当前 不能包含 |
|
最后,subdir() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
if_found |
list[dep] |
仅当所有 |
(从 0.44.0 开始) |
subdir_done()
停止从调用点开始进一步解释 Meson 脚本文件。执行到此点的所有步骤都是有效的,并将由 Meson 执行。这意味着在调用 subdir_done() 之前定义的所有目标都将被构建。
如果当前脚本是由 subdir 调用的,则执行将返回到调用目录并继续执行,就好像脚本已到达结尾一样。如果当前脚本是顶级脚本,则 Meson 将根据到目前为止定义的内容配置项目。
签名
(从 0.46.0 开始)
void subdir_done()
示例
project('example exit', 'cpp')
executable('exe1', 'exe1.cpp')
subdir_done()
executable('exe2', 'exe2.cpp')
可执行文件 exe1 将被构建,而可执行文件 exe2 不会被构建。
subproject()
获取位置参数中指定的项目,并通过返回 subproject 对象将其引入当前构建规范。子项目必须始终放在顶级源目录的 subprojects 目录内。例如,名为 foo 的子项目必须位于 ${MESON_SOURCE_ROOT}/subprojects/foo 中。
-
default_options(自 0.37.0 起):默认选项值数组,覆盖子项目meson.options中设置的值(如project中的default_options,它们仅在 Meson 首次运行时有效,命令行参数会覆盖构建文件中的任何默认选项)。(自 0.54.0 起):还可以覆盖default_library内置选项。(自 1.2.0 起):现在可以传递字典而不是数组。 -
version:工作方式与dependency中的相同。它指定子项目应该是什么版本,例如>=1.0.1 -
required(自 0.48.0 起):默认情况下,required为true,如果子项目无法设置,Meson 将中止。您可以将其设置为false,然后在subproject对象上使用.found()方法。您也可以传递feature选项的值,与dependency()相同。
请注意,您可以使用返回的 subproject 对象访问子项目中的任何变量。但是,如果您想从子项目内部使用依赖项对象,更简单的方法是使用 dependency() 的 fallback: 关键字参数。
签名
# Takes the project specified in the positional argument and brings that
subproject subproject(
str subproject_name, # Name of the subproject
# Keyword arguments:
default_options : list[str] | dict[str | bool | int | list[str]] # An array of default option values
required : bool | feature # Works just the same as in dependency().
version : str # Works just like the same as in dependency().
)
参数
函数 subproject() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
subproject_name |
str |
子项目的名称。子项目必须作为目录或包装文件存在于 |
|
最后,subproject() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
default_options |
list[str] | dict[str | bool | int | list[str]] |
默认选项值数组,覆盖子项目 |
(从 0.37.0 开始) |
必需 |
bool | feature |
工作方式与 |
(从 0.48.0 开始)
|
版本 |
str |
工作方式与 |
|
summary()
此函数用于在构建过程结束时总结构建配置。此函数提供了一种方式让项目(和子项目)以清晰的方式报告此信息。
内容是一系列键值对,分组到各个部分。如果省略 section 关键字参数,则这些键值对会隐式分组到没有标题的部分。键值对可以可选地分组到字典中,但请记住字典不保证排序。key 必须是字符串,value 可以是
- 整数、布尔值或字符串
- 从 0.57.0 版本开始,外部程序或依赖项
- 从 0.58.0 版本开始,功能选项
- 这些的列表。
除了调用 summary 作为 summary(key, value) 之外,还可以直接将字典传递给 summary() 函数,如以下示例所示。
summary() 可以被多次调用,只要相同的 section/key 对不会出现两次。所有 section 将在配置结束时按调用顺序收集并打印。
签名
(从 0.53.0 开始)
# This function is used to summarize build configuration at the end of the build
void summary(
str | dict[str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]] key_or_dict, # The name of the new entry, or a dict containing multiple entries
str | bool | int | dep | external_program | list[str | bool | int | dep | external_program] [value], # The value to print for the `key`
# Keyword arguments:
bool_yn : bool # Convert bool values to yes and no
list_sep : str # The separator to use when printing list values in this summary
section : str # The section to put this summary information under
)
示例
示例 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')
输出
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
参数
参数扁平化 不支持 此函数。
函数 summary() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
key_or_dict |
str | dict[str | bool | int | dep | external_program | list[str | bool | int | dep | external_program]] |
新条目的名称,或包含多个条目的字典。如果传递了字典,则等同于为每个键值对调用一次 summary()。请记住,字典不保证顺序。 |
|
value |
str | bool | int | dep | external_program | list[str | bool | int | dep | external_program] |
要为 |
[可选] |
最后,summary() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
bool_yn |
布尔值 |
将布尔值转换为 yes 和 no |
|
list_sep |
str |
在打印此摘要中的列表值时使用的分隔符。如果没有指定分隔符,则每个列表项将单独打印在一行上。 |
(从 0.54.0 开始) |
section |
str |
放置此摘要信息的 section。如果省略 section 关键字参数,则键值对将隐式地分组到没有标题的 section 中。 |
|
test()
定义一个使用测试工具运行的测试。接受两个位置参数,第一个是测试的名称,第二个是要运行的可执行文件。可执行文件可以是 exe 对象(由 executable() 返回)或 external_program 对象(由 find_program() 返回)。
(从 0.55.0 版本开始),在交叉编译时,如果需要 exe_wrapper 并已定义,则环境变量 MESON_EXE_WRAPPER 将被设置为该包装器的字符串值(实现细节:使用 mesonlib.join_args)。测试脚本可以使用它来运行交叉构建的二进制文件。如果您的测试在交叉构建情况下需要 MESON_EXE_WRAPPER,则您有责任返回代码 77 以告知工具报告“跳过”。
默认情况下,环境变量 MALLOC_PERTURB_ 会被 meson test 自动设置为 1..255 之间的随机值。这可以帮助在使用 glibc 的配置中找到内存泄漏,包括使用非 GCC 编译器。但是,这可能会影响性能,并可能因外部库而导致测试失败,而这些库的内部细节不受用户控制。要检查此功能是否导致预期的运行时崩溃,请通过暂时设置环境变量 MALLOC_PERTURB_=0 来禁用此功能。虽然最好只暂时禁用此检查,但如果项目需要在 meson.build 中永久禁用此检查,请执行以下操作:
nomalloc = environment({'MALLOC_PERTURB_': '0'})
test(..., env: nomalloc, ...)
默认情况下,环境变量 ASAN_OPTIONS、UBSAN_OPTIONS 和 MSAN_OPTIONS 被设置为在检测到违规时中止并提供回溯。要抑制此行为,可以在环境中设置 ASAN_OPTIONS、UBSAN_OPTIONS 或 MSAN_OPTIONS。
除了将单个可执行文件作为测试用例运行外,test() 还可以用于调用外部测试工具。在这种情况下,最好使用 verbose: true (从 0.62.0 版本开始),以及在外部工具支持的情况下使用 protocol: 'tap' (从 0.50.0 版本开始)。这将确保 Meson 在每个子测试运行时记录它,而不是在运行结束时包含整个日志。
可以通过在构建目录中调用 meson test 或使用特定于后端的命令(例如 ninja test 或 msbuild RUN_TESTS.vcxproj)以与后端无关的方式运行定义的测试。
签名
# Defines a test to run with the test harness
void test(
str name, # The *unique* test id
exe | jar | external_program | file | custom_tgt | custom_idx executable, # The program to execute
# Keyword arguments:
args : list[str | file | tgt | external_program] # Arguments to pass to the executable
depends : list[build_tgt | custom_tgt] # specifies that this test depends on the specified
env : env | list[str] | dict[str] # environment variables to set, such as `['NAME1=value1',
is_parallel : bool # when false, specifies that no other test must be
priority : int # specifies the priority of a test
protocol : str # specifies how the test results are parsed and can
should_fail : bool # when true the test is considered passed if the
suite : str | list[str] # `'label'` (or list of labels `['label1', 'label2']`)
timeout : int # the amount of seconds the test is allowed to run, a test
verbose : bool # if true, forces the test results to be logged as if `--verbose` was passed
workdir : str # absolute path that will be used as the working directory
)
参数
函数 test() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
名称 |
str |
唯一 测试 ID |
|
可执行文件 |
exe | jar | external_program | file | custom_tgt | custom_idx |
要执行的程序。(从 1.4.0 开始) 也接受 CustomTarget。 |
|
最后,test() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
args |
list[str | file | tgt | external_program] |
传递给可执行文件的参数 |
|
取决于 |
list[build_tgt | custom_tgt] |
指定此测试依赖于指定的目标,即使它没有将任何目标作为命令行参数。这适用于测试在内部找到这些目标的情况,例如插件或通配符。即使它们具有 |
(从 0.46.0 开始) |
env |
env | list[str] | dict[str] |
要设置的环境变量,例如 |
|
is_parallel |
布尔值 |
当为 false 时,指定此测试不能与其他测试同时运行 |
|
优先级 |
int |
指定测试的优先级。优先级较高的测试会在优先级较低的测试之前启动。优先级相同的测试的启动顺序是实现定义的。默认优先级为 0,允许使用负数。 |
(从 0.52.0 开始)
|
协议 |
str |
指定如何解析测试结果,可以是
|
(自 0.50.0 版本起)
|
should_fail |
布尔值 |
如果可执行文件返回非零返回值(即报告错误),则测试将被视为通过,当此值为真时。 |
|
suite |
str | list[str] |
附加到此测试的 |
|
timeout |
int |
测试允许运行的秒数,超过时间限制的测试始终被视为失败,默认为 30 秒。自 0.57 版本起,如果超时为 |
|
verbose |
布尔值 |
如果为真,则强制将测试结果记录为 |
(自 0.62.0 版本起)
|
workdir |
str |
将用作测试工作目录的绝对路径 |
|
unset_variable()
取消设置变量。引用已取消设置的变量将导致错误,直到它再次被设置为止。
签名
(自 0.60.0 版本起)
# Unsets a variable
void unset_variable(
str varname, # The variable to unset
)
参数
函数 unset_variable() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
varname |
str |
要取消设置的变量。 |
|
vcs_tag()
此命令在构建时检测版本控制提交信息并将它放置在指定的输出文件中。保证该文件在每次构建时都保持最新。关键字类似于 custom_target()。
Meson 将读取 input 的内容,将 replace_string 替换为检测到的修订号,并将结果写入 output。此方法返回一个 custom_tgt 对象,该对象(与往常一样)应用于在其他目标使用此输出文件时发出依赖关系信号。
例如,如果您使用此方法生成一个标题并在构建目标中使用它,则必须将返回值添加到该构建目标的源代码中。没有它,Meson 将不知道构建目标的顺序。
如果您需要比此命令提供的更具体的行为,则应使用 custom_target()。
签名
# This command detects revision control commit information at build time
custom_tgt vcs_tag(
command : list[exe | external_program | custom_tgt | file | str] # The command to execute, see custom_target() for details
fallback : str # Version number to use when no revision control information is present,
input : str [required] # File to modify (e
output : str [required] # File to write the results to (e
replace_string : str # String in the input file to substitute with the commit information
)
参数
函数 vcs_tag() 接受以下关键字参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
命令 |
list[exe | external_program | custom_tgt | file | str] |
要执行的命令,有关此命令的指定方式的详细信息,请参见 此参数是可选的。如果它不存在,Meson 将尽力找到一个合适的默认命令。 (从 0.62.0 版本开始),接受 (从 0.63.0 版本开始),接受 |
|
fallback |
str |
当不存在版本控制信息时(例如从发行版压缩包构建时)要使用的版本号。 |
|
输入 |
str |
要修改的文件(例如 |
|
输出 |
str |
要写入结果的文件(例如 |
|
replace_string |
str |
输入文件中要使用提交信息替换的字符串。 |
|
warning()
此函数将它的参数打印到标准输出,前面加上 WARNING:。
签名
(从 0.44.0 开始)
# This function prints its argument to stdout prefixed with WARNING:
void warning(
str | int | bool | list[str | int | bool] | dict[str | int | bool] text, # The message to print
str | int | bool | list[str | int | bool] | dict[str | int | bool] more_text..., # Additional text that will be printed separated by spaces
)
参数
参数扁平化 不支持 此函数。
函数 warning() 接受以下位置参数
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
text |
str | int | bool | list[str | int | bool] | dict[str | int | bool] |
要打印的消息。 |
|
此外,该函数接受 0 到 infinity 个可变参数 (more_text...) 类型为 。str | int | bool | list[str | int | bool] | dict[str | int | bool]
将打印的附加文本,用空格分隔。
(从 0.54.0 开始)
搜索结果