Debian Codegraph @

test cases/common/178 bothlibraries/meson.build

raw
1 project('both libraries linking test', 'c', 'cpp')
2
3 both_libs = both_libraries('mylib', 'libfile.c')
4 dep = declare_dependency(link_with: both_libs)
5 alias_target('alias', both_libs)
6 exe_shared = executable('prog-shared', 'main.c', link_with : both_libs.get_shared_lib())
7 exe_static = executable('prog-static', 'main.c',
8 c_args : ['-DSTATIC_COMPILATION'],
9 link_with : both_libs.get_static_lib())
10 exe_both = executable('prog-both', 'main.c', link_with : both_libs)
11 exe_dep = executable('prog-dep', 'main.c', dependencies : [dep])
12
13 # Try using it in a custom_target
14 custom_target('tgt_a',
15 command: [
16 find_program('./dummy.py'),
17 '@OUTPUT@',
18 both_libs,
19 ],
20 output: ['hello1.txt'],
21 input: [both_libs],
22 )
23
24 test('runtest-shared', exe_shared)
25 test('runtest-static', exe_static)
26 test('runtest-both', exe_both)
27 test('runtest-dep', exe_dep)
28
29 # Same as above, but using build_target()
30 both_libs2 = build_target('mylib2', 'libfile.c', target_type: 'both_libraries')
31 exe_shared2 = executable('prog-shared2', 'main.c',
32 link_with : both_libs2.get_shared_lib())
33 exe_static2 = executable('prog-static2', 'main.c',
34 c_args : ['-DSTATIC_COMPILATION'],
35 link_with : both_libs2.get_static_lib())
36 exe_both2 = executable('prog-both2', 'main.c', link_with : both_libs2)
37
38 # Test {set,get}_variable
39 set_variable('both_libs2', both_libs)
40 both_libs3 = get_variable('both_libs')
41
42 # Ensure that calling the build target methods also works
43 assert(both_libs.name() == 'mylib')
44 assert(both_libs2.name() == 'mylib')
45 assert(both_libs3.name() == 'mylib')
46 assert(both_libs2.get_shared_lib().name() == 'mylib')
47 assert(both_libs3.get_static_lib().name() == 'mylib')
48
49 test('runtest-shared-2', exe_shared2)
50 test('runtest-static-2', exe_static2)
51 test('runtest-both-2', exe_both2)
52
53 # Regression test: libccpp has both C and C++ sources. The executable only has
54 # C sources. It should still link using the C++ compiler. When using
55 # both_libraries the static has no sources and thus no compilers, resulting in
56 # the executable linking using the C compiler.
57 # https://github.com/Netflix/vmaf/issues/1107
58 libccpp = both_libraries('ccpp', 'foo.cpp', 'libfile.c',
59 cpp_args : ['-std=c++11'],
60 c_static_args : ['-DSTATIC_COMPILATION'],
61 cpp_static_args : ['-DSTATIC_COMPILATION'],
62 )
63 exe = executable('prog-ccpp', 'main2.c',
64 link_with: libccpp.get_static_lib(),
65 c_args : ['-DSTATIC_COMPILATION'],
66 )
67 test('runtest-ccpp', exe)
68
69 exe = executable('prog-ccpp-shared', 'main2.c',
70 link_with: libccpp.get_shared_lib(),
71 )
72 test('runtest-ccpp-shared', exe)