source: mainline/uspace/lib/meson.build@ d63c842

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d63c842 was d63c842, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

more unification

  • Property mode set to 100644
File size: 8.1 KB
Line 
1always_static = (get_option('default_library') == 'static')
2
3# Which libraries are installed when CONFIG_DEVEL_FILES is enabled
4installed_libs = [
5 'c',
6 'math',
7 'gui',
8 'draw',
9 'softrend',
10 'posix',
11]
12
13# IMPORTANT: Dependencies must be listed before libs that depend on them.
14libs = [
15 'c',
16
17 'block',
18 'clui',
19 'compress',
20 'cpp',
21 'crypto',
22 'dltest',
23 'fdisk',
24 'fmtutil',
25 'fs',
26 'graph',
27 'http',
28 'label',
29 'math',
30 'minix',
31 'nettl',
32 'pcm',
33 'pcut',
34 'posix',
35 'scsi',
36 'sif',
37 'softrend',
38 'trackmod',
39 'untar',
40 'uri',
41
42 'bithenge',
43 'draw',
44 'drv',
45 'ext4',
46 'gui',
47 'hound',
48 'nic',
49 'usb',
50 'usbdev',
51 'usbhid',
52 'usbhost',
53 'usbvirt',
54 'virtio',
55
56 'ieee80211',
57]
58
59# Generated list of include directory paths
60include_paths = []
61
62# Generated list of test sources
63testfiles = []
64
65# Text of the install script.
66uspace_lib_install_script_text = []
67uspace_lib_install_depends = []
68
69foreach l : libs
70 # Variables that might be defined in library meson files:
71
72 # List of source files.
73 # To set it correctly, use files('list.c', 'of.c', 'files.c')
74 # Often this is the only variable that needs to be set.
75 src = files()
76
77 # Public include directories. These are used by everyone who depends
78 # on this library.
79 # Use include_directories('include_dir1', 'include_dir2') to set this.
80 # If the variable is omitted, it defaults to 'include' subdirectory
81 # if it exists, or the source directory otherwise.
82 # If the library has no headers, you can use
83 # includes += include_directories()
84 includes = []
85
86 # Private include directories.
87 # Unnecessary if you always include private headers using relative
88 # paths, but may be useful if you need to override system headers.
89 private_includes = []
90
91 # List of dependency names.
92 # E.g. to use libnic and libuntar use
93 # `deps = [ 'nic', 'untar' ]`
94 deps = []
95
96 # Extra arguments for the C compiler.
97 # Don't use for arguments involving file paths.
98 c_args = []
99
100 # Shared object version of the library.
101 version = '0.0'
102
103 # Sources of unit tests.
104 # Automatically get compiled into a test binary,
105 # but not into the library itself.
106 test_src = []
107
108 # Language of the library.
109 # Currently supported options are 'c' and 'cpp', with 'c' being default.
110 language = 'c'
111
112 # Whether the library can be dynamically linked.
113 # Eventually, all libraries will be shared by default and this will go away.
114 allow_shared = false
115
116 subdir(l)
117
118 # Add `include` or `.` subdirectory to include dirs if needed.
119 if includes.length() == 0
120 incdir = join_paths(l, 'include')
121 if run_command('[', '-d', incdir, ']').returncode() == 0
122 includes += include_directories(incdir)
123
124 if CONFIG_DEVEL_FILES and installed_libs.contains(l)
125 _sdir = meson.current_source_dir() / l / 'include'
126 uspace_lib_install_script_text += 'cp -R -L -T "@0@" "${MESON_INSTALL_DESTDIR_PREFIX}include/lib@1@"'.format(_sdir, l)
127 endif
128 else
129 includes += include_directories(l)
130
131 if CONFIG_DEVEL_FILES and installed_libs.contains(l)
132 _sdir = meson.current_source_dir() / l
133 uspace_lib_install_script_text += 'mkdir -p "${MESON_INSTALL_DESTDIR_PREFIX}include/lib@0@"'.format(l)
134 uspace_lib_install_script_text += 'cp -L -t "${MESON_INSTALL_DESTDIR_PREFIX}include/lib@0@" "@1@"/*.h'.format(l, _sdir)
135 endif
136 endif
137 endif
138
139 # Pretty much everything depends on libc.
140 if l != 'c'
141 deps += 'c'
142 endif
143
144 if language == 'cpp' and l != 'cpp'
145 deps += 'cpp'
146 endif
147
148 # TODO: install mapfile if install_debug_data is true
149 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
150
151 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
152 # We want linker to generate link map for debugging.
153 link_args += [ '-Wl,-Map,' + mapfile ]
154
155 # Convert strings to dependency objects
156 # TODO: this dependency business is way too convoluted due to issues in current Meson
157 _any_deps = []
158 _static_deps = []
159 _shared_deps = []
160 _include_deps = []
161 foreach s : deps
162 _any_deps += get_variable('lib' + s).get('any')
163 _static_deps += get_variable('lib' + s).get('static')
164 if not always_static
165 _shared_deps += get_variable('lib' + s).get('shared')
166 endif
167 _include_deps += get_variable('lib' + s).get('include')
168 endforeach
169
170 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
171 install_shared_lib = allow_shared
172
173 _shared_dep = disabler()
174
175 if src.length() > 0
176 if not always_static
177 _shared_lib = shared_library(l, src,
178 # TODO: Include private headers using #include "quoted",
179 # and get rid of private_includes.
180 include_directories: [ private_includes, includes ],
181 dependencies: _shared_deps,
182 c_args: arch_uspace_c_args + c_args,
183 cpp_args: arch_uspace_c_args + c_args,
184 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
185 version: version,
186 build_by_default: true,
187 install: install_shared_lib,
188 install_dir: 'lib',
189 )
190
191 if disassemble
192 custom_target('lib' + l + '.disasm',
193 command: [ objdump, '-S', '@INPUT@' ],
194 input: _shared_lib,
195 output: 'lib' + l + '.disasm',
196 capture: true,
197 build_by_default: true,
198 install: install_debug_files,
199 install_dir: join_paths('debug', 'lib'),
200 )
201 endif
202
203 _shared_dep = declare_dependency(
204 link_with: _shared_lib,
205 # TODO: Always use `include` subdirectory for public headers,
206 # and ditch the variable.
207 include_directories: includes,
208 dependencies: _shared_deps,
209 )
210 endif
211
212 _static_lib = static_library(l, src,
213 # TODO: Include private headers using #include "quoted",
214 # and get rid of private_includes.
215 include_directories: [ private_includes, includes ],
216 dependencies: _include_deps,
217 c_args: arch_uspace_c_args + c_args,
218 cpp_args: arch_uspace_c_args + c_args,
219 install: install_static_lib,
220 install_dir: 'lib',
221 )
222
223 _static_dep = declare_dependency(
224 link_with: _static_lib,
225 # TODO: Always use `include` subdirectory for public headers,
226 # and ditch the variable.
227 include_directories: includes,
228 dependencies: _static_deps,
229 )
230
231 if always_static or not allow_shared
232 _any_dep = declare_dependency(
233 link_with: _static_lib,
234 # TODO: Always use `include` subdirectory for public headers,
235 # and ditch the variable.
236 include_directories: includes,
237 dependencies: _any_deps,
238 )
239 else
240 _any_dep = declare_dependency(
241 link_with: _shared_lib,
242 # TODO: Always use `include` subdirectory for public headers,
243 # and ditch the variable.
244 include_directories: includes,
245 dependencies: _any_deps,
246 )
247 endif
248
249 _include_dep = declare_dependency(
250 # TODO: Always use `include` subdirectory for public headers,
251 # and ditch the variable.
252 include_directories: includes,
253 dependencies: _include_deps,
254 )
255 else
256 # Header-only library.
257 _any_dep = declare_dependency(
258 include_directories: includes,
259 dependencies: _any_deps,
260 )
261 _static_dep = declare_dependency(
262 include_directories: includes,
263 dependencies: _static_deps,
264 )
265 endif
266
267 if test_src.length() > 0
268 testfiles += [ {
269 'name': l,
270 'src': test_src,
271 'includes': [ private_includes, includes ],
272 } ]
273 endif
274
275 set_variable('lib' + l, {
276 'any': _any_dep,
277 'static': _static_dep,
278 'shared': _shared_dep,
279 'include': _include_dep,
280 })
281endforeach
282
283if not CONFIG_PCUT_TESTS
284 subdir_done()
285endif
286
287# Test binaries
288foreach test : testfiles
289 _testname = test['name']
290 _libname = _testname.split('-')[0]
291 _ldargs = []
292 _test_binname = 'test-lib' + _testname
293
294 if link_map
295 # We want linker to generate link map for debugging.
296 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
297 endif
298
299 _bin = executable(_test_binname, test.get('src'),
300 include_directories: test.get('includes'),
301 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
302 objects: startfiles,
303 install: true,
304 install_dir: 'test',
305 c_args: arch_uspace_c_args,
306 cpp_args: arch_uspace_c_args,
307 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
308 )
309
310 if disassemble
311 custom_target(_test_binname + '.disasm',
312 command: [ objdump, '-S', '@INPUT@' ],
313 input: _bin,
314 output: _test_binname + '.disasm',
315 capture: true,
316 install: install_debug_files,
317 install_dir: 'debug' / 'test',
318 )
319 endif
320endforeach
Note: See TracBrowser for help on using the repository browser.