source: mainline/uspace/lib/meson.build

Last change on this file was 4b9213d, checked in by GitHub <noreply@…>, 2 months ago

add shared libraries to export-dev (#252)

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