source: mainline/uspace/lib/meson.build@ 6301a24f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6301a24f was d8e2485, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Library with memory-backed GC (a.k.a. software renderer)

There are a few current cases where we can use this common implementation
instead of re-implementing it every time (e.g. window GC, RFB,
Canvas GC) as well as future ones.

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