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

Last change on this file since fd398b2c was 3dd99dde, checked in by Jiri Svoboda <jiri@…>, 19 months ago

Fix export libraries list and helenos-pkg-config default export path

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