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

topic/simplify-dev-export
Last change on this file since 0e2eee1 was 0e2eee1, checked in by Jiri Svoboda <jiri@…>, 2 years ago

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