summaryrefslogtreecommitdiff
path: root/test cases/frameworks/15 llvm/meson.build
blob: 411d6db29bb32221b77005aba0486b2c92fa75cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
project('llvmtest', ['c', 'cpp'], default_options : ['c_std=c99'])

method = get_option('method')
static = get_option('link-static')

if(method == 'combination')
  d = dependency('llvm', version : static ? '>0.1' : '>=7.0', required : false, static : static)
  if not d.found()
    error('MESON_SKIP_TEST llvm not found or llvm version is too low')
  endif
  llvm_ct_dep = dependency(
    'llvm',
    modules : ['bitwriter', 'asmprinter', 'executionengine', 'target',
              'mcjit', 'nativecodegen', 'amdgpu', 'engine'],
    required : false,
    static : static,
    method : 'config-tool',
  )

  # Bump the version along till the LLVM bug is fixed
  if static and d.version().startswith('16.0') and d.version()[5].to_int() <= 2
    message('Skipping modules with cmake, see https://github.com/mesonbuild/meson/issues/11642')
    llvm_cm_dep = dependency(
      'llvm',
      required : false,
      static : static,
      method : 'cmake',
    )
  else
    llvm_cm_dep = dependency(
      'llvm',
      modules : ['bitwriter', 'asmprinter', 'executionengine', 'target',
                'mcjit', 'nativecodegen', 'amdgpu', 'engine'],
      required : false,
      static : static,
      method : 'cmake',
    )
  endif

  assert(llvm_ct_dep.found() == llvm_cm_dep.found(), 'config-tool and cmake results differ')
  cm_version_major = llvm_cm_dep.version().split('.')[0].to_int()
  cm_version_minor = llvm_cm_dep.version().split('.')[1].to_int()
  ct_version_major = llvm_ct_dep.version().split('.')[0].to_int()
  ct_version_minor = llvm_ct_dep.version().split('.')[1].to_int()
  assert(cm_version_major == ct_version_major, 'config-tool and cmake returns different major versions')
  assert(cm_version_minor == ct_version_minor, 'config-tool and cmake returns different minor versions')
else
  d = dependency('llvm', required : false, method : method, static : static)
  if not d.found()
    error('MESON_SKIP_TEST llvm not found.')
  endif

  if(not static and method == 'cmake')
    d = dependency('llvm', version : '>=7.0', required : false, static : static)
    if not d.found()
      error('MESON_SKIP_TEST llvm version is too low for cmake dynamic link.')
    endif
  endif

  d = dependency('llvm', modules : 'not-found', required : false, static : static, method : method)
  assert(d.found() == false, 'not-found llvm module found')

  d = dependency('llvm', version : '<0.1', required : false, static : static, method : method)
  assert(d.found() == false, 'ancient llvm module found')

  d = dependency('llvm', optional_modules : 'not-found', required : false, static : static, method : method)
  assert(d.found() == true, 'optional module stopped llvm from being found.')

  # Check we can apply a version constraint
  d = dependency('llvm', version : ['< 500', '>=@0@'.format(d.version())], required: false, static : static, method : method)
  assert(d.found() == true, 'Cannot set version constraints')

  # Check if we have to get pseudo components
  d = dependency('llvm', modules: ['all-targets','native','engine'], required: false, static : static, method : method)
  assert(d.found() == true, 'Cannot find pseudo components')

  dep_tinfo = dependency('tinfo', required : false)
  if not dep_tinfo.found()
    cpp = meson.get_compiler('cpp')
    dep_tinfo = cpp.find_library('tinfo', required: false)
  endif

  # Bump the version along till the LLVM bug is fixed
  if static and method == 'cmake' and d.version().startswith('16.0') and d.version()[5].to_int() <= 2
    message('Skipping modules with cmake, see https://github.com/mesonbuild/meson/issues/11642')
    llvm_dep = dependency(
      'llvm',
      required : false,
      static : static,
      method : method,
    )
  else
    llvm_dep = dependency(
      'llvm',
      modules : ['bitwriter', 'asmprinter', 'executionengine', 'target',
                'mcjit', 'nativecodegen', 'amdgpu'],
      required : false,
      static : static,
      method : method,
    )
  endif

  if not llvm_dep.found()
    error('MESON_SKIP_TEST required llvm modules not found.')
  endif

  executable(
      'sum',
      'sum.c',
      dependencies : [
        llvm_dep, dep_tinfo,
        # zlib will be statically linked on windows
        dependency('zlib', required : host_machine.system() != 'windows'),
        meson.get_compiler('c').find_library('dl', required : false),
      ]
    )
endif