[PATCH v2] disas: recognize either <capstone.h> or <capstone/capstone.h>

Michael Tokarev posted 1 patch 1 year, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20221115115552.77242-1-mjt@msgid.tls.msk.ru
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
include/disas/capstone.h |  5 +++++
meson.build              | 21 +++++++++++----------
2 files changed, 16 insertions(+), 10 deletions(-)
[PATCH v2] disas: recognize either <capstone.h> or <capstone/capstone.h>
Posted by Michael Tokarev 1 year, 5 months ago
Historically, capstone varies in requiring either <capstone.h>
or <capstone/capstone.h> include depending on version and the
way how it has been installed.  This has already been an issue
before, and will likely become an issue again with capstone
5.0 which seem to have changed this aspect once again.

Recognize both ways in the meson check, but prefer <capstone.h>
so it's easy to override which capstone to use by
pkgconfig's --cflags (or --extra-cflags).

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
v2: use cc.has_header, not cc.compile (pm215)

 include/disas/capstone.h |  5 +++++
 meson.build              | 21 +++++++++++----------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/include/disas/capstone.h b/include/disas/capstone.h
index e29068dd97..406132a63c 100644
--- a/include/disas/capstone.h
+++ b/include/disas/capstone.h
@@ -3,7 +3,12 @@
 
 #ifdef CONFIG_CAPSTONE
 
+#ifdef HAVE_CAPSTONE_CAPSTONE_H
+#include <capstone/capstone.h>
+#else
 #include <capstone.h>
+#endif
+
 
 #else
 
diff --git a/meson.build b/meson.build
index cf3e517e56..65cb53d1cf 100644
--- a/meson.build
+++ b/meson.build
@@ -2680,16 +2680,17 @@ if not get_option('capstone').auto() or have_system or have_user
   capstone = dependency('capstone', version: '>=3.0.5',
                         kwargs: static_kwargs, method: 'pkg-config',
                         required: get_option('capstone'))
-
-  # Some versions of capstone have broken pkg-config file
-  # that reports a wrong -I path, causing the #include to
-  # fail later. If the system has such a broken version
-  # do not use it.
-  if capstone.found() and not cc.compiles('#include <capstone.h>',
-                                          dependencies: [capstone])
-    capstone = not_found
-    if get_option('capstone').enabled()
-      error('capstone requested, but it does not appear to work')
+  if capstone.found()
+    # capstone works either with <capstone.h> or <capstone/capstone.h>
+    if cc.has_header('capstone.h', dependencies: [capstone])
+      # nothing to be done here (see include/disas/capstone.h)
+    elif cc.has_header('capstone/capstone.h', dependencies: [capstone])
+      config_host_data.set('HAVE_CAPSTONE_CAPSTONE_H')
+    else
+      capstone = not_found
+      if get_option('capstone').enabled()
+        error('capstone requested, but it does not appear to work')
+      endif
     endif
   endif
 endif
-- 
2.30.2
Re: [PATCH v2] disas: recognize either <capstone.h> or <capstone/capstone.h>
Posted by Michael Tokarev 1 year, 5 months ago
15.11.2022 14:55, Michael Tokarev wrote:

> +    elif cc.has_header('capstone/capstone.h', dependencies: [capstone])
> +      config_host_data.set('HAVE_CAPSTONE_CAPSTONE_H')

This needs to be
         config_host_data.set('HAVE_CAPSTONE_CAPSTONE_H', 1)

It either can be fixed at apply time or I resend a v3.

(threading was messed up too due to our mailserver munging message-id).

/mjt
Re: [PATCH v2] disas: recognize either <capstone.h> or <capstone/capstone.h>
Posted by Richard Henderson 1 year, 5 months ago
On 11/15/22 21:55, Michael Tokarev wrote:
> Historically, capstone varies in requiring either <capstone.h>
> or <capstone/capstone.h> include depending on version and the
> way how it has been installed.  This has already been an issue
> before, and will likely become an issue again with capstone
> 5.0 which seem to have changed this aspect once again.
> 
> Recognize both ways in the meson check, but prefer <capstone.h>
> so it's easy to override which capstone to use by
> pkgconfig's --cflags (or --extra-cflags).
> 
> Signed-off-by: Michael Tokarev<mjt@tls.msk.ru>
> ---
> v2: use cc.has_header, not cc.compile (pm215)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Re: [PATCH v2] disas: recognize either <capstone.h> or <capstone/capstone.h>
Posted by Peter Maydell 1 year, 5 months ago
On Tue, 15 Nov 2022 at 11:55, Michael Tokarev <mjt@tls.msk.ru> wrote:
>
> Historically, capstone varies in requiring either <capstone.h>
> or <capstone/capstone.h> include depending on version and the
> way how it has been installed.  This has already been an issue
> before, and will likely become an issue again with capstone
> 5.0 which seem to have changed this aspect once again.
>
> Recognize both ways in the meson check, but prefer <capstone.h>
> so it's easy to override which capstone to use by
> pkgconfig's --cflags (or --extra-cflags).
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> v2: use cc.has_header, not cc.compile (pm215)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM