source: mainline/uspace/lib/meson.build@ 0d275e1

topic/simplify-dev-export
Last change on this file since 0d275e1 was 1be9ee0, checked in by Jiri Svoboda <jiri@…>, 23 months ago

Move output API to separate library

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