Debian Codegraph @

test cases/common/273 both libraries/meson.build

raw
1 project(
2 'test both libraries',
3 'c',
4 meson_version: '>= 1.6.0',
5 )
6
7 expected = 0
8
9
10 with_bl = both_libraries(
11 'with_bl',
12 files('src/both_libraries.c'),
13 c_shared_args: ['-DEXPORT'],
14 )
15
16 with_bl_dep = declare_dependency(
17 link_with: with_bl,
18 )
19
20
21 if get_option('use_dep')
22 lib_deps = [with_bl_dep]
23 lib_links = []
24 else
25 lib_deps = []
26 lib_links = [with_bl]
27 endif
28
29
30 with_library = library(
31 'with_library',
32 files('src/library.c'),
33 c_shared_args: ['-DEXPORT'],
34 link_with: lib_links,
35 dependencies: lib_deps,
36 )
37
38 with_library_dep = declare_dependency(
39 link_with: with_library,
40 )
41
42
43 if get_option('default_library') == 'shared'
44 expected += 1
45 if get_option('default_both_libraries') in ['shared', 'auto']
46 expected += 1
47 endif
48 elif get_option('default_library') == 'both'
49 if get_option('default_both_libraries') in ['shared', 'auto']
50 expected += 2
51 endif
52 else
53 if get_option('default_both_libraries') == 'shared'
54 expected += 1
55 endif
56 endif
57
58
59 if get_option('use_dep')
60 main_deps = [with_library_dep]
61 main_links = []
62 else
63 main_deps = []
64 main_links = [with_library]
65 endif
66
67 main = executable(
68 'main',
69 files('src/main.c'),
70 c_args: [f'-DEXPECTED=@expected@'],
71 link_with: main_links,
72 dependencies: main_deps,
73 )
74 test('test both libs', main)
75
76
77 if get_option('default_library') == 'both' and get_option('default_both_libraries') == 'auto'
78 # With those options, even if the both_libraries defaults to 'shared',
79 # 'static' version is used when linking to the static part of another both_libraries.
80
81 if get_option('use_dep')
82 main_static_deps = [with_library_dep.as_static(recursive: true)]
83 main_static_links = []
84 else
85 main_static_deps = []
86 main_static_links = [with_library.get_static_lib()]
87 endif
88 main_static = executable(
89 'main_static',
90 files('src/main.c'),
91 c_args: [f'-DEXPECTED=0'],
92 link_with: main_static_links,
93 dependencies: main_static_deps,
94 )
95 test('test static', main_static)
96
97
98 if get_option('use_dep')
99 main_shared_deps = [with_library_dep.as_shared(recursive: true)]
100 main_shared_links = []
101 else
102 main_shared_deps = []
103 main_shared_links = [with_library.get_shared_lib()]
104 endif
105 main_shared = executable(
106 'main_shared',
107 files('src/main.c'),
108 c_args: [f'-DEXPECTED=2'],
109 link_with: main_shared_links,
110 dependencies: main_shared_deps,
111 )
112 test('test shared', main_shared)
113 endif
114
115 # Test case for https://github.com/mesonbuild/meson/pull/14098
116 if get_option('default_library') == 'shared'
117
118 if get_option('use_dep')
119 lib_deps = [with_bl_dep.as_static(recursive: true)]
120 lib_links = []
121 else
122 lib_deps = []
123 lib_links = [with_bl.get_static_lib()]
124 endif
125
126 lib_with_static_dep = library(
127 'lib_with_static_dep',
128 files('src/library.c'),
129 c_shared_args: ['-DEXPORT'],
130 link_with: lib_links,
131 dependencies: lib_deps,
132 )
133
134 main_with_static_dep = executable(
135 'main_with_static_dep',
136 files('src/main.c'),
137 c_args: [f'-DEXPECTED=1'],
138 link_with: lib_with_static_dep,
139 )
140 test('test static dep', main_with_static_dep)
141
142 endif