forked from r9y9/pylibfreenect2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
177 lines (155 loc) · 6.03 KB
/
setup.py
File metadata and controls
177 lines (155 loc) · 6.03 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# coding: utf-8
from __future__ import with_statement, print_function, absolute_import
from setuptools import setup, find_packages, Extension
try:
from packaging.version import Version as LooseVersion
except ImportError:
from distutils.version import LooseVersion
import platform
import numpy as np
import os
from os.path import join, exists
from subprocess import Popen, PIPE
import sys
libfreenect2_install_prefix = os.environ.get(
"LIBFREENECT2_INSTALL_PREFIX", "/usr/local/")
libfreenect2_include_top = join(libfreenect2_install_prefix, "include")
libfreenect2_library_path = join(libfreenect2_install_prefix, "lib")
libfreenect2_configh_path = join(
libfreenect2_include_top, "libfreenect2", "config.h")
if not exists(libfreenect2_configh_path):
raise OSError("{}: is not found".format(libfreenect2_configh_path))
if platform.system() == "Windows":
lib_candidates = list(filter(lambda l: l.startswith("freenect2."),
os.listdir(join(libfreenect2_library_path))))
else:
lib_candidates = list(filter(lambda l: l.startswith("libfreenect2."),
os.listdir(join(libfreenect2_library_path))))
if len(lib_candidates) == 0:
raise OSError("libfreenect2 library cannot be found")
min_cython_ver = '0.21.0'
try:
import Cython
ver = Cython.__version__
_CYTHON_INSTALLED = LooseVersion(ver) >= LooseVersion(min_cython_ver)
except ImportError:
_CYTHON_INSTALLED = False
try:
if not _CYTHON_INSTALLED:
raise ImportError('No supported version of Cython installed.')
from Cython.Distutils import build_ext
from Cython.Build import cythonize
cython = True
except ImportError:
cython = False
if cython:
ext = '.pyx'
cmdclass = {'build_ext': build_ext}
else:
ext = '.cpp'
cmdclass = {}
if not os.path.exists(join("pylibfreenect2", "libfreenect2" + ext)):
raise RuntimeError("Cython is required to generate C++ codes.")
def has_define_in_config(key, close_fds=None):
if close_fds is None:
if platform.system() == "Windows":
close_fds = False
else:
close_fds = True
if platform.system() == "Windows":
lines = []
with open(libfreenect2_configh_path, 'r') as f:
for line in f:
if key in line:
lines.append(line)
else:
p = Popen("cat {0} | grep {1}".format(libfreenect2_configh_path, key),
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds, shell=True)
p.wait()
lines = p.stdout.readlines()
if sys.version_info.major >= 3 and not platform.system() == "Windows":
return len(lines) == 1 and lines[0].startswith(b"#define")
else:
return len(lines) == 1 and lines[0].startswith("#define")
if platform.system() == "Darwin":
extra_compile_args = ["-std=c++11", "-stdlib=libc++",
"-mmacosx-version-min=10.8", "-O3"]
elif platform.system() == "Windows":
# Windows Visual Studio compiler flags with safe optimizations
# /O2 = Maximum optimization for speed (keeps accuracy)
# /GL = Whole program optimization (optional, minor gains)
# /fp:precise = Default floating point model (accurate depth data)
extra_compile_args = ["/std:c++11", "/EHsc", "/O2", "/GL", "/fp:precise"]
extra_link_args = ["/LTCG"] # Link time code generation
else:
# Linux/Unix with safe optimizations
# -O3 = Maximum optimization
# -march=native = Use CPU-specific instructions
# Note: Removed -ffast-math for accurate depth data
extra_compile_args = ["-std=c++11", "-O3", "-march=native"]
extra_link_args = []
ext_modules = cythonize(
[Extension(
name="pylibfreenect2.libfreenect2",
sources=[
join("pylibfreenect2", "libfreenect2" + ext),
],
include_dirs=[np.get_include(),
join(libfreenect2_include_top)],
library_dirs=[libfreenect2_library_path],
libraries=["freenect2"],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args if 'extra_link_args' in locals() else [],
language="c++")],
compile_time_env={
"LIBFREENECT2_WITH_OPENGL_SUPPORT":
has_define_in_config("LIBFREENECT2_WITH_OPENGL_SUPPORT"),
"LIBFREENECT2_WITH_OPENCL_SUPPORT":
has_define_in_config("LIBFREENECT2_WITH_OPENCL_SUPPORT"),
"LIBFREENECT2_WITH_CUDA_SUPPORT":
has_define_in_config("LIBFREENECT2_WITH_CUDA_SUPPORT"),
}
)
install_requires = ['numpy >= 1.19.0', 'packaging']
if sys.version_info < (3, 4):
install_requires.append('enum34')
# Build requirements that need to be available during setup
setup_requires = ['numpy >= 1.19.0', 'cython >= 0.29.36']
setup(
name='pylibfreenect2',
version='0.1.5-dev',
description='A python interface for libfreenect2',
author='Ryuichi Yamamoto',
author_email='zryuichi@gmail.com',
url='https://github.com/r9y9/pylibfreenect2',
license='MIT',
packages=find_packages(),
ext_modules=ext_modules,
cmdclass=cmdclass,
install_requires=install_requires,
setup_requires=setup_requires,
tests_require=['nose', 'coverage'],
extras_require={
'docs': ['numpydoc', 'sphinx_rtd_theme', 'seaborn'],
'test': ['nose'],
'develop': ['cython >= ' + min_cython_ver],
},
classifiers=[
"Operating System :: POSIX",
"Operating System :: Unix",
"Operating System :: MacOS",
"Programming Language :: Cython",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"License :: OSI Approved :: MIT License",
"Topic :: Scientific/Engineering",
"Topic :: Software Development",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
],
keywords=["pylibfreenect2", "libfreenect2", "freenect2"]
)