函數
此文件列出 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
和 infinity
之間的變數參數 (Compiler argument...
),類型為
。str
要新增的編譯器參數
函數 add_global_arguments()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
language |
list [str ] |
指定應將參數套用至的語言。如果給定語言列表,則會將參數新增至每個對應的編譯器命令列。請注意,沒有辦法移除以這種方式設定的參數。如果您有僅在目標子集中使用的參數,則必須在每個目標的旗標中指定它。 |
|
native |
bool |
一個布林值,指定是否應將參數套用至原生編譯或交叉編譯。如果為 |
(自 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
和 infinity
之間的變數參數 (Linker argument...
),類型為
。str
要新增的連結器參數
函數 add_global_link_arguments()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
language |
list [str ] |
指定應將參數套用至的語言。如果給定語言列表,則會將參數新增至每個對應的編譯器命令列。請注意,沒有辦法移除以這種方式設定的參數。如果您有僅在目標子集中使用的參數,則必須在每個目標的旗標中指定它。 |
|
native |
bool |
一個布林值,指定是否應將參數套用至原生編譯或交叉編譯。如果為 |
(自 0.48.0 起)
|
add_languages()
新增專案使用的程式設計語言。
這相當於在 project
宣告中包含它們。此函數通常用於新增僅在某些條件下使用的語言。
如果找到所有指定的語言,則傳回 true
,否則傳回 false
。
如果省略 native
,則這些語言可用於建置或主機電腦,但建置電腦永遠不會需要它們。(也就是說,它相當於 add_languages(*langs*, native: false, required: *required*) 和 add_languages(*langs*, native: true, required: false)
。此預設行為可能會在未來的 Meson 版本中變更為 native: false
。
簽名
# 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
和 infinity
之間的變數參數 (Language...
),類型為
。str
要新增的語言
函數 add_languages()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
native |
bool |
如果設定為 |
(自 0.54.0 起) |
required |
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
和 infinity
之間的變數參數 (Compiler argument...
),類型為
。str
要新增的編譯器參數
函數 add_project_arguments()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
language |
list [str ] |
指定應將參數套用至的語言。如果給定語言列表,則會將參數新增至每個對應的編譯器命令列。請注意,沒有辦法移除以這種方式設定的參數。如果您有僅在目標子集中使用的參數,則必須在每個目標的旗標中指定它。 |
|
native |
bool |
一個布林值,指定是否應將參數套用至原生編譯或交叉編譯。如果為 |
(自 0.48.0 起)
|
add_project_dependencies()
將參數新增至編譯器和連結器命令列,以便將給定的一組相依性包含在此專案的所有建置產品中。
簽名
(自 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
和 infinity
之間的變數參數 (dependencies...
),類型為
。dep
要新增的相依性;如果包含內部相依性,則它們不得包含任何建置的物件。
函數 add_project_dependencies()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
language |
list [str ] |
指定應將參數套用至的語言。如果給定語言列表,則會將參數新增至每個對應的編譯器命令列。請注意,沒有辦法移除以這種方式設定的參數。如果您有僅在目標子集中使用的參數,則必須在每個目標的旗標中指定它。 |
|
native |
bool |
一個布林值,指定是否應將參數套用至原生編譯或交叉編譯。如果為 |
(自 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
和 infinity
之間的變數參數 (Linker argument...
),類型為
。str
要新增的連結器參數
函數 add_project_link_arguments()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
language |
list [str ] |
指定應將參數套用至的語言。如果給定語言列表,則會將參數新增至每個對應的編譯器命令列。請注意,沒有辦法移除以這種方式設定的參數。如果您有僅在目標子集中使用的參數,則必須在每個目標的旗標中指定它。 |
|
native |
bool |
一個布林值,指定是否應將參數套用至原生編譯或交叉編譯。如果為 |
(自 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()
接受下列位置參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
name |
str |
測試設定的名稱 |
|
最後,add_test_setup()
接受下列關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
env |
env | list [str ] | dict [str ] |
要設定的環境變數,例如 |
|
exclude_suites |
list [str ] |
應該在使用此設定時排除的測試套件清單。 |
(自 0.57.0 起) |
exe_wrapper |
list [str | external_program ] |
命令或指令碼,後接其參數 |
|
gdb |
bool |
如果為 |
|
is_default |
bool |
設定這是否為預設測試設定。如果為 |
(自 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()
接受下列位置參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
別名目標的名稱 |
|
此外,此函數接受介於 1
和 infinity
之間的變數參數 (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
)
message
引數自 0.53.0 起為可選,預設為列印條件陳述式。
參數
函數 assert()
接受下列位置參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
condition |
bool |
如果此條件的評估結果為 |
|
message |
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()
接受下列位置參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
name |
str |
唯一的測試 ID |
|
executable |
exe | jar | external_program | file | custom_tgt | custom_idx |
要執行的程式。(自 1.4.0 版本起) 也接受 CustomTarget。 |
|
最後,benchmark()
接受以下關鍵字引數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
args |
list [str | file | tgt | external_program ] |
要傳遞給可執行檔的引數 |
|
depends |
list [build_tgt | custom_tgt ] |
指定此測試依賴於指定的目標,即使它不將它們中的任何一個作為命令列引數。這是用於測試在內部找到這些目標的情況,例如外掛程式或 globbing。這些目標會在測試執行之前被建置,即使它們的 |
(自 0.46.0 版本起) |
env |
env | list [str ] | dict [str ] |
要設定的環境變數,例如 |
|
priority |
int |
指定測試的優先順序。優先順序較高的測試會比優先順序較低的測試先啟動。具有相同優先順序的測試的啟動順序由實作定義。預設優先順序為 0,允許使用負數。 |
(自 0.52.0 起)
|
protocol |
str |
指定如何解析測試結果,可以是
|
(自 0.50.0 版本起)
|
should_fail |
bool |
如果為 true,則當可執行檔傳回非零傳回值(即報告錯誤)時,測試會被視為通過 |
|
suite |
str | list [str ] |
附加到此測試的 |
|
timeout |
int |
允許測試運行的秒數,超過時間限制的測試總是會被視為失敗,預設為 30 秒。自 0.57 版本起,如果 timeout 為 |
|
verbose |
bool |
如果為 true,則強制將測試結果記錄下來,如同將 |
(自 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()
接受以下位置引數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,both_libraries()
接受以下關鍵字引數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
<lang>_shared_args |
list [str ] |
僅傳遞給共享程式庫的引數 |
(自 1.3.0 版本起) |
<lang>_static_args |
list [str ] |
僅傳遞給靜態程式庫的引數 |
(自 1.3.0 版本起) |
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
pic |
bool |
將程式庫建置為與位置無關的程式碼 (因此可以連結到共用程式庫)。此選項在 Windows 和 OS X 上無效,因為在 Windows 上沒有意義,而且在 OS X 上無法停用 PIC。 |
(自 0.36.0 版起) |
prelink |
bool |
如果為 |
(自 0.57.0 起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
soversion |
str | int |
指定此共用程式庫 soversion 的字串或整數,例如 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
vala_shared_args |
list [str | file ] |
僅傳遞給共用程式庫的引數。與 |
(自 1.3.0 版本起) |
vala_static_args |
list [str | file ] |
僅傳遞給靜態程式庫的引數。與 |
(自 1.3.0 版本起) |
version |
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,build_target()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
<lang>_shared_args |
list [str ] |
僅傳遞給共享程式庫的引數 |
(自 1.3.0 版本起) |
<lang>_static_args |
list [str ] |
僅傳遞給靜態程式庫的引數 |
(自 1.3.0 版本起) |
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 true 時,D 模組會在偵錯模式中編譯。 |
|
darwin_versions |
str | int | list [str ] |
定義 macOS 上 dylib 的 |
(自 0.48.0 起) |
dependencies |
list [dep ] |
使用 |
|
export_dynamic |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implib |
bool | str |
設定為 true 時,會為執行檔產生匯入程式庫 (匯入程式庫的名稱以 exe_name 為基礎)。或者,當設定為字串時,會提供匯入程式庫的基本名稱。當傳回的建置目標物件出現在其他地方的 |
(自 0.42.0 版本起) |
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
pic |
bool |
將程式庫建置為與位置無關的程式碼 (因此可以連結到共用程式庫)。此選項在 Windows 和 OS X 上無效,因為在 Windows 上沒有意義,而且在 OS X 上無法停用 PIC。 |
(自 0.36.0 版起) |
pie |
bool |
建置與位置無關的執行檔。 |
(自 0.49.0 起) |
prelink |
bool |
如果為 |
(自 0.57.0 起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
soversion |
str | int |
指定此共用程式庫 soversion 的字串或整數,例如 |
|
target_type |
str |
要建置的實際目標類型 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
vala_shared_args |
list [str | file ] |
僅傳遞給共用程式庫的引數。與 |
(自 1.3.0 版本起) |
vala_static_args |
list [str | file ] |
僅傳遞給靜態程式庫的引數。與 |
(自 1.3.0 版本起) |
version |
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
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()
接受以下關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
capture |
bool |
當此參數設定為 true 時,Meson 會擷取 |
(自 0.41.0 起)
|
command |
list [str | file ] |
如上所述,如果指定了此參數,Meson 不會自行建立檔案,而是執行指定的命令,這可讓您進行完全自訂的檔案產生。(自 0.52.0 起) 命令可以包含檔案物件,並且可以將多個檔案傳遞給 |
|
configuration |
cfg_data | dict [str | int | bool ] |
如上所述,如果傳遞此參數,則會為輸入檔案(如果提供)提供取代資料,或提供要寫入輸出的鍵值對。 |
|
copy |
bool |
如上所述,如果指定此參數,Meson 只會將檔案從輸入複製到輸出。 |
(自 0.47.0 版本起)
|
depfile |
str |
命令可以寫入的相依性檔案,其中列出此目標所相依的所有其他檔案。任何這些檔案的變更都會觸發重新組態。 |
(自 0.52.0 起) |
encoding |
str |
設定輸入和輸出檔案的檔案編碼。支援的編碼是 python3 的編碼,請參閱 標準編碼。 |
(自 0.47.0 版本起)
|
format |
str |
定義的格式。預設為 |
(自 0.46.0 版本起)
|
input |
str | file |
輸入檔案名稱。如果未在組態模式中指定,則會將 |
|
install |
bool |
如果為 true,則會在安裝步驟期間安裝此產生的檔案,而且必須設定 |
(自 0.50.0 版本起)
|
install_dir |
str |
將產生的檔案安裝到的子目錄 (例如 |
|
install_mode |
list [str | int ] |
以符號格式指定檔案模式,並可選擇性地指定已安裝檔案的擁有者/uid 和群組/gid。 如需更多資訊,請參閱 |
(自 0.47.0 版本起) |
install_tag |
str |
|
(自 0.60.0 版本起) |
macro_name |
str |
指定時,將會使用巨集保護,而不是 '#pragma once'。巨集保護名稱將會是指定的名稱。 |
(自 1.3.0 版本起) |
output |
str |
輸出檔案名稱。(自 0.41.0 起) 可能包含 |
|
output_format |
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 起,name 引數為可選,預設為第一個輸出的基本名稱 (在上述範例中為 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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
name |
str |
自訂目標的唯一 ID 此位置引數為可選自 0.60.0 起。預設為第一個輸出的基本名稱。 |
[可選] |
最後,custom_target()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
build_always |
bool |
如果為 |
已棄用 於 0.47.0 |
build_always_stale |
bool |
如果為 |
(自 0.47.0 版本起)
|
build_by_default |
bool |
設定為 true 時,會導致此目標預設為建置。這表示當在不帶任何引數的情況下呼叫 (自 0.50.0 起) 如果將 |
(自 0.38.0 版本起) |
capture |
bool |
有些編譯器無法被告知要將其輸出寫入檔案,而是寫入標準輸出。當此引數設定為 true 時,Meson 會擷取 |
|
command |
list [str | file | exe | external_program ] |
要執行以從輸入建立輸出的命令。命令可以是字串或傳回類似檔案物件的函式的傳回值,例如 |
|
console |
bool |
關鍵字引數與 |
(自 0.48.0 起) |
depend_files |
list [str | file ] |
此目標所依賴但未在 |
|
depends |
list [build_tgt | custom_tgt | custom_idx ] |
指定此目標依賴於指定的目標,即使它沒有將它們中的任何一個作為命令列引數。這適用於您有一個工具會在內部執行例如 globbing 的情況。通常您應該將生成的來源作為輸入,Meson 會自動設定所有依賴項 (在 0.60 到 1.4.0 之間,custom_idx 不可用作類型)。 |
|
depfile |
str |
命令可以寫入的依賴項檔案,列出此目標所依賴的所有其他檔案,例如 C 編譯器會列出它包含的所有標頭檔,並且其中任何一個檔案的變更都會觸發重新編譯。 (自 0.47.0 起) 也接受 |
|
env |
env | list [str ] | dict [str ] |
要設定的環境變數,例如 |
(自 0.57.0 起) |
feed |
bool |
有些編譯器無法被告知從檔案讀取輸入,而是從標準輸入讀取。當此引數設定為 |
(自 0.59.0 起)
|
input |
list [str | file ] |
原始檔清單。(自 0.41.0 起) 此清單會被扁平化。 |
|
install |
bool |
當為 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 版本起) |
output |
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
message |
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 ] |
要連結的程式庫。 |
|
objects |
list [extracted_obj ] |
物件檔案的列表,直接連結到使用相依性的目標。 |
(自 1.1.0 起) |
sources |
list [str | file | custom_tgt | custom_idx | generated_list ] |
要新增至目標的來源 (或在建置包含它們的來源之前應該建置的生成的標頭檔) |
|
variables |
dict [str ] | list [str ] |
任意字串的字典,這表示在子專案中使用,其中特殊變數會透過 cmake 或 pkg-config 提供。自 0.56.0 起,它也可以是 |
(自 0.54.0 起) |
version |
str |
此相依性的版本,例如 |
|
dependency()
使用給定的名稱透過 pkg-config
和 使用 CMake (如果 pkg-config
失敗) 尋找外部相依性 (通常是安裝在您系統上的程式庫)。此外,還支援框架 (僅限 OSX) 和特定於程式庫的回退偵測邏輯。
自 0.60.0 起 可以提供多個名稱,它們會依序嘗試,並且會使用找到的第一個名稱。僅當系統上找不到任何名稱時,才會使用回退子專案。一旦找到其中一個名稱,所有其他名稱都會新增到快取中,以便後續對這些名稱的任何呼叫都將傳回相同的值。如果相依性可能具有不同的名稱 (例如 png
和 libpng
),這會很有用。
- 自 0.64.0 起,可以由 WrapDB 提供相依性回退。只需使用
meson wrap update-db
命令在本機下載資料庫,如果系統上找不到相依性且專案未運送自己的.wrap
檔案,Meson 會自動回退到 WrapDB 提供的子專案。
也可以透過其他兩種方式解析相依性
-
如果在呼叫
dependency
之前在meson.override_dependency
中使用了相同的名稱,則會無條件傳回覆寫相依性;也就是說,無論系統中是否安裝外部相依性,都會使用覆寫相依性。通常,子專案會使用meson.override_dependency
。 -
透過回退子專案,如果需要,會將其帶入目前的建置規格,就像呼叫了
subproject()
一樣。可以使用fallback
引數指定子專案。或者,如果缺少fallback
引數,自 0.55.0 起,如果 wrap 檔案提供相依性,或者子專案的名稱與相依性相同,則 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
到 無限
個可變引數 (names...
),類型為
。str
要查找的相依性名稱。相依性會按照此處提供的順序查找。將會使用第一個找到的相依性。只有在系統上找不到任何名稱時,才會使用後備子專案。一旦找到其中一個名稱,所有其他名稱都會被新增到快取中,因此後續對這些名稱的任何呼叫都將回傳相同的值。如果相依性可能有不同的名稱,例如 png
和 libpng
,這會很有用。
注意: 在 0.60.0 之前,只允許單一相依性名稱。
(自 0.60.0 版本起)
函式 dependency()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
allow_fallback |
bool |
指定當在系統中找不到相依性時,Meson 是否應自動選擇後備子專案。如果為 |
(自 0.56.0 版起) |
default_options |
list [str ] | dict [str | bool | int | list [str ]] |
預設選項值的陣列,會覆寫在子專案的 |
(自 0.38.0 版本起) |
disabler |
bool |
如果此關鍵字引數設定為 |
(自 0.49.0 起)
|
fallback |
list [str ] | str |
手動指定當在系統中找不到相依性時要使用的後備子專案。如果自動搜尋不適用,或者您想要支援早於 0.55.0 的 Meson 版本,這會很有用。如果值是一個陣列 |
|
include_type |
str |
一個列舉旗標,標示應如何轉換相依性旗標。支援的值為 |
(自 0.52.0 起)
|
language |
str |
定義如果有多種語言可用,則要尋找哪種特定於語言的相依性。 |
(自 0.42.0 版本起) |
method |
str |
定義偵測相依性的方式,預設值為 |
(自 0.40.0 版起)
|
native |
bool |
如果設定為 |
|
not_found_message |
str |
如果找不到相依性,將列印為 |
(自 0.50.0 版本起) |
required |
bool | feature |
當設定為 當設定為 (自 0.47.0 起)也可以傳遞 |
|
static |
bool |
告知相依性提供者嘗試取得靜態程式庫,而不是動態程式庫(請注意,並非所有相依性後端都支援此功能) 自 0.60.0 起,如果未在 自 0.63.0 起,當 |
|
version |
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
message |
str |
要列印的訊息 |
|
此外,該函式接受 0
到 無限
個可變引數 (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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,executable()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 true 時,D 模組會在偵錯模式中編譯。 |
|
dependencies |
list [dep ] |
使用 |
|
export_dynamic |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implib |
bool | str |
設定為 true 時,會為執行檔產生匯入程式庫 (匯入程式庫的名稱以 exe_name 為基礎)。或者,當設定為字串時,會提供匯入程式庫的基本名稱。當傳回的建置目標物件出現在其他地方的 |
(自 0.42.0 版本起) |
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
pie |
bool |
建置與位置無關的執行檔。 |
(自 0.49.0 起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
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
到 無限
個可變引數 (file...
),類型為
。str
檔案的路徑。
find_program()
這裡的 program_name
是一個字串,它可以是要在 PATH
或專案內其他地方搜尋的可執行檔或腳本。搜尋順序如下:
- 透過
meson.override_find_program()
設定的程式覆寫。 -
子專案 wrap 檔案中的
[provide]
區塊,如果wrap_mode
設定為forcefallback
。 -
機器檔案中的
[binaries]
區塊。 - 使用
dirs:
kwarg 提供的目錄(見下文)。 - 相對於目前子目錄的專案原始碼樹。
- 如果您使用
configure_file()
的回傳值,則會改用建置樹內的目前子目錄。
- 如果您使用
-
PATH
環境變數。 -
子專案 wrap 檔案中的
[provide]
區塊,如果wrap_mode
設定為除nofallback
以外的任何值。
Meson 也會自動偵測具有 shebang 行的腳本,並在 Windows(因為命令呼叫器會拒絕該命令)和 Unix(如果腳本檔案未設定執行位元)上,使用其中指定的執行檔/解譯器執行它們。因此,當使用此腳本作為命令清單的一部分時,您*必須不要*手動新增解譯器。自 *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 |
bool |
如果為 |
(自 0.49.0 起)
|
native |
bool |
定義應該如何搜尋此可執行檔。預設設定為 |
(自 0.43.0 起)
|
required |
bool | feature |
當為 |
|
version |
str | list [str ] |
指定必要的版本,請參閱 |
(自 0.52.0 起) |
version_argument |
str |
指定在嘗試尋找程式版本時要傳遞的引數。如果未指定此引數,則會使用 |
(自 1.5.0 起) |
generator()
另請參閱:custom_target()
此函式會建立 generator
物件,該物件可用於執行自訂編譯命令。唯一的位置引數是要使用的可執行檔。它可以是自行建置的可執行檔,也可以是 find_program
回傳的可執行檔。
傳遞給所有關鍵字引數的範本字串接受以下特殊取代:
-
@PLAINNAME@
:完整的輸入檔案名稱,例如:foo.c
變成foo.c
(未變更)。 -
@BASENAME@
:輸入檔案名稱的基底名稱,例如:foo.c.y
變成foo.c
(移除副檔名)。
傳遞給 output
關鍵字引數的每個字串*必須*使用這兩個取代之一或兩個來建構。
除了上述取代之外,arguments
關鍵字引數也接受以下取代:
-
@OUTPUT@
:輸出檔案的完整路徑。 -
@INPUT@
:輸入檔案的完整路徑。 -
@DEPFILE@
: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 ] |
將傳遞給可執行檔的命令列引數的範本字串清單。 |
|
capture |
bool |
當此引數設定為 true 時,Meson 會擷取 |
(自 0.43.0 起)
|
depends |
list [build_tgt | custom_tgt | custom_idx ] |
必須先建置的建置目標陣列,然後才能執行此產生器。如果您有一個產生器會呼叫在此專案中建置的第二個可執行檔,則會使用此引數(自 0.60 到 1.4.0 之間沒有 custom_idx)。 |
(自 0.51.0 版起) |
depfile |
str |
指向相依性檔案的範本字串,產生器可以寫入該檔案,列出此目標相依的所有其他檔案。例如,C 編譯器會列出其包含的所有標頭檔,而任何這些檔案中的變更都會觸發重新編譯。 |
|
output |
list [str ] |
範本字串(或範本字串清單),定義如何從單個來源檔案名稱產生輸出檔案名稱(或多個輸出名稱)。 |
|
get_option()
取得位置引數中指定的 專案建置選項 的值。
請注意,以 dir
結尾的內建選項(例如 bindir
和 libdir
)回傳的值通常是相對於(且在)prefix
內的路徑,但您不應該依賴它,因為 在某些情況下它也可能是絕對路徑。install_dir
引數會如預期般處理,但如果您需要絕對路徑,例如在 define 中使用,則應使用路徑串聯運算子,如下所示: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 |
bool |
找不到時回傳 |
(自 0.59.0 起) |
required |
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 |
bool |
如果設定為 |
|
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
)
在 0.59.0 到 1.1.0 之間的 install_mode
kwarg 會忽略整數值。
省略的 install_dir
kwarg 在 1.3.0 之前無法在子專案內正常運作。
省略的 install_dir
kwarg 在 1.3.0 之前與 preserve_path
kwarg 組合使用時無法正常運作。
參數
此函數接受 0
到 無限大
個可變引數 (file...
),類型為
。file
| str
要安裝的檔案。
函數 install_data()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
follow_symlinks |
bool |
如果為 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 |
bool |
安裝時,停用從資料檔中剝離子目錄。 這相當於 GNU Automake 的 |
(自 0.64.0 起)
|
rename |
list [str ] |
如果指定,則會將每個來源檔案重新命名為 |
(自 0.46.0 版本起) |
sources |
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
)
在 1.1.0 之前,install_mode
kwarg 會忽略整數值。
參數
此函數接受 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)
在 0.59.0 到 1.1.0 之間的 install_mode
kwarg 會忽略整數值。
參數
此函數接受 0
到 無限大
個可變引數 (file...
),類型為
。file
| str
要安裝的標頭檔。
函數 install_headers()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
follow_symlinks |
bool |
如果為 true,則會取消參照連結並複製其目標。預設值在未來將會變成 false。 |
(自 1.3.0 版本起)
|
install_dir |
str |
要安裝到的位置。 |
|
install_mode |
list [str | int ] |
以符號格式指定檔案模式,並可選擇性地指定已安裝檔案的擁有者/uid 和群組/gid。 如需更多資訊,請參閱 |
(自 0.47.0 版本起) |
preserve_path |
bool |
安裝時,停用從標頭檔中剝離子目錄。 這相當於 GNU Automake 的 |
(自 0.63.0 起)
|
subdir |
str |
安裝到預設 includedir 的 與 |
|
install_man()
在安裝步驟期間,將指定的 man 檔案從來源樹狀結構安裝到系統的 man 目錄。可以使用 install_dir
關鍵字引數覆寫此目錄。
(自 0.49.0 起) man 頁面不再隱含壓縮。
簽名
# 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
)
在 0.59.0 到 1.1.0 之間的 install_mode
kwarg 會忽略整數值。
參數
此函數接受 0
到 無限大
個可變引數 (file...
),類型為
。file
| str
要安裝的 Man 頁面。
函數 install_man()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
install_dir |
str |
要安裝到的位置。 |
|
install_mode |
list [str | int ] |
以符號格式指定檔案模式,並可選擇性地指定已安裝檔案的擁有者/uid 和群組/gid。 如需更多資訊,請參閱 |
(自 0.47.0 版本起) |
locale |
str |
可用來指定 man 頁面將安裝在手冊頁面目錄樹狀結構中的地區設定。範例手冊可能是 |
(自 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/
在 0.59.0 到 1.1.0 之間的 install_mode
kwarg 會忽略整數值。
參數
函數 install_subdir()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
subdir_name |
str |
要安裝的子目錄 |
|
最後,install_subdir()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
exclude_directories |
list [str ] |
不應安裝的目錄名稱清單。名稱會解譯為相對於 |
(自 0.47.0 版本起) |
exclude_files |
list [str ] |
不應安裝的檔案名稱清單。名稱會解譯為相對於 |
|
follow_symlinks |
bool |
如果為 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 |
bool |
安裝目錄內容。如果 |
(自 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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,jar()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
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
到 無限大
個可變引數 (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
)
using_static_args
可能會導致與 both_library
搭配使用時編譯時間大幅增加,因為靜態目標和共享目標之間無法共用目標檔案。如果這些參數為空陣列,則保證不會重複建置。
參數
函式 library()
接受以下位置參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,library()
接受以下關鍵字參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
<lang>_shared_args |
list [str ] |
僅傳遞給共享程式庫的引數 |
(自 1.3.0 版本起) |
<lang>_static_args |
list [str ] |
僅傳遞給靜態程式庫的引數 |
(自 1.3.0 版本起) |
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
pic |
bool |
將程式庫建置為與位置無關的程式碼 (因此可以連結到共用程式庫)。此選項在 Windows 和 OS X 上無效,因為在 Windows 上沒有意義,而且在 OS X 上無法停用 PIC。 |
(自 0.36.0 版起) |
prelink |
bool |
如果為 |
(自 0.57.0 起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
soversion |
str | int |
指定此共用程式庫 soversion 的字串或整數,例如 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
vala_shared_args |
list [str | file ] |
僅傳遞給共用程式庫的引數。與 |
(自 1.3.0 版本起) |
vala_static_args |
list [str | file ] |
僅傳遞給靜態程式庫的引數。與 |
(自 1.3.0 版本起) |
version |
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
到 無限
個可變參數 (more_text...
),類型為
。str
| int
| bool
| list
[str
| int
| bool
] | dict
[str
| int
| bool
]
將以空格分隔列印的其他文字。
(自 0.54.0 起)
project()
每個專案中第一個被呼叫的函式,用於初始化 Meson。
此函式的第一個參數必須是定義此專案名稱的字串。
專案名稱可以是任何你想要的字串,除了描述用途外,它沒有其他用途。但是,由於它會寫入例如相依性資訊清單,因此通常將其與專案 tarball 或 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
到 無限
個可變參數 (language...
),類型為
。str
Meson 應初始化的語言。
最後,project()
接受以下關鍵字參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
default_options |
list [str ] | dict [str | bool | int | list [str ]] |
接受格式為 請注意,某些選項可以覆寫預設行為;例如,在此處使用 (自 1.2.0 版本起):現在可以傳遞字典。 |
|
license |
str | list [str ] |
接受一個字串或字串陣列,描述程式碼所使用的授權。 這應為 SPDX 授權表示式,使用 SPDX 授權清單 中的標準化授權識別符。通常這會是類似 由於回溯相容性的原因,您也可以在此處傳遞授權陣列。不建議這樣做,因為它具有歧義: 請注意,文字是非正式的,並且僅寫入相依性資訊清單。Meson 不會執行任何授權驗證,您有責任驗證您是否遵守所有授權條款。您可以使用 |
|
license_files |
str | list [str ] |
接受一個字串或字串陣列,其中包含程式碼所使用的授權檔案的路徑。 這會藉由允許同時指定簡短授權名稱和完整授權文字來增強 請注意,這些檔案是非正式的,並且僅與相依性資訊清單一起安裝。Meson 不會執行任何授權驗證,您有責任驗證您是否遵守所有授權條款。您可以使用 |
(自 1.1.0 起) |
meson_version |
str |
接受一個字串,描述專案所需的 Meson 版本。通常類似於 |
|
subproject_dir |
str |
指定保存 Meson 子專案的頂層目錄名稱。這僅作為現有程式碼庫的相容性選項,這些程式碼庫將其嵌入式原始碼存放在自訂目錄中。所有新專案都不應設定此項,而應使用預設值。應注意的是,此關鍵字引數在子專案中會被忽略。只能有一個子專案目錄,並且它是在頂層 Meson 檔案中設定的。 |
|
version |
str | file |
描述此專案版本的自由格式字串。您可以使用 |
|
range()
傳回一個不透明的物件,該物件只能在 foreach
陳述式中使用。
range
range(int
stop)
range
range(int
start, int
stop[, int
step])
-
start
必須是等於或大於 0 的整數。預設值為 0。 -
stop
必須是等於或大於start
的整數。 -
step
必須是等於或大於 1 的整數。預設值為 1。
它會導致使用從 start
(包含)到 stop
(不包含)的值呼叫 foreach
迴圈,並且在每次迴圈後遞增 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
範圍物件也可以指定給變數並編製索引。
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()
接受以下關鍵字參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
capture |
bool |
如果為 |
(自 0.47.0 版本起)
|
check |
bool |
如果為 |
(自 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()
接受以下位置參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
執行目標的名稱 |
|
最後,run_target()
接受以下關鍵字參數:
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
command |
list [exe | external_program | custom_tgt | file | str ] |
一個包含要執行的命令及其參數的清單。每個清單項目可以是字串或目標。例如,將 |
|
depends |
list [build_tgt | custom_tgt | custom_idx ] |
此目標所依賴,但未列在命令陣列中的目標清單(例如,因為腳本在內部進行檔案 globbing,在 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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,shared_library()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
soversion |
str | int |
指定此共用程式庫 soversion 的字串或整數,例如 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
version |
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,shared_module()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
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()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
target_name |
str |
建置目標的唯一名稱 |
|
此外,函式還接受介於 0
和 無限
個變數引數 (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 將在所有產生的輸入檔案上建立建置時間的 僅順序相依性,包括未知的檔案。這是為了引導在您的編譯器產生的 depfile 中產生實際的相依性,以判斷何時重建原始碼。Ninja 依賴此相依性檔案來處理所有輸入檔案,無論是產生的還是非產生的。其他後端的行為類似。
最後,static_library()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
<lang>_args |
list [str ] |
用於指定語言的編譯器旗標;例如:C++ 的 |
|
<lang>_pch |
str |
用於指定語言的預先編譯標頭檔 |
|
build_by_default |
bool |
設定為 |
(自 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 |
bool |
設定為 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 |
bool |
設定為 true 時,會在對此有影響的平台上將此目標標示為 GUI 應用程式,自 0.56.0 版本起已棄用,請改用 |
已棄用 於 0.56.0 版本中
|
implicit_include_directories |
bool |
控制 Meson 是否將目前原始碼和建置目錄新增至 include 路徑 |
(自 0.42.0 版本起)
|
include_directories |
list [inc | str ] |
使用 |
|
install |
bool |
設定為 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 上是 將此設定為 |
|
native |
bool |
控制是否為建置或主機機器編譯目標。 |
|
objects |
list [extracted_obj | file | str ] |
應該在此目標中連結的物件檔案列表。 自 1.1.0 版起,除了您沒有來源或由其他建置目標產生的物件檔案之外,此處還可以包含產生的檔案。在較早的版本中,產生的物件檔案必須放在 |
|
override_options |
list [str ] | dict [str | bool | int | list [str ]] |
採用與 |
(自 0.40.0 版起) |
pic |
bool |
將程式庫建置為與位置無關的程式碼 (因此可以連結到共用程式庫)。此選項在 Windows 和 OS X 上無效,因為在 Windows 上沒有意義,而且在 OS X 上無法停用 PIC。 |
(自 0.36.0 版起) |
prelink |
bool |
如果為 |
(自 0.57.0 起) |
rust_abi |
str |
設定要編譯的特定 ABI (在編譯 Rust 時)。
|
(自 1.3.0 版本起) |
rust_crate_type |
str |
設定要編譯的特定 Rust 程式碼庫類型 (在編譯 Rust 時)。 如果目標是 如果是 如果是 "proc-macro" 在 0.62.0 版中新增。 自 1.3.0 版起,此選項已過時,並由 "rust_abi" 關鍵字引數取代。 |
(自 0.42.0 版本起) 已棄用 在 1.3.0 版中 |
rust_dependency_map |
dict [str ] |
在 Rust 目標上,這會提供程式庫名稱到它在 Rust 程式碼中可用的程式碼庫名稱的對應。 這允許類似於 Cargo 或 Rust 程式碼內的 |
(自 1.2.0 版起) |
sources |
str | file | custom_tgt | custom_idx | generated_list | structured_src |
其他原始程式檔。與 source varargs 相同。 |
|
vala_args |
list [str | file ] |
Vala 的編譯器旗標。與其他語言不同,此處可能包含 Files |
|
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 ] |
其他來源,其中 key 是根目錄下放置值的目錄 |
[可選] |
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 起) |
required |
bool | feature |
運作方式與 |
(自 0.48.0 起)
|
version |
str |
運作方式與 |
|
summary()
此函式用於在建置過程結束時總結建置設定。此函式提供一種方式,讓專案(和子專案)以清晰的方式報告此資訊。
內容是一系列分組到各個區段的鍵/值對。如果省略區段關鍵字引數,這些鍵/值對會隱式分組到一個沒有標題的區段中。鍵/值對可以選擇性地分組到字典中,但請記住字典不保證順序。key
必須是字串,而 value
可以是
- 整數、布林值或字串
- 自 0.57.0 起 外部程式或依賴項
- 自 0.58.0 起 功能選項
- 它們的清單。
除了將 summary 稱為 summary(key, value)
之外,也可以將字典直接傳遞給 summary()
函式,如下例所示。
可以多次呼叫 summary()
,只要相同的區段/鍵配對沒有出現兩次。所有區段將會被收集,並以它們被呼叫的順序,在設定結束時印出。
簽名
(自 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 |
bool |
將布林值轉換為 yes 和 no |
|
list_sep |
str |
在此摘要中列印列表值時要使用的分隔符。如果未給定分隔符,則每個列表項目將列印在單獨的行上。 |
(自 0.54.0 起) |
section |
str |
將此摘要資訊放置在其中的區段。如果省略 section 關鍵字參數,則鍵/值對會隱式分組到沒有標題的區段中。 |
|
test()
定義要與測試工具一起執行的測試。接受兩個位置參數,第一個是測試的名稱,第二個是要執行的可執行檔。可執行檔可以是 exe
物件(由 executable()
返回)或 external_program
物件(由 find_program()
返回)。
(自 0.55.0 起) 進行交叉編譯時,如果需要並定義了 exe_wrapper,則環境變數 MESON_EXE_WRAPPER
將被設定為該 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()
接受以下位置參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
name |
str |
唯一的測試 ID |
|
executable |
exe | jar | external_program | file | custom_tgt | custom_idx |
要執行的程式。(自 1.4.0 版本起) 也接受 CustomTarget。 |
|
最後,test()
接受以下關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
args |
list [str | file | tgt | external_program ] |
要傳遞給可執行檔的引數 |
|
depends |
list [build_tgt | custom_tgt ] |
指定此測試依賴於指定的目標,即使它不將它們中的任何一個作為命令列引數。這是用於測試在內部找到這些目標的情況,例如外掛程式或 globbing。這些目標會在測試執行之前被建置,即使它們的 |
(自 0.46.0 版本起) |
env |
env | list [str ] | dict [str ] |
要設定的環境變數,例如 |
|
is_parallel |
bool |
當為 false 時,指定沒有其他測試必須與此測試同時執行 |
|
priority |
int |
指定測試的優先順序。優先順序較高的測試會比優先順序較低的測試先啟動。具有相同優先順序的測試的啟動順序由實作定義。預設優先順序為 0,允許使用負數。 |
(自 0.52.0 起)
|
protocol |
str |
指定如何解析測試結果,可以是
|
(自 0.50.0 版本起)
|
should_fail |
bool |
如果為 true,則當可執行檔傳回非零傳回值(即報告錯誤)時,測試會被視為通過 |
|
suite |
str | list [str ] |
附加到此測試的 |
|
timeout |
int |
允許測試運行的秒數,超過時間限制的測試總是會被視為失敗,預設為 30 秒。自 0.57 版本起,如果 timeout 為 |
|
verbose |
bool |
如果為 true,則強制將測試結果記錄下來,如同將 |
(自 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()
接受以下關鍵字參數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
command |
list [exe | external_program | custom_tgt | file | str ] |
要執行的命令,有關如何指定此命令的詳細資訊,請參閱 此參數為可選參數。如果不存在,Meson 將盡力尋找合適的預設命令。 (自 0.62.0 起) 接受 (自 0.63.0 起) 接受 |
|
fallback |
str |
當不存在修訂控制資訊時要使用的版本號碼,例如從發行 tarball 建置時。 |
|
input |
str |
要修改的檔案 (例如 |
|
output |
str |
要寫入結果的檔案 (例如 |
|
replace_string |
str |
輸入檔案中要替換為提交資訊的字串。 |
|
warning()
此函式會將其引數列印到 stdout,並加上 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
到 無限
個可變參數 (more_text...
),類型為
。str
| int
| bool
| list
[str
| int
| bool
] | dict
[str
| int
| bool
]
將以空格分隔列印的其他文字。
(自 0.54.0 起)
搜尋的結果是