source: mainline/uspace/lib/meson.build@ 6c1e7c0

Last change on this file since 6c1e7c0 was f2cb80a, checked in by GitHub <noreply@…>, 20 months ago

Merge branch 'HelenOS:master' into topic/packet-capture

  • Property mode set to 100644
File size: 10.4 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 _sdir = meson.current_source_dir() / l / 'include'
184
185 if installed_libs.contains(l)
186 uspace_lib_devel_install_script_text += 'cp -R -L -T "@0@" "${DESTDIR}include/lib@1@"'.format(_sdir, l)
187 endif
188
189 exported_devel_files += ['include', _sdir, 'lib' + l]
190 else
191 includes += include_directories(l)
192
193 if installed_libs.contains(l)
194 _sdir = meson.current_source_dir() / l
195 uspace_lib_devel_install_script_text += 'mkdir -p "${DESTDIR}include/lib@0@"'.format(l)
196 uspace_lib_devel_install_script_text += 'cp -L -t "${DESTDIR}include/lib@0@" "@1@"/*.h || true'.format(l, _sdir)
197 endif
198 endif
199 endif
200
201 # Pretty much everything depends on libc.
202 if l != 'c'
203 deps += 'c'
204 endif
205
206 if language == 'cpp' and l != 'cpp'
207 deps += 'cpp'
208 endif
209
210 mapfile = meson.current_build_dir() / 'lib' + l + '.map'
211
212 link_args = [ '-Wl,--no-undefined,--no-allow-shlib-undefined' ]
213 # We want linker to generate link map for debugging.
214 link_args += [ '-Wl,-Map,' + mapfile ]
215
216 # Convert strings to dependency objects
217 # TODO: this dependency business is way too convoluted due to issues in current Meson
218 _any_deps = []
219 _static_deps = []
220 _shared_deps = []
221 _include_deps = []
222 foreach s : deps
223 _any_deps += get_variable('lib' + s).get('any')
224 _static_deps += get_variable('lib' + s).get('static')
225 if not always_static
226 _shared_deps += get_variable('lib' + s).get('shared')
227 endif
228 _include_deps += get_variable('lib' + s).get('include')
229 endforeach
230
231 install_static_lib = CONFIG_DEVEL_FILES and installed_libs.contains(l)
232 install_shared_lib = allow_shared
233
234 _shared_dep = disabler()
235
236 if src.length() > 0
237 if not always_static
238 _libname = 'lib' + l + '.so.' + version.split('.')[0]
239
240 _shared_lib = shared_library(l, src,
241 # TODO: Include private headers using #include "quoted",
242 # and get rid of private_includes.
243 include_directories: [ private_includes, includes ],
244 dependencies: _shared_deps,
245 c_args: arch_uspace_c_args + c_args,
246 cpp_args: arch_uspace_c_args + c_args,
247 link_args: arch_uspace_c_args + arch_uspace_link_args + link_args,
248 version: version,
249 build_by_default: true,
250 )
251
252 if install_shared_lib
253 install_files += [[ 'lib', _shared_lib.full_path(), _libname ]]
254 install_deps += [ _shared_lib ]
255 endif
256
257 if install_shared_lib and install_debug_files
258 install_files += [[ 'debug/lib', mapfile, _libname + '.map' ]]
259 endif
260
261 if disassemble
262 _disasm = custom_target('lib' + l + '.disasm',
263 command: [ objdump, '-S', '@INPUT@' ],
264 input: _shared_lib,
265 output: 'lib' + l + '.disasm',
266 capture: true,
267 build_by_default: true,
268 )
269
270 if install_shared_lib and install_debug_files
271 install_files += [[ 'debug/lib', _disasm.full_path(), _libname + '.disasm' ]]
272 install_deps += [ _disasm ]
273 endif
274 endif
275
276 _shared_dep = declare_dependency(
277 link_with: _shared_lib,
278 # TODO: Always use `include` subdirectory for public headers,
279 # and ditch the variable.
280 include_directories: includes,
281 dependencies: _shared_deps,
282 )
283 endif
284
285 _static_lib = static_library(l, src,
286 # TODO: Include private headers using #include "quoted",
287 # and get rid of private_includes.
288 include_directories: [ private_includes, includes ],
289 dependencies: _include_deps,
290 c_args: arch_uspace_c_args + c_args,
291 cpp_args: arch_uspace_c_args + c_args,
292 )
293
294 if install_static_lib
295 install_files += [[ 'lib', _static_lib.full_path(), 'lib' + l + '.a' ]]
296 install_deps += [ _static_lib ]
297 endif
298
299 exported_devel_files += ['staticlib', _static_lib, 'lib' + l + '.a']
300
301 _static_dep = declare_dependency(
302 link_with: _static_lib,
303 # TODO: Always use `include` subdirectory for public headers,
304 # and ditch the variable.
305 include_directories: includes,
306 dependencies: _static_deps,
307 )
308
309 if always_static or not allow_shared
310 _any_dep = declare_dependency(
311 link_with: _static_lib,
312 # TODO: Always use `include` subdirectory for public headers,
313 # and ditch the variable.
314 include_directories: includes,
315 dependencies: _any_deps,
316 )
317 else
318 _any_dep = declare_dependency(
319 link_with: _shared_lib,
320 # TODO: Always use `include` subdirectory for public headers,
321 # and ditch the variable.
322 include_directories: includes,
323 dependencies: _any_deps,
324 )
325 endif
326
327 _include_dep = declare_dependency(
328 # TODO: Always use `include` subdirectory for public headers,
329 # and ditch the variable.
330 include_directories: includes,
331 dependencies: _include_deps,
332 )
333 else
334 # Header-only library.
335 _any_dep = declare_dependency(
336 include_directories: includes,
337 dependencies: _any_deps,
338 )
339 _static_dep = declare_dependency(
340 include_directories: includes,
341 dependencies: _static_deps,
342 )
343 endif
344
345 if test_src.length() > 0
346 testfiles += [ {
347 'name': l,
348 'src': test_src,
349 'includes': [ private_includes, includes ],
350 } ]
351 endif
352
353 set_variable('lib' + l, {
354 'any': _any_dep,
355 'static': _static_dep,
356 'shared': _shared_dep,
357 'include': _include_dep,
358 })
359endforeach
360
361if not CONFIG_PCUT_TESTS
362 subdir_done()
363endif
364
365# Test binaries
366foreach test : testfiles
367 _testname = test['name']
368 _libname = _testname.split('-')[0]
369 _ldargs = []
370 _test_binname = 'test-lib' + _testname
371
372 if link_map
373 # We want linker to generate link map for debugging.
374 _ldargs += [ '-Wl,-Map,' + meson.current_build_dir() / _test_binname + '.map' ]
375 endif
376
377 _bin = executable(_test_binname, test.get('src'),
378 include_directories: test.get('includes'),
379 dependencies: [ get_variable('lib' + _libname).get('any'), libpcut.get('any') ],
380 link_whole: libstartfiles,
381 c_args: arch_uspace_c_args,
382 cpp_args: arch_uspace_c_args,
383 link_args: arch_uspace_c_args + arch_uspace_link_args + _ldargs,
384 build_by_default: true,
385 )
386
387 install_files += [[ 'test', _bin.full_path(), _test_binname ]]
388 install_deps += [ _bin ]
389
390 if disassemble
391 _disasm = custom_target(_test_binname + '.disasm',
392 command: [ objdump, '-S', '@INPUT@' ],
393 input: _bin,
394 output: _test_binname + '.disasm',
395 capture: true,
396 build_by_default: true,
397 )
398
399 if install_debug_files
400 install_files += [[ 'debug/test', _disasm.full_path(), _test_binname + '.disasm' ]]
401 install_deps += [ _disasm ]
402 endif
403 endif
404endforeach
Note: See TracBrowser for help on using the repository browser.