Skip to content

Commit 1147197

Browse files
Add logic for building against a system lz4 library to setup.py
1 parent a7316f7 commit 1147197

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

setup.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,57 @@
22

33

44
from setuptools import setup, find_packages, Extension
5+
import subprocess
6+
import os
57

68
VERSION = (0, 7, 0)
79
VERSION_STR = ".".join([str(x) for x in VERSION])
810

11+
# Check to see if we have a lz4 library installed on the system and
12+
# use it if so. If not, we'll use the bundled library. If lz4 is
13+
# installed it will have a pkg-config file, so we'll use pkg-config to
14+
# check for existence of the library.
15+
pkg_config_exe = os.environ.get('PKG_CONFIG', None) or 'pkg-config'
16+
cmd = '{0} --exists liblz4'.format(pkg_config_exe).split()
17+
liblz4_found = subprocess.call(cmd) == 0
18+
19+
if liblz4_found:
20+
# Use system lz4, and don't set optimization and warning flags for
21+
# the compiler. Specifically we don't define LZ4_VERSION since the
22+
# system lz4 library could be updated (that's the point of a
23+
# shared library).
24+
lz4mod = Extension('lz4',
25+
[
26+
'src/python-lz4.c'
27+
],
28+
extra_compile_args=[
29+
"-std=c99",
30+
"-DVERSION=\"%s\"" % VERSION_STR,
31+
],
32+
libraries=['lz4'],
33+
)
34+
else:
35+
# Use the bundled lz4 libs, and set the compiler flags as they
36+
# historically have been set. We do set LZ4_VERSION here, since it
37+
# won't change after compilation.
38+
lz4mod = Extension('lz4',
39+
[
40+
'src/lz4.c',
41+
'src/lz4hc.c',
42+
'src/python-lz4.c'
43+
],
44+
extra_compile_args=[
45+
"-std=c99",
46+
"-O3",
47+
"-Wall",
48+
"-W",
49+
"-Wundef",
50+
"-DVERSION=\"%s\"" % VERSION_STR,
51+
"-DLZ4_VERSION=\"r130\"",
52+
]
53+
)
54+
55+
956
setup(
1057
name='lz4',
1158
version=VERSION_STR,
@@ -16,21 +63,7 @@
1663
url='https://github.com/steeve/python-lz4',
1764
packages=find_packages('src'),
1865
package_dir={'': 'src'},
19-
ext_modules=[
20-
Extension('lz4', [
21-
'src/lz4.c',
22-
'src/lz4hc.c',
23-
'src/python-lz4.c'
24-
], extra_compile_args=[
25-
"-std=c99",
26-
"-O3",
27-
"-Wall",
28-
"-W",
29-
"-Wundef",
30-
"-DVERSION=\"%s\"" % VERSION_STR,
31-
"-DLZ4_VERSION=\"r130\"",
32-
])
33-
],
66+
ext_modules=[lz4mod,],
3467
setup_requires=["nose>=1.0"],
3568
test_suite = "nose.collector",
3669
classifiers=[

0 commit comments

Comments
 (0)