build: improve pcap dependency handling
authorLuca Boccassi <luca.boccassi@microsoft.com>
Tue, 26 Feb 2019 17:46:37 +0000 (17:46 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Fri, 1 Mar 2019 13:19:56 +0000 (14:19 +0100)
pcap has historically shipped a custom pcap-config binary tool which
does the job of pkg-config. It was never compatible with cross
compilation.
Meson uses it when using dependency(), which then means cross
compilation fails.
Set pcap-config to empty in the meson cross compilation files so
that Meson will not use it, and add a fallback in case
dependency() fails.
libpcap 1.9.0 finally ships a pkg-config file so everything will
work out of the box in the future.

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
config/arm/arm64_armv8_linuxapp_gcc
config/arm/arm64_dpaa2_linuxapp_gcc
config/arm/arm64_dpaa_linuxapp_gcc
config/arm/arm64_thunderx_linuxapp_gcc
drivers/net/pcap/meson.build

index 987c02f..5137609 100644 (file)
@@ -3,6 +3,7 @@ c = 'aarch64-linux-gnu-gcc'
 cpp = 'aarch64-linux-gnu-cpp'
 ar = 'aarch64-linux-gnu-gcc-ar'
 strip = 'aarch64-linux-gnu-strip'
+pcap-config = ''
 
 [host_machine]
 system = 'linux'
index 7ec74ec..0df8c8f 100644 (file)
@@ -4,6 +4,7 @@ cpp = 'aarch64-linux-gnu-cpp'
 ar = 'aarch64-linux-gnu-ar'
 as = 'aarch64-linux-gnu-as'
 strip = 'aarch64-linux-gnu-strip'
+pcap-config = ''
 
 [host_machine]
 system = 'linux'
index 73a8f0b..f4b85a8 100644 (file)
@@ -4,6 +4,7 @@ cpp = 'aarch64-linux-gnu-cpp'
 ar = 'aarch64-linux-gnu-ar'
 as = 'aarch64-linux-gnu-as'
 strip = 'aarch64-linux-gnu-strip'
+pcap-config = ''
 
 [host_machine]
 system = 'linux'
index 967d9d4..14b8019 100644 (file)
@@ -3,6 +3,7 @@ c = 'aarch64-linux-gnu-gcc'
 cpp = 'aarch64-linux-gnu-cpp'
 ar = 'aarch64-linux-gnu-gcc-ar'
 strip = 'aarch64-linux-gnu-strip'
+pcap-config = ''
 
 [host_machine]
 system = 'linux'
index 0c4e020..2c2fd11 100644 (file)
@@ -1,12 +1,20 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-pcap_dep = cc.find_library('pcap', required: false)
-if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+pcap_dep = dependency('pcap', required: false)
+if pcap_dep.found()
        build = true
 else
-       build = false
+       # pcap got a pkg-config file only in 1.9.0 and before that meson uses
+       # an internal pcap-config finder, which is not compatible with
+       # cross-compilation, so try to fallback to find_library
+       pcap_dep = cc.find_library('pcap', required: false)
+       if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep)
+               build = true
+               pkgconfig_extra_libs += '-lpcap'
+       else
+               build = false
+       endif
 endif
 sources = files('rte_eth_pcap.c')
 ext_deps += pcap_dep
-pkgconfig_extra_libs += '-lpcap'