Merge pull request #2130 from bruce-richardson/pcap_config_support

add support for pcap dependencies
pull/2185/head
Jussi Pakkanen 7 years ago committed by GitHub
commit 8c8e9230a5
  1. 3
      mesonbuild/dependencies/__init__.py
  2. 2
      mesonbuild/dependencies/base.py
  3. 49
      mesonbuild/dependencies/misc.py
  4. 7
      test cases/frameworks/19 pcap/meson.build
  5. 9
      test cases/frameworks/19 pcap/pcap_prog.c

@ -17,7 +17,7 @@ from .base import ( # noqa: F401
ExternalDependency, ExternalLibrary, ExtraFrameworkDependency, InternalDependency,
PkgConfigDependency, find_external_dependency, get_dep_identifier, packages, _packages_accept_language)
from .dev import GMockDependency, GTestDependency, LLVMDependency, ValgrindDependency
from .misc import (BoostDependency, MPIDependency, Python3Dependency, ThreadDependency)
from .misc import (BoostDependency, MPIDependency, Python3Dependency, ThreadDependency, PcapDependency)
from .platform import AppleFrameworks
from .ui import GLDependency, GnuStepDependency, Qt4Dependency, Qt5Dependency, SDL2Dependency, WxDependency, VulkanDependency
@ -34,6 +34,7 @@ packages.update({
'mpi': MPIDependency,
'python3': Python3Dependency,
'threads': ThreadDependency,
'pcap': PcapDependency,
# From platform:
'appleframeworks': AppleFrameworks,

@ -44,6 +44,8 @@ class DependencyMethods(Enum):
SYSTEM = 'system'
# Detect using sdl2-config
SDLCONFIG = 'sdlconfig'
# Detect using pcap-config
PCAPCONFIG = 'pcap-config'
# This is only supported on OSX - search the frameworks directory by name.
EXTRAFRAMEWORK = 'extraframework'
# Detect using the sysconfig module.

@ -19,10 +19,12 @@ import os
import re
import shlex
import stat
import shutil
import sysconfig
from .. import mlog
from .. import mesonlib
from ..mesonlib import Popen_safe
from ..environment import detect_cpu_family
from .base import DependencyException, DependencyMethods
@ -574,3 +576,50 @@ class Python3Dependency(ExternalDependency):
return [DependencyMethods.PKGCONFIG, DependencyMethods.EXTRAFRAMEWORK]
else:
return [DependencyMethods.PKGCONFIG]
class PcapDependency(ExternalDependency):
def __init__(self, environment, kwargs):
super().__init__('pcap', environment, None, kwargs)
if DependencyMethods.PKGCONFIG in self.methods:
try:
kwargs['required'] = False
pcdep = PkgConfigDependency('pcap', environment, kwargs)
if pcdep.found():
self.type_name = 'pkgconfig'
self.is_found = True
self.compile_args = pcdep.get_compile_args()
self.link_args = pcdep.get_link_args()
self.version = pcdep.get_version()
return
except Exception as e:
mlog.debug('Pcap not found via pkgconfig. Trying next, error was:', str(e))
if DependencyMethods.PCAPCONFIG in self.methods:
pcapconf = shutil.which('pcap-config')
if pcapconf:
stdo = Popen_safe(['pcap-config', '--cflags'])[1]
self.compile_args = stdo.strip().split()
stdo = Popen_safe(['pcap-config', '--libs'])[1]
self.link_args = stdo.strip().split()
self.version = '0'
self.is_found = True
mlog.log('Dependency', mlog.bold('pcap'), 'found:',
mlog.green('YES'), '(%s)' % pcapconf)
return
mlog.debug('Could not find pcap-config binary, trying next.')
if DependencyMethods.EXTRAFRAMEWORK in self.methods:
if mesonlib.is_osx():
fwdep = ExtraFrameworkDependency('pcap', False, None, self.env,
self.language, kwargs)
if fwdep.found():
self.is_found = True
self.compile_args = fwdep.get_compile_args()
self.link_args = fwdep.get_link_args()
self.version = '2' # FIXME
return
mlog.log('Dependency', mlog.bold('pcap'), 'found:', mlog.red('NO'))
def get_methods(self):
if mesonlib.is_osx():
return [DependencyMethods.PKGCONFIG, DependencyMethods.PCAPCONFIG, DependencyMethods.EXTRAFRAMEWORK]
else:
return [DependencyMethods.PKGCONFIG, DependencyMethods.PCAPCONFIG]

@ -0,0 +1,7 @@
project('pcap test', 'c')
pcap_dep = dependency('pcap', version : '>=1.0')
e = executable('pcap_prog', 'pcap_prog.c', dependencies : pcap_dep)
test('pcaptest', e)

@ -0,0 +1,9 @@
#include <pcap/pcap.h>
int
main()
{
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *p = pcap_create(NULL, errbuf);
return p == NULL;
}
Loading…
Cancel
Save