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

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

Start porting libgui over to libdisplay/libgfx

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