Debian Codegraph @

test cases/common/44 pkgconfig-gen/meson.build

raw
1 project('pkgconfig-gen', 'c', meson_version: '>=0.60.0')
2
3 # Some CI runners does not have zlib, just skip them as we need some common
4 # external dependency.
5 cc = meson.get_compiler('c')
6 if not cc.find_library('z', required: false).found()
7 error('MESON_SKIP_TEST: zlib missing')
8 endif
9
10 # First check we have pkg-config >= 0.29
11 pkgconfig = find_program('pkg-config', native: true, required: false)
12 if not pkgconfig.found()
13 error('MESON_SKIP_TEST: pkg-config not found')
14 endif
15
16 v = run_command(pkgconfig, '--version', check: true).stdout().strip()
17 if v.version_compare('<0.29')
18 error('MESON_SKIP_TEST: pkg-config version \'' + v + '\' too old')
19 endif
20
21 python = find_program('python3')
22 fs = import('fs')
23 pkgg = import('pkgconfig')
24
25 lib = shared_library('simple', 'simple.c')
26 libver = '1.0'
27 h = install_headers('simple.h')
28
29 pkgg.generate(
30 libraries : [lib, '-lz'],
31 subdirs : '.',
32 version : libver,
33 name : 'libsimple',
34 filebase : 'simple',
35 description : 'A simple demo library.',
36 requires : 'glib-2.0', # Not really, but only here to test that this works.
37 requires_private : ['gio-2.0', 'gobject-2.0'],
38 libraries_private : [lib, '-lz'],
39 cflags_private: '-DSIMPLE_STATIC',
40 )
41
42 env = environment()
43 env.prepend('PKG_CONFIG_PATH', meson.current_build_dir() / 'meson-private')
44
45 test(
46 'pkgconfig-validation',
47 pkgconfig,
48 args: ['--validate', 'simple'],
49 env : env,
50 )
51
52 answerlib = shared_library('answer', 'answer.c')
53
54 pkgg.generate(answerlib,
55 name : 'libanswer',
56 description : 'An answer library.',
57 extra_cflags : ['-DLIBFOO'],
58 )
59
60 # Test that name_prefix='' and name='libfoo' results in '-lfoo'
61 lib2 = shared_library('libfoo', 'foo.c',
62 link_with: answerlib,
63 name_prefix : '',
64 version : libver)
65
66 pkgg.generate(lib2,
67 libraries : [lib2, answerlib],
68 name : 'libfoo',
69 version : libver,
70 description : 'A foo library.',
71 variables : ['foo=bar', 'datadir=${prefix}/data'],
72 extra_cflags : ['-DLIBFOO'],
73 )
74
75 pkgg.generate(
76 name : 'libhello',
77 description : 'A minimalistic pkgconfig file.',
78 version : libver,
79 )
80
81 pkgg.generate(
82 name : 'libhello_nolib',
83 description : 'A minimalistic pkgconfig file.',
84 version : libver,
85 dataonly: true,
86 variables : {
87 'foo': 'bar',
88 # prefix is not set by default for dataonly pc files, but it is allowed to
89 # define it manually.
90 'prefix': get_option('prefix'),
91 'escaped_var': 'hello world',
92 },
93 unescaped_variables: {
94 'unescaped_var': 'hello world',
95 }
96 )
97
98 # Regression test for 2 cases:
99 # - link_whole from InternalDependency used to be ignored, but we should still
100 # recurse to add libraries they link to. In this case it must add `-lsimple1`
101 # in generated pc file.
102 # - dependencies from InternalDependency used to be ignored. In this it must add
103 # `-lz` in generated pc file.
104 simple1 = shared_library('simple1', 'simple.c')
105 stat1 = static_library('stat1', 'simple.c', link_with: simple1)
106 dep = declare_dependency(link_whole: stat1, dependencies: cc.find_library('z'))
107 simple2 = library('simple2', 'simple.c')
108 pkgg.generate(simple2, libraries: dep)
109
110 # Regression test: as_system() does a deepcopy() of the InternalDependency object
111 # which caused `-lsimple3` to be duplicated because generator used to compare
112 # Target instances instead of their id.
113 simple3 = shared_library('simple3', 'simple.c')
114 dep1 = declare_dependency(link_with: simple3)
115 dep2 = dep1.as_system()
116 pkgg.generate(libraries: [dep1, dep2],
117 name: 'simple3',
118 description: 'desc')
119
120 # Regression test: stat2 is both link_with and link_whole, it should not appear
121 # in generated pc file.
122 stat2 = static_library('stat2', 'simple.c', install: true)
123 simple4 = library('simple4', 'simple.c', link_with: stat2)
124 simple5 = library('simple5', 'simple5.c', link_with: simple4, link_whole: stat2)
125 pkgg.generate(simple5)
126
127 # Test passing a linkable CustomTarget and CustomTargetIndex to generator.
128 # Do this only with gcc/clang to not have to deal with other compiler command
129 # line specificities.
130 if cc.get_id() in ['gcc', 'clang']
131 ct = custom_target('ct',
132 input: 'simple.c',
133 output: 'libct.so',
134 command: [cc.cmd_array(), '@INPUT@', '-shared', '-o', '@OUTPUT@'],
135 )
136 pkgg.generate(libraries: ct,
137 name: 'ct',
138 description: 'custom target'
139 )
140 pkgg.generate(libraries: ct[0],
141 name: 'ct0',
142 description: 'custom target index'
143 )
144 endif
145
146 # Regression test: A library linking to an uninstalled custom_target static
147 # library used to crash when generating its pkgconfig file.
148 # Copy libstat2.a to libstat3.a to have a static library as custom target.
149 infile = stat2.full_path()
150 outfile = meson.current_build_dir() / 'libstat3.a'
151 script = 'import shutil ; shutil.copyfile("@0@", "@1@")'.format(infile, outfile)
152 ct = custom_target('stat3',
153 input: stat2,
154 output: fs.name(outfile),
155 command: [python, '-c', script],
156 )
157 simple6 = library('simple6', 'dependencies/dummy.c', link_with: ct)
158 pkgg.generate(simple6)
159
160 # implicit variables
161 pkgg.generate(
162 name : 'libvartest',
163 description : 'Check that implicit vars are created',
164 version : libver,
165 variables: ['datadir=${prefix}/data', 'foo=${datadir}/foo', 'bar=${bindir}/bar']
166 )
167 pkgg.generate(
168 name : 'libvartest2',
169 description : 'Check that libdir is not an implicit var',
170 version : libver,
171 variables: ['bar=${libdir}/bar']
172 )
173
174 # Regression test: variables kwarg should listify single string value
175 pkgg.generate(
176 name : 'libvartest3',
177 description : 'Check that variables can be single string',
178 variables: 'foo=bar',
179 )
180
181 # without a mainlib, name/description are mandatory
182 testcase expect_error('pkgconfig.generate: if a library is not passed as a positional argument, the \'name\' keyword argument is required.')
183 pkgg.generate(description: 'empty data')
184 endtestcase
185
186 testcase expect_error('pkgconfig.generate: if a library is not passed as a positional argument, the \'description\' keyword argument is required.')
187 pkgg.generate(name: 'foobar')
188 endtestcase
189
190 # Test for FeatureBroken warning with absolute subdirs
191 pkgg.generate(name: 'abssubdir', description: 'absolute subdirs test', subdirs: '/usr/include')
192
193 # Make sure the -uninstalled.pc file contains both include directories.
194 # See dependencies/test2.c that gets built against both simple7.pc and
195 # simple7-uninstalled.pc.
196 simple7 = library('simple7', include_directories: 'inc1')
197 dep = declare_dependency(include_directories: 'inc2')
198 install_headers('inc1/inc1.h', 'inc2/inc2.h')
199 pkgg.generate(simple7, libraries: dep)
200
201 # Regression test: empty string passed to requires.private should not
202 # fail the build
203 pkgg.generate(
204 name : 'emptytest',
205 description : 'Check that requires.private can be an empty string',
206 requires_private: '',
207 )