qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Michael Tokarev
Subject: [PATCH] disas: recognize either <capstone.h> or <capstone/capstone.h>
Date: Tue, 15 Nov 2022 12:38:03 +0300

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]