[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/10] meson: option to build as shared library
From: |
Joelle van Dyne |
Subject: |
[PATCH 04/10] meson: option to build as shared library |
Date: |
Mon, 12 Oct 2020 16:29:33 -0700 |
From: osy <osy86@users.noreply.github.com>
On iOS, we cannot fork() new processes, so the best way to load QEMU into an
app is through a shared library. We add a new configure option
`--enable-shared-lib` that will build the bulk of QEMU into a shared lib.
The usual executables will then link to the library.
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
configure | 14 ++++++++++++--
meson.build | 40 ++++++++++++++++++++++++++++++++++------
meson_options.txt | 2 ++
3 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/configure b/configure
index c474d7c221..37b27d9e35 100755
--- a/configure
+++ b/configure
@@ -448,6 +448,7 @@ ninja=""
skip_meson=no
gettext=""
host_block_device_support="yes"
+shared_lib="false"
bogus_os="no"
malloc_trim="auto"
@@ -1563,6 +1564,10 @@ for opt do
;;
--disable-libdaxctl) libdaxctl=no
;;
+ --enable-shared-lib) shared_lib=true
+ ;;
+ --disable-shared-lib) shared_lib=false
+ ;;
*)
echo "ERROR: unknown option $opt"
echo "Try '$0 --help' for more information"
@@ -1770,6 +1775,7 @@ Advanced options (experts only):
enable plugins via shared library loading
--disable-containers don't use containers for cross-building
--gdb=GDB-path gdb to use for gdbstub tests [$gdb_bin]
+ --enable-shared-lib build QEMU as a shared library
Optional features, enabled with --enable-FEATURE and
disabled with --disable-FEATURE, default is enabled if available:
@@ -7211,7 +7217,11 @@ echo "ranlib = [$(meson_quote $ranlib)]" >> $cross
if has $sdl2_config; then
echo "sdl2-config = [$(meson_quote $sdl2_config)]" >> $cross
fi
-echo "strip = [$(meson_quote $strip)]" >> $cross
+if test "$shared_lib" = "true"; then
+ echo "strip = [$(meson_quote $strip), '-x']" >> $cross
+else
+ echo "strip = [$(meson_quote $strip)]" >> $cross
+fi
echo "windres = [$(meson_quote $windres)]" >> $cross
if test "$cross_compile" = "yes"; then
cross_arg="--cross-file config-meson.cross"
@@ -7273,7 +7283,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \
-Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png
\
-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
- -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
+ -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt -Dshared-lib=$shared_lib
\
$cross_arg \
"$PWD" "$source_path"
diff --git a/meson.build b/meson.build
index 69a3c00cce..32cf08619f 100644
--- a/meson.build
+++ b/meson.build
@@ -1565,14 +1565,31 @@ foreach target : target_dirs
arch_srcs += target_specific.sources()
arch_deps += target_specific.dependencies()
- lib = static_library('qemu-' + target,
+ if get_option('shared-lib')
+ build_lib_args = {
+ 'target_type': 'shared_library',
+ 'install': true,
+ 'dependencies': arch_deps + deps,
+ 'link_language': link_language,
+ 'link_depends': [block_syms, qemu_syms],
+ 'link_args': link_args +
cc.get_supported_link_arguments(['-Wl,-U,_qemu_main'])
+ }
+ else
+ build_lib_args = {
+ 'target_type': 'static_library',
+ 'install': false,
+ 'dependencies': arch_deps,
+ 'name_suffix': 'fa'
+ }
+ endif
+
+ lib = build_target('qemu-' + target,
sources: arch_srcs + genh,
- dependencies: arch_deps,
objects: objects,
include_directories: target_inc,
c_args: c_args,
build_by_default: false,
- name_suffix: 'fa')
+ kwargs: build_lib_args)
if target.endswith('-softmmu')
execs = [{
@@ -1606,17 +1623,27 @@ foreach target : target_dirs
'dependencies': []
}]
endif
+ if get_option('shared-lib')
+ build_exe_args = {
+ 'link_with': lib,
+ 'link_args': link_args +
cc.get_supported_link_arguments(['-Wl,--exclude-libs,ALL'])
+ }
+ else
+ build_exe_args = {
+ 'objects': lib.extract_all_objects(recursive: true),
+ 'link_args': link_args
+ }
+ endif
foreach exe: execs
emulators += {exe['name']:
executable(exe['name'], exe['sources'],
install: true,
c_args: c_args,
dependencies: arch_deps + deps + exe['dependencies'],
- objects: lib.extract_all_objects(recursive: true),
link_language: link_language,
link_depends: [block_syms, qemu_syms] + exe.get('link_depends',
[]),
- link_args: link_args,
- gui_app: exe['gui'])
+ gui_app: exe['gui'],
+ kwargs: build_exe_args)
}
if 'CONFIG_TRACE_SYSTEMTAP' in config_host
@@ -1758,6 +1785,7 @@ endif
summary_info += {'Doc directory': get_option('docdir')}
summary_info += {'Build directory': meson.current_build_dir()}
summary_info += {'Source path': meson.current_source_dir()}
+summary_info += {'build shared lib': get_option('shared-lib')}
summary_info += {'GIT binary': config_host['GIT']}
summary_info += {'GIT submodules': config_host['GIT_SUBMODULES']}
summary_info += {'C compiler': meson.get_compiler('c').cmd_array()[0]}
diff --git a/meson_options.txt b/meson_options.txt
index 1d3c94840a..bcecbd5e12 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,6 +2,8 @@ option('qemu_suffix', type : 'string', value: 'qemu',
description: 'Suffix for QEMU data/modules/config directories (can be
empty)')
option('docdir', type : 'string', value : 'doc',
description: 'Base directory for documentation installation (can be
empty)')
+option('shared-lib', type : 'boolean', value : false,
+ description: 'build QEMU as a shared library')
option('gettext', type : 'boolean', value : true,
description: 'Localization of the GTK+ user interface')
--
2.24.3 (Apple Git-128)
- [PATCH 05/10] slirp: update for iOS resolv fix, (continued)
[PATCH 07/10] tcg: implement bulletproof JIT, Joelle van Dyne, 2020/10/12
[PATCH 01/10] configure: option to disable host block devices, Joelle van Dyne, 2020/10/12
[PATCH 04/10] meson: option to build as shared library,
Joelle van Dyne <=
- Re: [PATCH 04/10] meson: option to build as shared library, Daniel P . Berrangé, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, BALATON Zoltan, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, Daniel P . Berrangé, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, Joelle van Dyne, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, Daniel P . Berrangé, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, BALATON Zoltan, 2020/10/13
- Re: [PATCH 04/10] meson: option to build as shared library, Joelle van Dyne, 2020/10/14
Re: [PATCH 04/10] meson: option to build as shared library, BALATON Zoltan, 2020/10/13
[PATCH 10/10] block: check availablity for preadv/pwritev on mac, Joelle van Dyne, 2020/10/12
Re: [PATCH 00/10] iOS and Apple Silicon host support, no-reply, 2020/10/12