aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2021-10-07 15:08:29 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2021-10-14 09:51:06 +0200
commit3b4da13293482134b81d71be656ec76beff73a76 (patch)
treea799bf5d234cc2059f91287f527e7a52d1352f5c /docs
parent8b5fb29842fdb586485dcfc4f24a9997c07cc9de (diff)
downloadqemu-3b4da13293482134b81d71be656ec76beff73a76.zip
qemu-3b4da13293482134b81d71be656ec76beff73a76.tar.gz
qemu-3b4da13293482134b81d71be656ec76beff73a76.tar.bz2
configure: automatically parse command line for meson -D options
Right now meson_options.txt lists about 90 options. Each option needs code in configure to parse it and pass the option down to Meson as a -D command-line argument; in addition the default must be duplicated between configure and meson_options.txt. This series tries to remove the code duplication by generating the case statement for those --enable and --disable options, as well as the corresponding help text. About 80% of the options can be handled completely by the new mechanism. Eight meson options are not of the --enable/--disable kind. Six more need to be parsed in configure for various reasons documented in the patch, but they still have their help automatically generated. The advantages are: - less code in configure - parsing and help is more consistent (for example --enable-blobs was not supported) - options are described entirely in one place, meson_options.txt. This make it more attractive to use Meson options instead of hand-crafted configure options and config-host.mak A few options change name: --enable-tcmalloc and --enable-jemalloc become --enable-malloc={tcmalloc,jemalloc}; --disable-blobs becomes --disable-install-blobs; --enable-trace-backend becomes --enable-trace-backends. However, the old names are allowed for backwards compatibility. Message-Id: <20211007130829.632254-19-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/devel/build-system.rst136
1 files changed, 69 insertions, 67 deletions
diff --git a/docs/devel/build-system.rst b/docs/devel/build-system.rst
index 0f636d6..7f106d2 100644
--- a/docs/devel/build-system.rst
+++ b/docs/devel/build-system.rst
@@ -42,73 +42,21 @@ perform a build:
../configure
make
-For now, checks on the compilation environment are found in configure
-rather than meson.build, though this is expected to change. The command
-line is parsed in the configure script and, whenever needed, converted
-into the appropriate options to Meson.
-
-New checks should be added to Meson, which usually comprises the
-following tasks:
-
- - Add a Meson build option to meson_options.txt.
-
- - Add support to the command line arg parser to handle any new
- ``--enable-XXX``/``--disable-XXX`` flags required by the feature.
-
- - Add information to the help output message to report on the new
- feature flag.
-
- - Add code to perform the actual feature check.
-
- - Add code to include the feature status in ``config-host.h``
-
- - Add code to print out the feature status in the configure summary
- upon completion.
-
-
-Taking the probe for SDL2_Image as an example, we have the following pieces
-in configure::
-
- # Initial variable state
- sdl_image=auto
-
- ..snip..
-
- # Configure flag processing
- --disable-sdl-image) sdl_image=disabled
- ;;
- --enable-sdl-image) sdl_image=enabled
- ;;
-
- ..snip..
-
- # Help output feature message
- sdl-image SDL Image support for icons
-
- ..snip..
-
- # Meson invocation
- -Dsdl_image=$sdl_image
-
-In meson_options.txt::
-
- option('sdl', type : 'feature', value : 'auto',
- description: 'SDL Image support for icons')
-
-In meson.build::
-
- # Detect dependency
- sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
- method: 'pkg-config',
- kwargs: static_kwargs)
-
- # Create config-host.h (if applicable)
- config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
-
- # Summary
- summary_info += {'SDL image support': sdl_image.found()}
-
-
+The configure script automatically recognizes
+command line options for which a same-named Meson option exists;
+dashes in the command line are replaced with underscores.
+
+Many checks on the compilation environment are still found in configure
+rather than `meson.build`, but new checks should be added directly to
+`meson.build`.
+
+Patches are also welcome to move existing checks from the configure
+phase to `meson.build`. When doing so, ensure that `meson.build` does
+not use anymore the keys that you have removed from `config-host.mak`.
+Typically these will be replaced in `meson.build` by boolean variables,
+``get_option('optname')`` invocations, or `dep.found()` expressions.
+In general, the remaining checks have little or no interdependencies,
+so they can be moved one by one.
Helper functions
----------------
@@ -335,6 +283,60 @@ new target, or enabling new devices or hardware for a particular
system/userspace emulation target
+Adding checks
+-------------
+
+New checks should be added to Meson. Compiler checks can be as simple as
+the following::
+
+ config_host_data.set('HAVE_BTRFS_H', cc.has_header('linux/btrfs.h'))
+
+A more complex task such as adding a new dependency usually
+comprises the following tasks:
+
+ - Add a Meson build option to meson_options.txt.
+
+ - Add code to perform the actual feature check.
+
+ - Add code to include the feature status in `config-host.h`
+
+ - Add code to print out the feature status in the configure summary
+ upon completion.
+
+Taking the probe for SDL2_Image as an example, we have the following
+in ``meson_options.txt``::
+
+ option('sdl_image', type : 'feature', value : 'auto',
+ description: 'SDL Image support for icons')
+
+Unless the option was given a non-``auto`` value (on the configure
+command line), the detection code must be performed only if the
+dependency will be used::
+
+ sdl_image = not_found
+ if not get_option('sdl_image').auto() or have_system
+ sdl_image = dependency('SDL2_image', required: get_option('sdl_image'),
+ method: 'pkg-config',
+ static: enable_static)
+ endif
+
+This avoids warnings on static builds of user-mode emulators, for example.
+Most of the libraries used by system-mode emulators are not available for
+static linking.
+
+The other supporting code is generally simple::
+
+ # Create config-host.h (if applicable)
+ config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
+
+ # Summary
+ summary_info += {'SDL image support': sdl_image.found()}
+
+For the configure script to parse the new option, the
+``scripts/meson-buildoptions.sh`` file must be up-to-date; ``make
+update-buildoptions`` (or just `make`) will take care of updating it.
+
+
Support scripts
---------------