Debian Codegraph @

test cases/frameworks/15 llvm/meson.build

raw
1 project('llvmtest', ['c', 'cpp'], default_options : ['c_std=c99'])
2
3 method = get_option('method')
4 static = get_option('link-static')
5
6 d = dependency('llvm', required : false, static : static)
7 if not d.found()
8 error('MESON_SKIP_TEST llvm not found.')
9 endif
10
11 if method != 'config-tool' and d.version().startswith('17.0') and host_machine.system() == 'windows'
12 # https://github.com/llvm/llvm-project/commit/e7fc7540daa9333f0be4f380fc9c619236d17f57#r130257253
13 error('MESON_SKIP_TEST broken llvm cmake files on MSYS2')
14 endif
15
16 modules_to_find = [
17 'bitwriter', 'asmprinter', 'executionengine', 'mcjit', 'target',
18 'nativecodegen', 'amdgpu', 'engine'
19 ]
20
21 if method == 'combination'
22 if not d.version().version_compare(static ? '>0.1' : '>=7.0')
23 error('MESON_SKIP_TEST: llvm version is too low')
24 endif
25 llvm_ct_dep = dependency(
26 'llvm',
27 modules : modules_to_find,
28 required : false,
29 static : static,
30 method : 'config-tool',
31 )
32
33 if static and d.version().startswith('16.0') and d.version()[5].to_int() <= 6
34 message('Skipping modules with cmake due to an LLVM bug, see https://github.com/mesonbuild/meson/issues/11642')
35 llvm_cm_dep = dependency(
36 'llvm',
37 required : false,
38 static : static,
39 method : 'cmake',
40 )
41 else
42 llvm_cm_dep = dependency(
43 'llvm',
44 modules : modules_to_find,
45 required : false,
46 static : static,
47 method : 'cmake',
48 )
49 endif
50
51 assert(llvm_ct_dep.found() and llvm_cm_dep.found(), 'config-tool and cmake both need to be found')
52 cm_version_major = llvm_cm_dep.version().split('.')[0].to_int()
53 cm_version_minor = llvm_cm_dep.version().split('.')[1].to_int()
54 ct_version_major = llvm_ct_dep.version().split('.')[0].to_int()
55 ct_version_minor = llvm_ct_dep.version().split('.')[1].to_int()
56 assert(cm_version_major == ct_version_major, 'config-tool and cmake returns different major versions')
57 assert(cm_version_minor == ct_version_minor, 'config-tool and cmake returns different minor versions')
58 else
59 if not static and method == 'cmake'
60 d = dependency('llvm', version : '>=7.0', required : false, static : static)
61 if not d.found()
62 error('MESON_SKIP_TEST llvm version is too low for cmake dynamic link.')
63 endif
64 endif
65
66 d = dependency('llvm', modules : 'not-found', required : false, static : static, method : method)
67 assert(d.found() == false, 'not-found llvm module found')
68
69 d = dependency('llvm', version : '<0.1', required : false, static : static, method : method)
70 assert(d.found() == false, 'ancient llvm module found')
71
72 d = dependency('llvm', optional_modules : 'not-found', required : false, static : static, method : method)
73 assert(d.found() == true, 'optional module stopped llvm from being found.')
74
75 # Check we can apply a version constraint
76 d = dependency('llvm', version : ['< 500', '>=@0@'.format(d.version())], required: false, static : static, method : method)
77 assert(d.found() == true, 'Cannot set version constraints')
78
79 # Check if we have to get pseudo components
80 d = dependency('llvm', modules: ['all-targets','native','engine'], required: false, static : static, method : method)
81 assert(d.found() == true, 'Cannot find pseudo components')
82
83 dep_tinfo = dependency('tinfo', required : false)
84 if not dep_tinfo.found()
85 cpp = meson.get_compiler('cpp')
86 dep_tinfo = cpp.find_library('tinfo', required: false)
87 endif
88
89 if static and method == 'cmake' and d.version().startswith('16.0')
90 message('Skipping modules with cmake due to an LLVM bug, see https://github.com/mesonbuild/meson/issues/11642')
91 llvm_dep = dependency(
92 'llvm',
93 required : false,
94 static : static,
95 method : method,
96 )
97 else
98 llvm_dep = dependency(
99 'llvm',
100 modules : modules_to_find,
101 required : false,
102 static : static,
103 method : method,
104 )
105 endif
106
107 if not llvm_dep.found()
108 error('MESON_SKIP_TEST required llvm modules not found.')
109 endif
110
111 executable(
112 'sum',
113 'sum.c',
114 dependencies : [
115 llvm_dep, dep_tinfo,
116 # zlib will be statically linked on windows
117 dependency('zlib', required : host_machine.system() != 'windows'),
118 meson.get_compiler('c').find_library('dl', required : false),
119 ]
120 )
121 endif