-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
280 lines (251 loc) · 9.47 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
from fnmatch import filter as fnfilter
from sys import platform, argv
from os.path import join, dirname, realpath, sep, exists
from os import walk, environ
from distutils.core import setup
from distutils.extension import Extension
try:
# check for cython
from Cython.Distutils import build_ext
except ImportError:
print '\nCython is missing, its required for compiling kivy !\n\n'
raise
# extract version (simulate doc generation, kivy will be not imported)
environ['KIVY_DOC_INCLUDE'] = '1'
import kivy
# extra build commands go in the cmdclass dict {'command-name': CommandClass}
# see tools.packaging.{platform}.build.py for custom build commands for
# portable packages. also e.g. we use build_ext command from cython if its
# installed for c extensions.
cmdclass = {}
try:
# add build rules for portable packages to cmdclass
if platform == 'win32':
from kivy.tools.packaging.win32.build import WindowsPortableBuild
cmdclass['build_portable'] = WindowsPortableBuild
elif platform == 'darwin':
from kivy.tools.packaging.osx.build import OSXPortableBuild
cmdclass['build_portable'] = OSXPortableBuild
except ImportError:
print 'User distribution detected, avoid portable command.'
from kivy.tools.packaging.factory import FactoryBuild
cmdclass['build_factory'] = FactoryBuild
#
# Detect options
#
c_options = {
'use_opengl_es2': True,
'use_opengl_debug': False,
'use_glew': False,
'use_mesagl': 'USE_MESAGL' in environ}
# Detect which opengl version headers to use
if platform == 'win32':
print 'Windows platform detected, force GLEW usage.'
c_options['use_glew'] = True
elif platform == 'darwin':
# macosx is using their own gl.h
pass
else:
# searching GLES headers
default_header_dirs = ['/usr/include', '/usr/local/include']
found = False
for hdir in default_header_dirs:
filename = join(hdir, 'GLES2', 'gl2.h')
if exists(filename):
found = True
print 'Found GLES 2.0 headers at', filename
break
if not found:
print 'WARNING: GLES 2.0 headers are not found'
print 'Fallback to Desktop opengl headers.'
c_options['use_opengl_es2'] = False
class KivyBuildExt(build_ext):
def build_extensions(self):
print 'Build configuration is:'
for opt, value in c_options.iteritems():
print ' *', opt, ' = ', repr(value)
print 'Generate config.h'
config_h = join(dirname(__file__), 'kivy', 'graphics', 'config.h')
with open(config_h, 'w') as fd:
fd.write('// Autogenerated file for Kivy C configuration\n')
for k, v in c_options.iteritems():
fd.write('#define __%s %d\n' % (k.upper(), int(v)))
print 'Generate config.pxi'
config_pxi = join(dirname(__file__), 'kivy', 'graphics', 'config.pxi')
with open(config_pxi, 'w') as fd:
fd.write('# Autogenerated file for Kivy Cython configuration\n')
for k, v in c_options.iteritems():
fd.write('DEF %s = %d\n' % (k.upper(), int(v)))
build_ext.build_extensions(self)
cmdclass['build_ext'] = KivyBuildExt
# extension modules
ext_modules = []
# list all files to compile
pyx_files = []
pxd_files = []
kivy_libs_dir = realpath(join(kivy.kivy_base_dir, 'libs'))
for root, dirnames, filenames in walk(join(dirname(__file__), 'kivy')):
# ignore lib directory
if realpath(root).startswith(kivy_libs_dir):
continue
for filename in fnfilter(filenames, '*.pxd'):
pxd_files.append(join(root, filename))
for filename in fnfilter(filenames, '*.pyx'):
pyx_files.append(join(root, filename))
# add cython core extension modules if cython is available
if True:
libraries = ['m']
include_dirs = []
extra_link_args = []
if platform == 'win32':
libraries.append('opengl32')
elif platform == 'darwin':
# On OSX, it's not -lGL, but -framework OpenGL...
extra_link_args = ['-framework', 'OpenGL']
elif platform.startswith('freebsd'):
include_dirs += ['/usr/local/include']
extra_link_args += ['-L', '/usr/local/lib']
else:
libraries.append('GL')
if c_options['use_glew']:
if platform == 'win32':
libraries.append('glew32')
else:
libraries.append('GLEW')
def get_modulename_from_file(filename):
pyx = '.'.join(filename.split('.')[:-1])
pyxl = pyx.split(sep)
while pyxl[0] != 'kivy':
pyxl.pop(0)
if pyxl[1] == 'kivy':
pyxl.pop(0)
return '.'.join(pyxl)
OrigExtension = Extension
def Extension(*args, **kwargs):
# Small hack to only compile for x86_64 on OSX.
# Is there a better way to do this?
if platform == 'darwin':
extra_args = ['-arch', 'x86_64']
kwargs['extra_compile_args'] = extra_args + \
kwargs.get('extra_compile_args', [])
kwargs['extra_link_args'] = extra_args + \
kwargs.get('extra_link_args', [])
return OrigExtension(*args, **kwargs)
# simple extensions
for pyx in (x for x in pyx_files if not 'graphics' in x):
pxd = [x for x in pxd_files if not 'graphics' in x]
module_name = get_modulename_from_file(pyx)
ext_modules.append(Extension(module_name, [pyx] + pxd))
# opengl aware modules
for pyx in (x for x in pyx_files if 'graphics' in x):
pxd = [x for x in pxd_files if 'graphics' in x]
module_name = get_modulename_from_file(pyx)
ext_modules.append(Extension(
module_name, [pyx] + pxd,
libraries=libraries,
include_dirs=include_dirs,
extra_link_args=extra_link_args))
#setup datafiles to be included in the disytibution, liek examples...
#extracts all examples files except sandbox
data_file_prefix = 'share/kivy-'
examples = {}
examples_allowed_ext = ('readme', 'py', 'wav', 'png', 'jpg', 'svg', 'json',
'avi', 'gif', 'txt', 'ttf', 'obj', 'mtl', 'kv')
for root, subFolders, files in walk('examples'):
if 'sandbox' in root:
continue
for file in files:
ext = file.split('.')[-1].lower()
if ext not in examples_allowed_ext:
continue
filename = join(root, file)
directory = '%s%s' % (data_file_prefix, dirname(filename))
if not directory in examples:
examples[directory] = []
examples[directory].append(filename)
# setup !
setup(
name='Kivy',
version=kivy.__version__,
author='Kivy Crew',
author_email='kivy-dev@googlegroups.com',
url='http://kivy.org/',
license='LGPL',
description='A software library for rapid development of ' + \
'hardware-accelerated multitouch applications.',
ext_modules=ext_modules,
cmdclass=cmdclass,
packages=[
'kivy',
'kivy.core',
'kivy.core.audio',
'kivy.core.camera',
'kivy.core.clipboard',
'kivy.core.image',
'kivy.core.gl',
'kivy.core.spelling',
'kivy.core.text',
'kivy.core.video',
'kivy.core.window',
'kivy.ext',
'kivy.graphics',
'kivy.input',
'kivy.input.postproc',
'kivy.input.providers',
'kivy.lib',
'kivy.lib.osc',
'kivy.modules',
'kivy.network',
'kivy.tools',
'kivy.tools.packaging',
'kivy.uix',
],
package_dir={'kivy': 'kivy'},
package_data={'kivy': [
'data/*.kv',
'data/*.json',
'data/fonts/*.ttf',
'data/images/*.png',
'data/images/*.jpg',
'data/images/*.gif',
'data/keyboards/*.json',
'data/logo/*.png',
'data/glsl/*.png',
'data/glsl/*.vs',
'data/glsl/*.fs',
'tools/packaging/README.txt',
'tools/packaging/win32/kivy.bat',
'tools/packaging/win32/kivyenv.sh',
'tools/packaging/win32/README.txt',
'tools/packaging/osx/kivy.sh']},
data_files=examples.items(),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: MacOS X',
'Environment :: Win32 (MS Windows)',
'Environment :: X11 Applications',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU Library or Lesser '
'General Public License (LGPL)',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: BSD :: FreeBSD',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Artistic Software',
'Topic :: Games/Entertainment',
'Topic :: Multimedia :: Graphics :: 3D Rendering',
'Topic :: Multimedia :: Graphics :: Capture :: Digital Camera',
'Topic :: Multimedia :: Graphics :: Presentation',
'Topic :: Multimedia :: Graphics :: Viewers',
'Topic :: Multimedia :: Sound/Audio :: Players :: MP3',
'Topic :: Multimedia :: Video :: Display',
'Topic :: Scientific/Engineering :: Human Machine Interfaces',
'Topic :: Scientific/Engineering :: Visualization',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: User Interfaces'])