[PATCH] 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/20221115093803.52050-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              | 22 ++++++++++++----------
2 files changed, 17 insertions(+), 10 deletions(-)
[PATCH] 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 easily to override which capstone to use by
pkgconfig's --cflags (or --extra-cflags).

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 include/disas/capstone.h |  5 +++++
 meson.build              | 22 ++++++++++++----------
 2 files changed, 17 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..2a3ae65d76 100644
--- a/meson.build
+++ b/meson.build
@@ -2680,16 +2680,18 @@ 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>
+    # determine which one do we have here, prefer first one with pkg-config's --cflags
+    if cc.compiles('#include <capstone.h>', dependencies: [capstone])
+      # nothing to be done here (see include/disas/capstone.h)
+    elif cc.compiles('#include <capstone/capstone.h>', dependencies: [capstone])
+      config_host_data.set('HAVE_CAPSTONE_CAPSTONE_H', 1)
+    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