相依性物件 (dep
)
相依性的抽象表示
由以下項目傳回
相依性物件由以下函式和方法傳回
declare_dependency()
dependency()
compiler.find_library()
dep.as_link_whole()
dep.as_shared()
dep.as_static()
dep.as_system()
dep.partial_dependency()
相依性物件方法
dep.as_link_whole()
只有使用 declare_dependency()
建立的相依性,才會傳回一個相依性物件的副本,其中所有 link_with 參數都更改為 link_whole。例如,這對於使用 default_library=static
建置的子專案中的回退相依性很有用。請注意,所有 link_with
物件都必須是靜態函式庫,否則在嘗試 link_whole
動態函式庫時會引發錯誤。
簽章
(自 0.56.0 起)
dep as_link_whole()
dep.as_shared()
僅適用於使用 declare_dependency()
建立的相依性,傳回相依性物件的副本,該副本偏好 both_libraries()
的 shared
版本。
簽章
(自 1.6.0 起)
# Only for dependencies created with declare_dependency()
,
dep as_shared(
recursive : bool # If true, this is recursively applied to dependencies
)
引數
方法 dep.as_shared()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
recursive |
bool |
如果為 true,則會遞迴地套用至相依性 |
|
dep.as_static()
僅適用於使用 declare_dependency()
建立的相依性,傳回相依性物件的副本,該副本偏好 both_libraries()
的 static
版本。
簽章
(自 1.6.0 起)
# Only for dependencies created with declare_dependency()
,
dep as_static(
recursive : bool # If true, this is recursively applied to dependencies
)
引數
方法 dep.as_static()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
recursive |
bool |
如果為 true,則會遞迴地套用至相依性 |
|
dep.as_system()
傳回相依性物件的副本,該副本已將 include_type
的值變更為 value
。value
引數是選用的,預設值為 'preserve'
。
簽章
(自 0.52.0 起)
# Returns a copy of the dependency object, which has changed the value of `include_type`
dep as_system(
str [value], # The new value. See dependency()
for supported values.
)
引數
方法 dep.as_system()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
value |
str |
新值。如需支援的值,請參閱 |
[選用] |
dep.found()
傳回是否已找到相依性。
簽章
bool found()
dep.get_configtool_variable()
從組態工具取得命令列引數 (帶有 --
前置詞),或者,如果對非組態工具相依性呼叫,則會產生錯誤。
簽章
(自 0.44.0 起)
已棄用
於 0.56.0
# Gets the command line argument from the config tool (with `--` prepended), or,
str get_configtool_variable(
str var_name, # Name of the variable to query
)
引數
方法 dep.get_configtool_variable()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
var_name |
str |
要查詢的變數名稱 |
|
dep.get_pkgconfig_variable()
取得指定的 pkg-config 變數,或者,如果對非 pkg-config 相依性呼叫,則會產生錯誤。
簽章
(自 0.36.0 起)
已棄用
於 0.56.0
# Gets the pkg-config variable specified,
str get_pkgconfig_variable(
str var_name, # Name of the variable to query
# Keyword arguments:
default : str # The value to return if the variable was not found
define_variable : list[str] # You can also redefine a
)
引數
方法 dep.get_pkgconfig_variable()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
var_name |
str |
要查詢的變數名稱 |
|
最後,dep.get_pkgconfig_variable()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
default |
str |
如果找不到變數,則傳回的值。如果未定義變數且未設定此 kwarg,則會發出警告。 |
(自 0.45.0 起) |
define_variable |
list [str ] |
您也可以藉由將清單傳遞至此 kwarg 來重新定義變數,這會影響擷取的變數: (自 1.3.0 起) 可以在成對指定多個變數。 |
(自 0.44.0 起) |
dep.get_variable()
通用變數 getter 方法,取代 get_*type*_variable
方法。這允許從相依性取得變數,而無需明確知道如何找到該相依性。如果設定了 default_value
,且無法從物件取得值,則會傳回 default_value
,如果未設定,則會引發錯誤。
簽章
(自 0.51.0 起)
# A generic variable getter method, which replaces the
str get_variable(
str [varname], # This argument is used as a default value
# Keyword arguments:
cmake : str # The CMake variable name
configtool : str # The configtool variable name
default_value : str # The default value to return when the variable does not exist
internal : str # The internal variable name
pkgconfig : str # The pkgconfig variable name
pkgconfig_define : list[str] # See dep.get_pkgconfig_variable()
system : str # The system variable name
)
在 1.3.0 之前,指定多個 pkgconfig_define 配對會無訊息地導致結果變形。只會重新定義第一個變數,但其值會包含第二個變數名稱及其值。
引數
方法 dep.get_variable()
接受以下位置引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
varname |
str |
此引數用作 |
(自 0.58.0 起) [選用] |
最後,dep.get_variable()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
cmake |
str |
CMake 變數名稱 |
|
configtool |
str |
組態工具變數名稱 |
|
default_value |
str |
當變數不存在時要傳回的預設值 |
|
internal |
str |
內部變數名稱 |
(自 0.54.0 起) |
pkgconfig |
str |
pkgconfig 變數名稱 |
|
pkgconfig_define |
list [str ] |
|
|
system |
str |
系統變數名稱 |
(自 1.6.0 起) |
dep.include_type()
傳回由 include_type
kwarg 設定的值。
簽章
(自 0.52.0 起)
str include_type()
dep.name()
傳回搜尋到的相依性名稱。對於使用 declare_dependency()
建立的相依性,傳回 'internal'
。
注意:在 Meson 1.5.0 之前,這並未針對 compiler.find_library()
傳回的 dep 物件實作。
簽章
(自 0.48.0 起)
str name()
dep.partial_dependency()
傳回具有與呼叫它的物件相同的名稱、版本、找到狀態、類型名稱和方法的新相依性物件。此新物件只會繼承其父系的屬性,並由關鍵字引數控制。
如果父系有任何相依性,這些相依性將以相同規則套用至新的部分相依性。因此,給定
dep1 = declare_dependency(compile_args : '-Werror=foo', link_with : 'libfoo')
dep2 = declare_dependency(compile_args : '-Werror=bar', dependencies : dep1)
dep3 = dep2.partial_dependency(compile_args : true)
dep3 會將 ['-Werror=foo', '-Werror=bar']
新增至新增至的任何目標的編譯器引數,但 libfoo 不會新增至 link_args。
以下引數會新增以下屬性
- compile_args:傳遞至編譯器的任何引數
- link_args:傳遞至連結器的任何引數
- links:透過 link_with 或 link_whole 傳遞的任何項目
- includes:任何 include_directories
- sources:相依性擁有的任何已編譯或靜態來源
簽章
(自 0.46.0 起)
# Returns a new dependency object with the same name, version, found status,
dep partial_dependency(
compile_args : bool # Whether to include compile_args
includes : bool # Whether to include includes
link_args : bool # Whether to include link_args
links : bool # Whether to include links
sources : bool # Whether to include sources
)
在 0.50.1 之前存在一個錯誤,導致上述行為無法正常運作。
引數
方法 dep.partial_dependency()
接受以下關鍵字引數
名稱 | 類型 | 描述 | 標籤 |
---|---|---|---|
compile_args |
bool |
是否包含 compile_args |
|
includes |
bool |
是否包含 includes |
|
link_args |
bool |
是否包含 link_args |
|
links |
bool |
是否包含 links |
|
sources |
bool |
是否包含 sources |
|
dep.type_name()
傳回描述相依性類型的字串,最常見的值是使用 declare_dependency()
建立的相依性的 internal
,以及使用 Pkg-config 取得的系統相依性的 pkgconfig
。
簽章
str type_name()
dep.version()
版本號碼為字串,例如 1.2.8
。如果相依性提供者不支援判斷版本,則為 unknown
。
簽章
str version()
搜尋結果如下