source: mainline/uspace/lib/meson.build@ 58a67050

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

Stub user interface library and demo

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