Skip to content

Commit

Permalink
added more robust pkg-config handling in setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
darvid committed May 26, 2018
1 parent 35398d2 commit dc580a9
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,33 @@ def readme():
return ''


# http://code.activestate.com/recipes/502261-python-distutils-pkg-config/
def pkgconfig(libs, optional=''):
flag_map = {
'include_dirs': ('--cflags-only-I', 2),
'library_dirs': ('--libs-only-L', 2),
'libraries': ('--libs-only-l', 2),
'extra_compile_args': ('--cflags-only-other', 0),
'extra_link_args': ('--libs-only-other', 0),
}
ext_kwargs = {}
for lib in libs:
for distutils_kwarg, (pkg_option, trim_offset) in flag_map.items():
try:
options = subprocess.check_output(
['pkg-config', optional, pkg_option, lib]).decode().split()
except subprocess.CalledProcessError:
continue
ext_kwargs.setdefault(distutils_kwarg, []).extend(
[opt[trim_offset:] for opt in options])
return ext_kwargs


def setup():
ext = setuptools.extension.Extension(
'hyperscan',
['src/hyperscanmodule.c'],
define_macros=[

],
libraries=['hs'],
extra_compile_args=[
subprocess.check_output([
'pkg-config', '--cflags', 'libhs']).decode('utf-8'),
],
**pkgconfig(['libhs'])
)
setup_requirements = ['six', 'setuptools>=17.1', 'setuptools_scm']
setuptools.setup(
Expand Down

0 comments on commit dc580a9

Please sign in to comment.