source: mainline/uspace/lib/meson.build@ 1822545

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

Display server scaffolding

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