forked from strawlab/python-pcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
85 lines (74 loc) · 3.05 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import print_function
from collections import defaultdict
from Cython.Distutils import build_ext
from distutils.core import setup
from distutils.extension import Extension
import subprocess
import numpy
import sys
import platform
import os
if platform.system() == "Darwin":
os.environ['ARCHFLAGS'] = ''
# Try to find PCL. XXX we should only do this when trying to build or install.
PCL_SUPPORTED = ["-1.7", "-1.6", ""] # in order of preference
for pcl_version in PCL_SUPPORTED:
if subprocess.call(['pkg-config', 'pcl_common%s' % pcl_version]) == 0:
break
else:
print("%s: error: cannot find PCL, tried" % sys.argv[0], file=sys.stderr)
for version in PCL_SUPPORTED:
print(' pkg-config pcl_common%s' % version, file=sys.stderr)
sys.exit(1)
# Find build/link options for PCL using pkg-config.
pcl_libs = ["common", "features", "filters", "io", "kdtree", "octree",
"registration", "sample_consensus", "search", "segmentation",
"surface"]
pcl_libs = ["pcl_%s%s" % (lib, pcl_version) for lib in pcl_libs]
ext_args = defaultdict(list)
ext_args['include_dirs'].append(numpy.get_include())
def pkgconfig(flag):
# Equivalent in Python 2.7 (but not 2.6):
#subprocess.check_output(['pkg-config', flag] + pcl_libs).split()
p = subprocess.Popen(['pkg-config', flag] + pcl_libs,
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
# Assume no evil spaces in filenames; unsure how pkg-config would
# handle those, anyway.
# decode() is required in Python 3. TODO how do know the encoding?
return stdout.decode().split()
for flag in pkgconfig('--cflags-only-I'):
ext_args['include_dirs'].append(flag[2:])
for flag in pkgconfig('--cflags-only-other'):
if flag.startswith('-D'):
macro, value = flag[2:].split('=', 1)
ext_args['define_macros'].append((macro, value))
else:
ext_args['extra_compile_args'].append(flag)
for flag in pkgconfig('--libs-only-l'):
if flag == "-lflann_cpp-gd":
print("skipping -lflann_cpp-gd (see https://github.com/strawlab/python-pcl/issues/29")
continue
ext_args['libraries'].append(flag[2:])
for flag in pkgconfig('--libs-only-L'):
ext_args['library_dirs'].append(flag[2:])
for flag in pkgconfig('--libs-only-other'):
ext_args['extra_link_args'].append(flag)
# Fix compile error on Ubuntu 12.04 (e.g., Travis-CI).
ext_args['define_macros'].append(
("EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET", "1"))
setup(name='python-pcl',
description='pcl wrapper',
url='http://github.com/strawlab/python-pcl',
version='0.2',
author='John Stowers',
author_email='[email protected]',
license='BSD',
packages=["pcl"],
ext_modules=[Extension("pcl._pcl", ["pcl/_pcl.pyx", "pcl/minipcl.cpp"],
language="c++", **ext_args),
Extension("pcl.registration", ["pcl/registration.pyx"],
language="c++", **ext_args),
],
cmdclass={'build_ext': build_ext}
)