From nobody Fri Dec 19 18:43:44 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1670586201; cv=none; d=zohomail.com; s=zohoarc; b=M+sPpXJl3h+xK+ZAE5P6q4J45JqO3SFnBEBbeGAuM3HAVCnIi7al3VlCpnqDaHLwyNMJUIfNpmzkES8wmcLfoqARPJZc2s/fzHz6C4ppEfnsxupblRbOh4aqxAgIFpo9X3fetmxtHqY8mQW30TYFx/x2elUzlSD3s0YOMP/P/FA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670586201; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NQVG1qMxVxADoLqdsGTmmP6GVi8GQAzTiysq17FwIyI=; b=NacFd2gh9rkr61ehDv0qduSUL/XrkGgblILe3u1+52063NscWzjKTr8O2yj1rfKKxFB3KL7qmrg7EquZvmlEOvWguAV21VOJIKVURJVW9a5kRm62NtOQBSb8NMhQ+0nkQLATVvOn6iwOTF9aX4MGHOHzv5bl1Xyp6lD56abU1XQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1670586201206931.3078557531665; Fri, 9 Dec 2022 03:43:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p3bW8-0004ny-UI; Fri, 09 Dec 2022 06:26:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3bV7-00045i-ES for qemu-devel@nongnu.org; Fri, 09 Dec 2022 06:25:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p3bUz-00011i-JB for qemu-devel@nongnu.org; Fri, 09 Dec 2022 06:25:04 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-115-ypmJzCcIO2GoELsflSt59g-1; Fri, 09 Dec 2022 06:24:58 -0500 Received: by mail-ej1-f69.google.com with SMTP id sh37-20020a1709076ea500b007c09b177cd1so2910655ejc.12 for ; Fri, 09 Dec 2022 03:24:57 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:1c09:f536:3de6:228c]) by smtp.gmail.com with ESMTPSA id fe17-20020a1709072a5100b007be301a1d51sm437578ejc.211.2022.12.09.03.24.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 03:24:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670585099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NQVG1qMxVxADoLqdsGTmmP6GVi8GQAzTiysq17FwIyI=; b=fOE3hdR31OYS6AiwOXdyrUrB0bp1g1vuNfZqkxA44XjBcP51CV1SpgVfz7L9wSQkDg9fgD QN/+kLTEf35uzhJ6k7CwqjicR6KLZR88ZKljIspodCr6Twvq9Ce5UbJHgMR8ISm6oplBNM 7/zf0IEqkgxMR25TRgLw8RABmvH9zRo= X-MC-Unique: ypmJzCcIO2GoELsflSt59g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NQVG1qMxVxADoLqdsGTmmP6GVi8GQAzTiysq17FwIyI=; b=4cqC5yUQcD89tDktg1E++KgFc5NRa5tBsQ+Ax21L5zzlgnGR4+c2wwRjIUac6yH2Gj wjPX8r7lKYGmpXYAdlVPSH2pDemhjogbn3f+5F7J3lNlNyMSEZfjazaHIJt4vyds1tDS WFWd308aqkikZpcaRzxx9vRjk/Pn3yzIprFrtugq8P5LoJCosCSJVbZKUHfPLEtUfLWa ap8HbBU8dq7K+fDdUtKOkztq2VXds71vUAwah1T98kXo6b/zJjGpu/JxPM5Zq2+oKYkb Kq+zUNV5+LhPk9MGkgpD5tAPVm7wA8BPow5W9qk4Zyms342i9kC1GOJ72yLUXr7n/XXm 79Dw== X-Gm-Message-State: ANoB5pkvdkDq9xt4xoaGRLIbW84A1oZsyJFM5mUio8cJ1BAxtCffJfc6 1JLO8sChpZPUwmPx9W/Y9Gk1R+f9M3JlIcbPwukW8lgUwtocChhGQQq8ws0Wh2fm6G3EDWwp8EA V+YTFfK39pvWexUY8v55ILVgznEcysIo9hHO+w5w1GWbcocBpKzEkvSLVcRlU2Yw+CkE= X-Received: by 2002:a17:906:8ce:b0:7ad:dd10:c614 with SMTP id o14-20020a17090608ce00b007addd10c614mr4339446eje.44.1670585096552; Fri, 09 Dec 2022 03:24:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf50sxpyGC6+oVsCT0pLbfQC1k6FRolEU14ic9/ZXEPaQpxUFhDcg1u1acisGZfZ4NMP2PaljQ== X-Received: by 2002:a17:906:8ce:b0:7ad:dd10:c614 with SMTP id o14-20020a17090608ce00b007addd10c614mr4339429eje.44.1670585096105; Fri, 09 Dec 2022 03:24:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 16/30] build: move glib detection and workarounds to meson Date: Fri, 9 Dec 2022 12:23:55 +0100 Message-Id: <20221209112409.184703-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221209112409.184703-1-pbonzini@redhat.com> References: <20221209112409.184703-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1670586203016100003 Content-Type: text/plain; charset="utf-8" QEMU adds the path to glib.h is added to all compilation commands. This is simpler due to the pervasive use of static_library, and was grandfathered in from the previous Make-based build system. Until Meson 0.63 the only way to do this was to detect glib in configure and use add_project_arguments, but now it is possible to use add_project_dependencies instead. gmodule is detected in a separate variable and added via both block_ss (for --enable-modules) and plugins/meson.build (for --enable-plugins). Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/meson.build | 1 + configure | 83 +--------------------------------------- contrib/plugins/Makefile | 4 +- meson.build | 81 +++++++++++++++++++++++++++++++++------ plugins/meson.build | 2 +- 5 files changed, 74 insertions(+), 97 deletions(-) diff --git a/block/meson.build b/block/meson.build index b7c68b83a36f..f2e0e86f3b0a 100644 --- a/block/meson.build +++ b/block/meson.build @@ -145,6 +145,7 @@ block_gen_c =3D custom_target('block-gen.c', block_ss.add(block_gen_c) =20 block_ss.add(files('stream.c')) +block_ss.add(gmodule) =20 softmmu_ss.add(files('qapi-sysemu.c')) =20 diff --git a/configure b/configure index 9c5393a25de7..fb28dd3963bd 100755 --- a/configure +++ b/configure @@ -1426,84 +1426,6 @@ if ! has "$pkg_config_exe"; then error_exit "pkg-config binary '$pkg_config_exe' not found" fi =20 -########################################## -# glib support probe - -# When bumping glib_req_ver, please check also whether we should increase -# the _WIN32_WINNT setting in osdep.h according to the value from glib -glib_req_ver=3D2.56 -glib_modules=3Dgthread-2.0 -if test "$modules" =3D yes; then - glib_modules=3D"$glib_modules gmodule-export-2.0" -elif test "$plugins" =3D "yes"; then - glib_modules=3D"$glib_modules gmodule-no-export-2.0" -fi - -for i in $glib_modules; do - if $pkg_config --atleast-version=3D$glib_req_ver $i; then - glib_cflags=3D$($pkg_config --cflags $i) - glib_libs=3D$($pkg_config --libs $i) - else - error_exit "glib-$glib_req_ver $i is required to compile QEMU" - fi -done - -glib_bindir=3D"$($pkg_config --variable=3Dbindir glib-2.0)" -if test -z "$glib_bindir" ; then - glib_bindir=3D"$($pkg_config --variable=3Dprefix glib-2.0)"/bin -fi - -# This workaround is required due to a bug in pkg-config file for glib as = it -# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static - -if test "$static" =3D yes && test "$mingw32" =3D yes; then - glib_cflags=3D"-DGLIB_STATIC_COMPILATION $glib_cflags" -fi - -# Sanity check that the current size_t matches the -# size that glib thinks it should be. This catches -# problems on multi-arch where people try to build -# 32-bit QEMU while pointing at 64-bit glib headers -cat > $TMPC < -#include - -#define QEMU_BUILD_BUG_ON(x) \ - typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused)); - -int main(void) { - QEMU_BUILD_BUG_ON(sizeof(size_t) !=3D GLIB_SIZEOF_SIZE_T); - return 0; -} -EOF - -if ! compile_prog "$glib_cflags" "$glib_libs" ; then - error_exit "sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T."\ - "You probably need to set PKG_CONFIG_LIBDIR"\ - "to point to the right pkg-config files for your"\ - "build target" -fi - -# Silence clang warnings triggered by glib < 2.57.2 -cat > $TMPC << EOF -#include -typedef struct Foo { - int i; -} Foo; -static void foo_free(Foo *f) -{ - g_free(f); -} -G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free) -int main(void) { return 0; } -EOF -if ! compile_prog "$glib_cflags -Werror" "$glib_libs" ; then - if cc_has_warning_flag "-Wno-unused-function"; then - glib_cflags=3D"$glib_cflags -Wno-unused-function" - CONFIGURE_CFLAGS=3D"$CONFIGURE_CFLAGS -Wno-unused-function" - fi -fi - ########################################## # fdt probe =20 @@ -2361,13 +2283,10 @@ echo "PYTHON=3D$python" >> $config_host_mak echo "GENISOIMAGE=3D$genisoimage" >> $config_host_mak echo "MESON=3D$meson" >> $config_host_mak echo "NINJA=3D$ninja" >> $config_host_mak +echo "PKG_CONFIG=3D${pkg_config_exe}" >> $config_host_mak echo "CC=3D$cc" >> $config_host_mak echo "QEMU_CFLAGS=3D$QEMU_CFLAGS" >> $config_host_mak echo "QEMU_OBJCFLAGS=3D$QEMU_OBJCFLAGS" >> $config_host_mak -echo "GLIB_CFLAGS=3D$glib_cflags" >> $config_host_mak -echo "GLIB_LIBS=3D$glib_libs" >> $config_host_mak -echo "GLIB_BINDIR=3D$glib_bindir" >> $config_host_mak -echo "GLIB_VERSION=3D$(pkg-config --modversion glib-2.0)" >> $config_host_= mak echo "QEMU_LDFLAGS=3D$QEMU_LDFLAGS" >> $config_host_mak echo "EXESUF=3D$EXESUF" >> $config_host_mak =20 diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 23e0396687e8..8a316cd76f2f 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -3,7 +3,7 @@ # This Makefile example is fairly independent from the main makefile # so users can take and adapt it for their build. We only really # include config-host.mak so we don't have to repeat probing for -# cflags that the main configure has already done for us. +# programs that the main configure has already done for us. # =20 BUILD_DIR :=3D $(CURDIR)/../.. @@ -26,7 +26,7 @@ SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 # The main QEMU uses Glib extensively so it's perfectly fine to use it # in plugins (which many example do). -CFLAGS =3D $(GLIB_CFLAGS) +CFLAGS :=3D $(shell $(PKG_CONFIG) --cflags glib-2.0) CFLAGS +=3D -fPIC -Wall $(filter -W%, $(QEMU_CFLAGS)) CFLAGS +=3D $(if $(findstring no-psabi,$(QEMU_CFLAGS)),-Wpsabi) CFLAGS +=3D $(if $(CONFIG_DEBUG_TCG), -ggdb -O0) diff --git a/meson.build b/meson.build index c4fa82ae8ba4..f63ab7f83bed 100644 --- a/meson.build +++ b/meson.build @@ -495,19 +495,77 @@ endif # Dependencies # ################ =20 -# The path to glib.h is added to all compilation commands. This was -# grandfathered in from the QEMU Makefiles. -add_project_arguments(config_host['GLIB_CFLAGS'].split(), - native: false, language: all_languages) -glib =3D declare_dependency(compile_args: config_host['GLIB_CFLAGS'].split= (), - link_args: config_host['GLIB_LIBS'].split(), - version: config_host['GLIB_VERSION'], +# When bumping glib minimum version, please check also whether to increase +# the _WIN32_WINNT setting in osdep.h according to the value from glib +glib_req_ver =3D '>=3D2.56.0' +glib =3D dependency('glib-2.0', version: glib_req_ver, required: true, + method: 'pkg-config') +glib_cflags =3D [] +if config_host.has_key('CONFIG_MODULES') + gmodule =3D dependency('gmodule-export-2.0', version: glib_req_ver, requ= ired: true, + method: 'pkg-config') +elif config_host.has_key('CONFIG_PLUGIN') + gmodule =3D dependency('gmodule-no-export-2.0', version: glib_req_ver, r= equired: true, + method: 'pkg-config') +else + gmodule =3D not_found +endif + +# This workaround is required due to a bug in pkg-config file for glib as = it +# doesn't define GLIB_STATIC_COMPILATION for pkg-config --static +if targetos =3D=3D 'windows' and get_option('prefer_static') + glib_cflags +=3D ['-DGLIB_STATIC_COMPILATION'] +endif + +# Sanity check that the current size_t matches the +# size that glib thinks it should be. This catches +# problems on multi-arch where people try to build +# 32-bit QEMU while pointing at 64-bit glib headers + +if not cc.compiles(''' + #include + #include + + #define QEMU_BUILD_BUG_ON(x) \ + typedef char qemu_build_bug_on[(x)?-1:1] __attribute__((unused)); + + int main(void) { + QEMU_BUILD_BUG_ON(sizeof(size_t) !=3D GLIB_SIZEOF_SIZE_T); + return 0; + }''', dependencies: glib, args: glib_cflags) + error('''sizeof(size_t) doesn't match GLIB_SIZEOF_SIZE_T. + You probably need to set PKG_CONFIG_LIBDIR" to point + to the right pkg-config files for your build target.''') +endif + +# Silence clang warnings triggered by glib < 2.57.2 +if not cc.compiles(''' + #include + typedef struct Foo { + int i; + } Foo; + static void foo_free(Foo *f) + { + g_free(f); + } + G_DEFINE_AUTOPTR_CLEANUP_FUNC(Foo, foo_free) + int main(void) { return 0; }''', dependencies: glib, args: ['-Werror']) + glib_cflags +=3D cc.get_supported_arguments('-Wno-unused-function') +endif +glib =3D declare_dependency(dependencies: glib, + compile_args: glib_cflags, + version: glib.version(), variables: { - 'bindir': config_host['GLIB_BINDIR'], + 'bindir': glib.get_variable('bindir') }) -# override glib dep with the configure results (for subprojects) + +# override glib dep to include the above refinements meson.override_dependency('glib-2.0', glib) =20 +# The path to glib.h is added to all compilation commands. +add_project_dependencies(glib.partial_dependency(compile_args: true, inclu= des: true), + native: false, language: all_languages) + gio =3D not_found gdbus_codegen =3D not_found gdbus_codegen_error =3D '@0@ requires gdbus-codegen, please install libgio' @@ -923,7 +981,7 @@ if have_system and get_option('curses').allowed() int main(void) { iconv_t conv =3D iconv_open("WCHAR_T", "UCS-2"); return conv !=3D (iconv_t) -1; - }''', args: config_host['GLIB_CFLAGS'].split() + config_host['GLIB= _LIBS'].split() + link_args) + }''', args: link_args, dependencies: glib) iconv =3D declare_dependency(link_args: link_args, dependencies: g= lib) break endif @@ -2977,7 +3035,6 @@ subdir('ui') subdir('hw') subdir('gdbstub') =20 - if enable_modules libmodulecommon =3D static_library('module-common', files('module-common= .c') + genh, pic: true, c_args: '-DBUILD_DSO') modulecommon =3D declare_dependency(link_whole: libmodulecommon, compile= _args: '-DBUILD_DSO') @@ -3590,7 +3647,7 @@ if host_machine.system() =3D=3D 'windows' '@OUTPUT@', get_option('prefix'), meson.current_source_dir(), - config_host['GLIB_BINDIR'], + glib.get_variable('bindir'), host_machine.cpu(), '--', '-DDISPLAYVERSION=3D' + meson.project_version(), diff --git a/plugins/meson.build b/plugins/meson.build index 752377c66d32..04cb7d252aab 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -17,4 +17,4 @@ specific_ss.add(when: 'CONFIG_PLUGIN', if_true: [files( 'loader.c', 'core.c', 'api.c', -), declare_dependency(link_args: plugin_ldflags)]) +), gmodule, declare_dependency(link_args: plugin_ldflags)]) --=20 2.38.1