diff mbox series

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

Message ID 20221122074559.848913-1-mjt@msgid.tls.msk.ru
State New
Headers show
Series [v3] disas: recognize either <capstone.h> or <capstone/capstone.h> | expand

Commit Message

Michael Tokarev Nov. 22, 2022, 7:45 a.m. UTC
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>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
v2: use cc.has_header, not cc.compile (pm215)
v3: fix the forgotten arg for config_host_data.set
 (comitted locally but not included in previous format-patch)

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

Comments

Daniel P. Berrangé Nov. 22, 2022, 8:16 a.m. UTC | #1
On Tue, Nov 22, 2022 at 10:45:59AM +0300, 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>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> v2: use cc.has_header, not cc.compile (pm215)
> v3: fix the forgotten arg for config_host_data.set
>  (comitted locally but not included in previous format-patch)
> 
>  include/disas/capstone.h |  5 +++++
>  meson.build              | 21 +++++++++++----------
>  2 files changed, 16 insertions(+), 10 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
diff mbox series

Patch

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..b97e9e1195 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', 1)
+    else
+      capstone = not_found
+      if get_option('capstone').enabled()
+        error('capstone requested, but it does not appear to work')
+      endif
     endif
   endif
 endif