source: mainline/uspace/lib/meson.build@ 901b302

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 901b302 was 0761448, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Window management protocol library

This allows the client to enumerate windows, activate or close a window.

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