1project(
2  'dependency get_variable',
3  ['c', 'cpp'],
4)
5
6# Just some string that nothing should return
7default = 'asufoiqwjtl;adjfbpiuqwoehtl;ajdfl;ghal;sdjg'
8
9dep = dependency('zlib', method: 'pkg-config', required : false)
10if not dep.found()
11  warning('Skipping pkg-config tests as zlib is not available or is not pkg-config')
12else
13  # Test for regular pkg-config
14  # We don't know what the value will be, but we know it should be the same
15  dep = dependency('zlib', method : 'pkg-config')
16  assert(dep.get_pkgconfig_variable('prefix') == dep.get_variable(pkgconfig : 'prefix'),
17        'Got different values from get_pkgconfig_variable and get_variable(pkgconfig: )')
18  assert(dep.get_variable(pkgconfig : default, default_value : default) == default,
19        'pkg-config didn\'t get default when we should have.')
20  assert(dep.get_variable(pkgconfig : 'prefix', default_value : default) != default,
21        'pkg-config got default when we shouldn\'t have.')
22endif
23
24dep_ct = dependency('llvm', method : 'config-tool', required : false)
25if not dep_ct.found()
26  warning('Skipping config-tool tests as llvm is not available or llvm-config was not found.')
27else
28  assert(dep_ct.get_configtool_variable('has-rtti') == dep_ct.get_variable(configtool : 'has-rtti'),
29        'Got different values from get_configtool_variable and get_variable(configtool: )')
30  assert(dep_ct.get_variable(configtool : default, default_value : default) == default,
31        'config-tool didn\'t get default when we should have.')
32  assert(dep_ct.get_variable(configtool : 'has-rtti', default_value : default) != default,
33        'config-tool got default when we shouldn\'t have.')
34endif
35
36dep_cm = dependency('llvm', method : 'cmake', required : false)
37if not dep_cm.found()
38  warning('Skipping cmake tests as llvm is not available via the cmake finder.')
39else
40  if dep_ct.found()
41    assert((dep_cm.get_variable(cmake : 'LLVM_ENABLE_RTTI') == 'ON') == (dep_ct.get_variable(configtool : 'has-rtti') == 'YES'),
42          'RTTI information for cmake and config tools disagree')
43  endif
44  assert(dep_cm.get_variable(cmake : default, default_value : default) == default,
45        'cmake didn\'t get default when we should have.')
46  assert(dep_cm.get_variable(cmake : 'LLVM_ENABLE_RTTI', default_value : default) != default,
47        'cmake config-tool got default when we shouldn\'t have.')
48endif
49
50idep = declare_dependency(variables : {'foo' : 'value'})
51assert(idep.get_variable(pkgconfig : 'foo', cmake : 'foo', configtool : 'foo',
52                         internal : 'foo', default_value : default) == 'value',
53       'internal got default when it shouldn\'t have.')
54assert(idep.get_variable(pkgconfig : 'foo', cmake : 'foo', configtool : 'foo',
55                         internal : 'bar', default_value : default) == default,
56       'internal didn\'t default when it should have.')
57
58idep = declare_dependency()
59assert(idep.get_variable(pkgconfig : 'foo', cmake : 'foo', configtool : 'foo',
60                         default_value : default) == default,
61       'something went wrong with an InternalDependency with no variables.')
62