source: mainline/uspace/lib/meson.build@ 86f862c

Last change on this file since 86f862c was dc5c303, checked in by GitHub <noreply@…>, 22 months ago

Merge branch 'master' into topic/packet-capture

  • Property mode set to 100644
File size: 10.3 KB
Line 
1#
2# Copyright (c) 2019 Jiří Zárevúcky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29always_static = not CONFIG_BUILD_SHARED_LIBS
30
31# Which libraries are installed when CONFIG_DEVEL_FILES is enabled
32installed_libs = [
33 'c',
34 'math',
35 'display',
36 'pixconv',
37 'posix',
38 'clui',
39 'pcm',
40 'hound',
41 'gfx',
42 'gfximage',
43 'ipcgfx',
44 'congfx',
45 'display',
46 'ui',
47]
48
49# IMPORTANT: Dependencies must be listed before libs that depend on them.
50libs = [
51 'c',
52
53 'inet',
54
55 'input',
56 'output',
57 'console',
58 'device',
59
60 'block',
61 'clipboard',
62 'clui',
63 'codepage',
64 'compress',
65 'corecfg',
66 'cpp',
67 'crypto',
68 'dltest',
69 'fbfont',
70 'fdisk',
71 'fmtutil',
72 'fs',
73 'gfx',
74 'http',
75 'ipctest',
76 'label',
77 'math',
78 'minix',
79 'nettl',
80 'pcap',
81 'ofw',
82 'pcm',
83 'pcut',
84 'pixconv',
85 'posix',
86 'riff',
87 'scsi',
88 'sif',
89 'tbarcfg',
90 'trackmod',
91 'untar',
92 'uri',
93
94 'bithenge',
95 'congfx',
96 'drv',
97 'ext4',
98 'gfxfont',
99 'gfximage',
100 'hound',
101 'ipcgfx',
102 'memgfx',
103 'nic',
104 'usb',
105 'usbdev',
106 'usbhid',
107 'usbhost',
108 'usbvirt',
109 'virtio',
110
111 'ieee80211',
112 'ddev',
113 'dispcfg',
114 'display',
115 'wndmgt',
116
117 'ui',
118]
119
120# Generated list of include directory paths
121include_paths = []
122
123# Generated list of test sources
124testfiles = []
125
126# Text of the install script.
127uspace_lib_devel_install_script_text = []
128
129foreach l : libs
130 # Variables that might be defined in library meson files:
131
132 # List of source files.
133 # To set it correctly, use files('list.c', 'of.c', 'files.c')
134 # Often this is the only variable that needs to be set.
135 src = files()
136
137 # Public include directories. These are used by everyone who depends
138 # on this library.
139 # Use include_directories('include_dir1', 'include_dir2') to set this.
140 # If the variable is omitted, it defaults to 'include' subdirectory
141 # if it exists, or the source directory otherwise.
142 # If the library has no headers, you can use
143 # includes += include_directories()
144 includes = []
145
146 # Private include directories.
147 # Unnecessary if you always include private headers using relative
148 # paths, but may be useful if you need to override system headers.
149 private_includes = []
150
151 # List of dependency names.
152 # E.g. to use libnic and libuntar use
153 # `deps = [ 'nic', 'untar' ]`
154 deps = []
155
156 # Extra arguments for the C compiler.
157 # Don't use for arguments involving file paths.
158 c_args = []
159
160 # Shared object version of the library.
161 version = '0.0'
162
163 # Sources of unit tests.
164 # Automatically get compiled into a test binary,
165 # but not into the library itself.
166 test_src = []
167
168 # Language of the library.
169 # Currently supported options are 'c' and 'cpp', with 'c' being default.
170 language = 'c'
171
172 # Whether the library can be dynamically linked.
173 # Eventually, all libraries will be shared by default and this will go away.
174 allow_shared = false
175
176 subdir(l)
177
178 # Add `include` or `.` subdirectory to include dirs if needed.
179 if includes.length() == 0
180 incdir = join_paths(l, 'include')
181 if run_command('[', '-d', incdir, ']').returncode() == 0
182 includes += include_directories(incdir)
183
184 if installed_libs.contains(l)
185 _sdir = meson.current_source_dir() / l / 'include'
186 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
187 endif
188 else
189 includes += include_directories(l)
190
191 if installed_libs.contains(l)
192 _sdir = meson.current_source_dir() / l
193 uspace_lib_devel_install_script_text += 'mkdir -p "${DESTDIR}include/lib@0@"'.format(l)
194 uspace_lib_devel_install_script_text += 'cp -L -t "${DESTDIR}include/lib@0@" "@1@"/*.h || true'.format(l, _sdir)
195 endif
196 endif
197 endif
198
199 # Pretty much everything depends on libc.
200 if l != 'c'
201 deps += 'c'
202 endif
203
204 if language == 'cpp' and l != 'cpp'
205 deps += 'cpp'
206 endif
207
208 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
209
210 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
211 # We want linker to generate link map for debugging.
212 link_args += [ '-Wl,-Map,' + mapfile ]
213
214 # Convert strings to dependency objects
215 # TODO: this dependency business is way too convoluted due to issues in current Meson
216 _any_deps = []
217 _static_deps = []
218 _shared_deps = []
219 _include_deps = []
220 foreach s : deps
221 _any_deps += get_variable('lib' + s).get('any')
222 _static_deps += get_variable('lib' + s).get('static')
223 if not always_static
224 _shared_deps += get_variable('lib' + s).get('shared')
225 endif
226 _include_deps += get_variable('lib' + s).get('include')
227 endforeach
228
229 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
230 install_shared_lib = allow_shared
231
232 _shared_dep = disabler()
233
234 if src.length() > 0
235 if not always_static
236 _libname = 'lib' + l + '.so.' + version.split('.')[0]
237
238 _shared_lib = shared_library(l, src,
239 # TODO: Include private headers using #include "quoted",
240 # and get rid of private_includes.
241 include_directories: [ private_includes, includes ],
242 dependencies: _shared_deps,
243 c_args: arch_uspace_c_args + c_args,
244 cpp_args: arch_uspace_c_args + c_args,
245 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
246 version: version,
247 build_by_default: true,
248 )
249
250 if install_shared_lib
251 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]]
252 install_deps += [ _shared_lib ]
253 endif
254
255 if install_shared_lib and install_debug_files
256 install_files += [[ 'debug/lib', mapfile, _libname + '.map' ]]
257 endif
258
259 if disassemble
260 _disasm = custom_target('lib' + l + '.disasm',
261 command: [ objdump, '-S', '@INPUT@' ],
262 input: _shared_lib,
263 output: 'lib' + l + '.disasm',
264 capture: true,
265 build_by_default: true,
266 )
267
268 if install_shared_lib and install_debug_files
269 install_files += [[ 'debug/lib', _disasm.full_path(), _libname + '.disasm' ]]
270 install_deps += [ _disasm ]
271 endif
272 endif
273
274 _shared_dep = declare_dependency(
275 link_with: _shared_lib,
276 # TODO: Always use `include` subdirectory for public headers,
277 # and ditch the variable.
278 include_directories: includes,
279 dependencies: _shared_deps,
280 )
281 endif
282
283 _static_lib = static_library(l, src,
284 # TODO: Include private headers using #include "quoted",
285 # and get rid of private_includes.
286 include_directories: [ private_includes, includes ],
287 dependencies: _include_deps,
288 c_args: arch_uspace_c_args + c_args,
289 cpp_args: arch_uspace_c_args + c_args,
290 )
291
292 if install_static_lib
293 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
294 install_deps += [ _static_lib ]
295 endif
296
297 _static_dep = declare_dependency(
298 link_with: _static_lib,
299 # TODO: Always use `include` subdirectory for public headers,
300 # and ditch the variable.
301 include_directories: includes,
302 dependencies: _static_deps,
303 )
304
305 if always_static or not allow_shared
306 _any_dep = declare_dependency(
307 link_with: _static_lib,
308 # TODO: Always use `include` subdirectory for public headers,
309 # and ditch the variable.
310 include_directories: includes,
311 dependencies: _any_deps,
312 )
313 else
314 _any_dep = declare_dependency(
315 link_with: _shared_lib,
316 # TODO: Always use `include` subdirectory for public headers,
317 # and ditch the variable.
318 include_directories: includes,
319 dependencies: _any_deps,
320 )
321 endif
322
323 _include_dep = declare_dependency(
324 # TODO: Always use `include` subdirectory for public headers,
325 # and ditch the variable.
326 include_directories: includes,
327 dependencies: _include_deps,
328 )
329 else
330 # Header-only library.
331 _any_dep = declare_dependency(
332 include_directories: includes,
333 dependencies: _any_deps,
334 )
335 _static_dep = declare_dependency(
336 include_directories: includes,
337 dependencies: _static_deps,
338 )
339 endif
340
341 if test_src.length() > 0
342 testfiles += [ {
343 'name': l,
344 'src': test_src,
345 'includes': [ private_includes, includes ],
346 } ]
347 endif
348
349 set_variable('lib' + l, {
350 'any': _any_dep,
351 'static': _static_dep,
352 'shared': _shared_dep,
353 'include': _include_dep,
354 })
355endforeach
356
357if not CONFIG_PCUT_TESTS
358 subdir_done()
359endif
360
361# Test binaries
362foreach test : testfiles
363 _testname = test['name']
364 _libname = _testname.split('-')[0]
365 _ldargs = []
366 _test_binname = 'test-lib' + _testname
367
368 if link_map
369 # We want linker to generate link map for debugging.
370 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
371 endif
372
373 _bin = executable(_test_binname, test.get('src'),
374 include_directories: test.get('includes'),
375 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
376 link_whole: libstartfiles,
377 c_args: arch_uspace_c_args,
378 cpp_args: arch_uspace_c_args,
379 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
380 build_by_default: true,
381 )
382
383 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
384 install_deps += [ _bin ]
385
386 if disassemble
387 _disasm = custom_target(_test_binname + '.disasm',
388 command: [ objdump, '-S', '@INPUT@' ],
389 input: _bin,
390 output: _test_binname + '.disasm',
391 capture: true,
392 build_by_default: true,
393 )
394
395 if install_debug_files
396 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
397 install_deps += [ _disasm ]
398 endif
399 endif
400endforeach
Note: See TracBrowser for help on using the repository browser.