From nobody Tue Feb 10 12:42:57 2026 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=1671646162; cv=none; d=zohomail.com; s=zohoarc; b=NN2W1CTBTzLK3srjivHVsqcFl0B98YCSBd/sDea8nuN9eAkcwMH7FX5YIoPGy28beVutiN5gtvFS8UvzdeOe01VkhWRkvgaKyKlk4QEuVzcisvfFWpwGCPTu8MyNSYqeolUvSKKUQWOCeIkeoJl1MYalCGqCmh6vDkiSQPOJhpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671646162; h=Content-Type:Content-Transfer-Encoding:Cc: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=82nDtmiImedDhp3vkdUqEEQgeQIdwDkdoWjDJgK0/Po=; b=kiSwwAQmOvvt5nHVuYvA/w36D/NX1KjaJzzkrZvbzd4Gun3jLjjDQCnK1MAG5d6nxqu02FkDlxQFqMFxDEDY2QInMmpWWM22dsa2JcU0FQ/utaf8P1y0vuGJRslMHSNqFUCkwJWJ3UmpX5euJ03DnJf4gM8/oAFT8juHJwcjLp8= 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 1671646162271746.5812681982243; Wed, 21 Dec 2022 10:09:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p83QP-0001D3-BQ; Wed, 21 Dec 2022 13:02:44 -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 1p83QJ-0001CN-Ez for qemu-devel@nongnu.org; Wed, 21 Dec 2022 13:02:35 -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 1p83QH-0004LW-IR for qemu-devel@nongnu.org; Wed, 21 Dec 2022 13:02:35 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-655-vGcvpPpbNbujURzwccR0mQ-1; Wed, 21 Dec 2022 13:02:31 -0500 Received: by mail-ej1-f70.google.com with SMTP id jg25-20020a170907971900b007c0e98ad898so11106052ejc.15 for ; Wed, 21 Dec 2022 10:02:31 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id rs13-20020a170907036d00b0077a1dd3e7b7sm7410423ejb.102.2022.12.21.10.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 10:02:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671645753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=82nDtmiImedDhp3vkdUqEEQgeQIdwDkdoWjDJgK0/Po=; b=GOXoYAlBPvz/26yzMEP6eUZBr/3Ue5UcxWKXlwD4bFX9ygWNlGW5pUQ9uWxwrWoPvYZWR6 ZGwfcUyFt9Jm/kWcGfhhMg64wm4JOJ8mcm5ykqkjVh/kq1yuW0gL1fituZQW1pmI1HCNxm Y6vwFl1gqIpCWgQL9fVVYhLLIPd63OQ= X-MC-Unique: vGcvpPpbNbujURzwccR0mQ-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:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=82nDtmiImedDhp3vkdUqEEQgeQIdwDkdoWjDJgK0/Po=; b=XJG3+ct/u1VsxtHT+6D0GkJCL4ct73s9UNPt9s9DyLsZ7IZMf3W75+ZxU6LjJCZ6nE nCAqdEnpWHWLapJsWZYMKFkZ9XSBfrckIgUmXVTXN+Zj0HPRRDrIF6eT5wT5XvYRwMPo 9M8moZM5UiXeyisGa5HBM6F7VR4HGUdkYi44qGFduNiF6r2KclbJbMIRsiofR2hZs/7D aYtodNQzIoWP3iYq1DVWlyibp6lMUgkTTc3f67ZVTF0xMbVW+emKxELSB/hdXvbr5tbM 21BQDPeqUCM7yA7iVsianiZ9YUg0VwuDSXPJRO+IIgmm/EM8FBMuCQrYm5rSilMLrJML 3+Wg== X-Gm-Message-State: AFqh2krjeb17wrscbMeVYcZocuuolkjA4lfjALLhSXgzAqSjYRKpHAuW 4lar7TDyY2tySRa+OybrUxN7tUbZQmgEX8Oto4Bf1qRX29alYnVCMA7ervoyWDXX0lpnmqG5XuL au6Jb09ZcGhnho1ezTdF0mrPpiradZ2Oo83QdNrkbRY6JnN2Wdy2jqNUblQcFGvoCCws= X-Received: by 2002:a05:6402:1298:b0:461:75f1:9254 with SMTP id w24-20020a056402129800b0046175f19254mr2442585edv.2.1671645749888; Wed, 21 Dec 2022 10:02:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFBFaiqqKzulTgBrEfTvafb/vT5xbCd2liNi5GulqCFWX950bX0kuB1zBY9NqEXV8Q+FHvcg== X-Received: by 2002:a05:6402:1298:b0:461:75f1:9254 with SMTP id w24-20020a056402129800b0046175f19254mr2442563edv.2.1671645749575; Wed, 21 Dec 2022 10:02:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PULL 17/24] meson: cleanup compiler detection Date: Wed, 21 Dec 2022 19:01:34 +0100 Message-Id: <20221221180141.839616-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221180141.839616-1-pbonzini@redhat.com> References: <20221221180141.839616-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Type: text/plain 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, PP_MIME_FAKE_ASCII_TEXT=0.001, 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: 1671646163966100003 Detect all compilers at the beginning of meson.build, and store the available languages in an array. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Paolo Bonzini --- meson.build | 62 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/meson.build b/meson.build index dbd0b5563446..81920844448d 100644 --- a/meson.build +++ b/meson.build @@ -14,8 +14,8 @@ keyval =3D import('keyval') ss =3D import('sourceset') fs =3D import('fs') =20 +targetos =3D host_machine.system() sh =3D find_program('sh') -cc =3D meson.get_compiler('c') config_host =3D keyval.load(meson.current_build_dir() / 'config-host.mak') enable_modules =3D 'CONFIG_MODULES' in config_host enable_static =3D 'CONFIG_STATIC' in config_host @@ -23,6 +23,18 @@ enable_static =3D 'CONFIG_STATIC' in config_host # Allow both shared and static libraries unless --enable-static static_kwargs =3D enable_static ? {'static': true} : {} =20 +cc =3D meson.get_compiler('c') +all_languages =3D ['c'] +if add_languages('cpp', required: false, native: false) + all_languages +=3D ['cpp'] + cxx =3D meson.get_compiler('cpp') +endif +if targetos =3D=3D 'darwin' and \ + add_languages('objc', required: get_option('cocoa'), native: false) + all_languages +=3D ['objc'] + objc =3D meson.get_compiler('objc') +endif + # Temporary directory used for files created while # configure runs. Since it is in the build directory # we can safely blow away any previous version of it @@ -58,8 +70,6 @@ if cpu in ['riscv32', 'riscv64'] cpu =3D 'riscv' endif =20 -targetos =3D host_machine.system() - target_dirs =3D config_host['TARGET_DIRS'].split() have_linux_user =3D false have_bsd_user =3D false @@ -165,7 +175,7 @@ if 'dtrace' in get_option('trace_backends') # semaphores are linked into the main binary and not the module's shar= ed # object. add_global_arguments('-DSTAP_SDT_V2', - native: false, language: ['c', 'cpp', 'objc']) + native: false, language: all_languages) endif endif =20 @@ -207,7 +217,7 @@ endif if get_option('fuzzing') add_project_link_arguments(['-Wl,-T,', (meson.current_source_dir() / 'tests/qtest/f= uzz/fork_fuzz.ld')], - native: false, language: ['c', 'cpp', 'objc']) + native: false, language: all_languages) =20 # Specify a filter to only instrument code that is directly related to # virtual-devices. @@ -220,7 +230,7 @@ if get_option('fuzzing') args: ['-fsanitize-coverage-allowlist=3D/dev/null', '-fsanitize-coverage=3Dtrace-pc'] ) add_global_arguments('-fsanitize-coverage-allowlist=3Dinstrumentation-= filter', - native: false, language: ['c', 'cpp', 'objc']) + native: false, language: all_languages) endif =20 if get_option('fuzzing_engine') =3D=3D '' @@ -229,9 +239,9 @@ if get_option('fuzzing') # everything with fsanitize=3Dfuzzer-no-link. Otherwise, the linker wi= ll be # unable to bind the fuzzer-related callbacks added by instrumentation. add_global_arguments('-fsanitize=3Dfuzzer-no-link', - native: false, language: ['c', 'cpp', 'objc']) + native: false, language: all_languages) add_global_link_arguments('-fsanitize=3Dfuzzer-no-link', - native: false, language: ['c', 'cpp', 'objc'= ]) + native: false, language: all_languages) # For the actual fuzzer binaries, we need to link against the libfuzzer # library. They need to be configurable, to support OSS-Fuzz fuzz_exe_ldflags =3D ['-fsanitize=3Dfuzzer'] @@ -242,15 +252,11 @@ if get_option('fuzzing') endif endif =20 -add_global_arguments(qemu_cflags, native: false, language: ['c']) -add_global_arguments(qemu_objcflags, native: false, language: ['objc']) - # Check that the C++ compiler exists and works with the C compiler. link_language =3D 'c' linker =3D cc qemu_cxxflags =3D [] -if add_languages('cpp', required: false, native: false) - cxx =3D meson.get_compiler('cpp') +if 'cpp' in all_languages add_global_arguments(['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS= ', '-D__STDC_FORMAT_MACROS'], native: false, language: 'cpp') foreach k: qemu_cflags @@ -259,7 +265,6 @@ if add_languages('cpp', required: false, native: false) qemu_cxxflags +=3D [k] endif endforeach - add_global_arguments(qemu_cxxflags, native: false, language: 'cpp') =20 if cxx.links(files('scripts/main.c'), args: qemu_cflags) link_language =3D 'cpp' @@ -275,22 +280,21 @@ if targetos !=3D 'sunos' and not config_host.has_key(= 'CONFIG_TSAN') qemu_ldflags +=3D linker.get_supported_link_arguments('-Wl,--warn-common= ') endif =20 -add_global_link_arguments(qemu_ldflags, native: false, language: ['c', 'cp= p', 'objc']) +add_global_link_arguments(qemu_ldflags, native: false, language: all_langu= ages) =20 +add_global_arguments(qemu_cflags, native: false, language: 'c') +add_global_arguments(qemu_cxxflags, native: false, language: 'cpp') +add_global_arguments(qemu_objcflags, native: false, language: 'objc') if targetos =3D=3D 'linux' add_project_arguments('-isystem', meson.current_source_dir() / 'linux-he= aders', '-isystem', 'linux-headers', - language: ['c', 'cpp']) + language: all_languages) endif =20 add_project_arguments('-iquote', '.', '-iquote', meson.current_source_dir(), '-iquote', meson.current_source_dir() / 'include', - language: ['c', 'cpp', 'objc']) - -if host_machine.system() =3D=3D 'darwin' - add_languages('objc', required: false, native: false) -endif + language: all_languages) =20 sparse =3D find_program('cgcc', required: get_option('sparse')) if sparse.found() @@ -472,7 +476,7 @@ if get_option('tcg').allowed() tcg_arch =3D 'ppc' endif add_project_arguments('-iquote', meson.current_source_dir() / 'tcg' / tc= g_arch, - language: ['c', 'cpp', 'objc']) + language: all_languages) =20 accelerators +=3D 'CONFIG_TCG' config_host +=3D { 'CONFIG_TCG': 'y' } @@ -498,7 +502,7 @@ endif # 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: ['c', 'cpp', 'objc']) + 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'], @@ -1723,8 +1727,8 @@ if get_option('cfi') error('-fno-sanitize-trap=3Dcfi-icall is not supported by the compil= er') endif endif - add_global_arguments(cfi_flags, native: false, language: ['c', 'cpp', 'o= bjc']) - add_global_link_arguments(cfi_flags, native: false, language: ['c', 'cpp= ', 'objc']) + add_global_arguments(cfi_flags, native: false, language: all_languages) + add_global_link_arguments(cfi_flags, native: false, language: all_langua= ges) endif =20 have_host_block_device =3D (targetos !=3D 'darwin' or @@ -3768,8 +3772,12 @@ if link_args.length() > 0 summary_info +=3D {'LDFLAGS': ' '.join(link_args)} endif summary_info +=3D {'QEMU_CFLAGS': ' '.join(qemu_cflags)} -summary_info +=3D {'QEMU_CXXFLAGS': ' '.join(qemu_cxxflags)} -summary_info +=3D {'QEMU_OBJCFLAGS': ' '.join(qemu_objcflags)} +if 'cpp' in all_languages + summary_info +=3D {'QEMU_CXXFLAGS': ' '.join(qemu_cxxflags)} +endif +if 'objc' in all_languages + summary_info +=3D {'QEMU_OBJCFLAGS': ' '.join(qemu_objcflags)} +endif summary_info +=3D {'QEMU_LDFLAGS': ' '.join(qemu_ldflags)} summary_info +=3D {'profiler': get_option('profiler')} summary_info +=3D {'link-time optimization (LTO)': get_option('b_lto')} --=20 2.38.1