source: mainline/uspace/lib/meson.build@ 4d9c807

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

Display device protocol library

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