依存関係オブジェクト (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()
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ペアを指定すると、結果が不正に形成されていました。最初の変数のみが再定義されますが、その値には2番目の変数名とその値の両方が含まれます。
引数
メソッドdep.get_variable()
は、以下の位置引数を受け入れます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
varname |
str |
この引数は、 |
(0.58.0以降) [オプション] |
最後に、dep.get_variable()
は、以下のキーワード引数を受け入れます。
名前 | 型 | 説明 | タグ |
---|---|---|---|
cmake |
str |
CMakeの変数名 |
|
configtool |
str |
configtoolの変数名 |
|
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()
で作成されたdepの場合はinternal
、Pkg-configで取得されたシステム依存関係の場合はpkgconfig
です。
シグネチャ
str type_name()
dep.version()
バージョン番号を文字列として返します。たとえば、1.2.8
などです。依存関係プロバイダーがバージョンの特定をサポートしていない場合はunknown
になります。
シグネチャ
str version()
検索結果は