Newer
Older
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
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Thu 20 Sep 2012 14:43:19 CEST
"""Bindings for flandmark
"""
import sys
import subprocess
from distutils.core import setup
from distutils.extension import Extension
def pkgconfig(package):
def uniq(seq, idfun=None):
# order preserving
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
# in old Python versions:
# if seen.has_key(marker)
# but in new ones:
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result
flag_map = {
'-I': 'include_dirs',
'-L': 'library_dirs',
'-l': 'libraries',
}
cmd = [
'pkg-config',
'--libs',
'--cflags',
package,
]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = proc.communicate()[0]
if proc.returncode != 0:
raise RuntimeError, "PkgConfig did not find package %s. Output:\n%s" % \
(package, output.strip())
kw = {}
for token in output.split():
if flag_map.has_key(token[:2]):
kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
else: # throw others to extra_link_args
kw.setdefault('extra_compile_args', []).append(token)
for k, v in kw.iteritems(): # remove duplicated
kw[k] = uniq(v)
return kw
def setup_bob_extension(ext_name, sources):
"""Sets up a given C++ extension that depends on Bob"""
bob = pkgconfig('bob-python')
ocv = pkgconfig('opencv')
return Extension(
ext_name,
sources=sources,
language="c++",
include_dirs=bob['include_dirs'] + ocv['include_dirs'],
library_dirs=bob['library_dirs'] + ocv.get('library_dirs', []),
runtime_library_dirs=bob['library_dirs'] + ocv.get('library_dirs', []),
libraries=bob['libraries'] + ocv['libraries'],
)
setup(
name="flandmark",
version="1.0.6",
ext_modules=[
[
"flandmark/ext/flandmark_detector.cpp",
"flandmark/ext/liblbp.cpp",
"flandmark/ext/ext.cpp",
])
])