| 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 |
) |
| 40 |
|
| 41 |
env = environment() |
| 42 |
env.prepend('PKG_CONFIG_PATH', meson.current_build_dir() / 'meson-private') |
| 43 |
|
| 44 |
test( |
| 45 |
'pkgconfig-validation', |
| 46 |
pkgconfig, |
| 47 |
args: ['--validate', 'simple'], |
| 48 |
env : env, |
| 49 |
) |
| 50 |
|
| 51 |
answerlib = shared_library('answer', 'answer.c') |
| 52 |
|
| 53 |
pkgg.generate(answerlib, |
| 54 |
name : 'libanswer', |
| 55 |
description : 'An answer library.', |
| 56 |
extra_cflags : ['-DLIBFOO'], |
| 57 |
) |
| 58 |
|
| 59 |
# Test that name_prefix='' and name='libfoo' results in '-lfoo' |
| 60 |
lib2 = shared_library('libfoo', 'foo.c', |
| 61 |
link_with: answerlib, |
| 62 |
name_prefix : '', |
| 63 |
version : libver) |
| 64 |
|
| 65 |
pkgg.generate(lib2, |
| 66 |
libraries : [lib2, answerlib], |
| 67 |
name : 'libfoo', |
| 68 |
version : libver, |
| 69 |
description : 'A foo library.', |
| 70 |
variables : ['foo=bar', 'datadir=${prefix}/data'], |
| 71 |
extra_cflags : ['-DLIBFOO'], |
| 72 |
) |
| 73 |
|
| 74 |
pkgg.generate( |
| 75 |
name : 'libhello', |
| 76 |
description : 'A minimalistic pkgconfig file.', |
| 77 |
version : libver, |
| 78 |
) |
| 79 |
|
| 80 |
pkgg.generate( |
| 81 |
name : 'libhello_nolib', |
| 82 |
description : 'A minimalistic pkgconfig file.', |
| 83 |
version : libver, |
| 84 |
dataonly: true, |
| 85 |
variables : { |
| 86 |
'foo': 'bar', |
| 87 |
# prefix is not set by default for dataonly pc files, but it is allowed to |
| 88 |
# define it manually. |
| 89 |
'prefix': get_option('prefix'), |
| 90 |
'escaped_var': 'hello world', |
| 91 |
}, |
| 92 |
unescaped_variables: { |
| 93 |
'unescaped_var': 'hello world', |
| 94 |
} |
| 95 |
) |
| 96 |
|
| 97 |
# Regression test for 2 cases: |
| 98 |
# - link_whole from InternalDependency used to be ignored, but we should still |
| 99 |
# recurse to add libraries they link to. In this case it must add `-lsimple1` |
| 100 |
# in generated pc file. |
| 101 |
# - dependencies from InternalDependency used to be ignored. In this it must add |
| 102 |
# `-lz` in generated pc file. |
| 103 |
simple1 = shared_library('simple1', 'simple.c') |
| 104 |
stat1 = static_library('stat1', 'simple.c', link_with: simple1) |
| 105 |
dep = declare_dependency(link_whole: stat1, dependencies: cc.find_library('z')) |
| 106 |
simple2 = library('simple2', 'simple.c') |
| 107 |
pkgg.generate(simple2, libraries: dep) |
| 108 |
|
| 109 |
# Regression test: as_system() does a deepcopy() of the InternalDependency object |
| 110 |
# which caused `-lsimple3` to be duplicated because generator used to compare |
| 111 |
# Target instances instead of their id. |
| 112 |
simple3 = shared_library('simple3', 'simple.c') |
| 113 |
dep1 = declare_dependency(link_with: simple3) |
| 114 |
dep2 = dep1.as_system() |
| 115 |
pkgg.generate(libraries: [dep1, dep2], |
| 116 |
name: 'simple3', |
| 117 |
description: 'desc') |
| 118 |
|
| 119 |
# Regression test: stat2 is both link_with and link_whole, it should not appear |
| 120 |
# in generated pc file. |
| 121 |
stat2 = static_library('stat2', 'simple.c', install: true) |
| 122 |
simple4 = library('simple4', 'simple.c', link_with: stat2) |
| 123 |
simple5 = library('simple5', 'simple5.c', link_with: simple4, link_whole: stat2) |
| 124 |
pkgg.generate(simple5) |
| 125 |
|
| 126 |
# Test passing a linkable CustomTarget and CustomTargetIndex to generator. |
| 127 |
# Do this only with gcc/clang to not have to deal with other compiler command |
| 128 |
# line specificities. |
| 129 |
if cc.get_id() in ['gcc', 'clang'] |
| 130 |
ct = custom_target('ct', |
| 131 |
input: 'simple.c', |
| 132 |
output: 'libct.so', |
| 133 |
command: [cc.cmd_array(), '@INPUT@', '-shared', '-o', '@OUTPUT@'], |
| 134 |
) |
| 135 |
pkgg.generate(libraries: ct, |
| 136 |
name: 'ct', |
| 137 |
description: 'custom target' |
| 138 |
) |
| 139 |
pkgg.generate(libraries: ct[0], |
| 140 |
name: 'ct0', |
| 141 |
description: 'custom target index' |
| 142 |
) |
| 143 |
endif |
| 144 |
|
| 145 |
# Regression test: A library linking to an uninstalled custom_target static |
| 146 |
# library used to crash when generating its pkgconfig file. |
| 147 |
# Copy libstat2.a to libstat3.a to have a static library as custom target. |
| 148 |
infile = stat2.full_path() |
| 149 |
outfile = meson.current_build_dir() / 'libstat3.a' |
| 150 |
script = 'import shutil ; shutil.copyfile("@0@", "@1@")'.format(infile, outfile) |
| 151 |
ct = custom_target('stat3', |
| 152 |
input: stat2, |
| 153 |
output: fs.name(outfile), |
| 154 |
command: [python, '-c', script], |
| 155 |
) |
| 156 |
simple6 = library('simple6', 'dependencies/dummy.c', link_with: ct) |
| 157 |
pkgg.generate(simple6) |
| 158 |
|
| 159 |
# implicit variables |
| 160 |
pkgg.generate( |
| 161 |
name : 'libvartest', |
| 162 |
description : 'Check that implicit vars are created', |
| 163 |
version : libver, |
| 164 |
variables: ['datadir=${prefix}/data', 'foo=${datadir}/foo', 'bar=${bindir}/bar'] |
| 165 |
) |
| 166 |
pkgg.generate( |
| 167 |
name : 'libvartest2', |
| 168 |
description : 'Check that libdir is not an implicit var', |
| 169 |
version : libver, |
| 170 |
variables: ['bar=${libdir}/bar'] |
| 171 |
) |
| 172 |
|
| 173 |
# Regression test: variables kwarg should listify single string value |
| 174 |
pkgg.generate( |
| 175 |
name : 'libvartest3', |
| 176 |
description : 'Check that variables can be single string', |
| 177 |
variables: 'foo=bar', |
| 178 |
) |
| 179 |
|
| 180 |
# without a mainlib, name/description are mandatory |
| 181 |
testcase expect_error('pkgconfig.generate: if a library is not passed as a positional argument, the \'name\' keyword argument is required.') |
| 182 |
pkgg.generate(description: 'empty data') |
| 183 |
endtestcase |
| 184 |
|
| 185 |
testcase expect_error('pkgconfig.generate: if a library is not passed as a positional argument, the \'description\' keyword argument is required.') |
| 186 |
pkgg.generate(name: 'foobar') |
| 187 |
endtestcase |
| 188 |
|
| 189 |
# Make sure the -uninstalled.pc file contains both include directories. |
| 190 |
# See dependencies/test2.c that gets built against both simple7.pc and |
| 191 |
# simple7-uninstalled.pc. |
| 192 |
simple7 = library('simple7', include_directories: 'inc1') |
| 193 |
dep = declare_dependency(include_directories: 'inc2') |
| 194 |
install_headers('inc1/inc1.h', 'inc2/inc2.h') |
| 195 |
pkgg.generate(simple7, libraries: dep) |