mirror of https://github.com/kivy/kivy.git
setup.py: autodetect gles 2 headers. Closes #22
This commit is contained in:
parent
258605ca81
commit
8871b201ae
52
setup.py
52
setup.py
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
from os.path import join, dirname, realpath, sep
|
||||
from fnmatch import filter as fnfilter
|
||||
from sys import platform, argv, modules
|
||||
from os.path import join, dirname, realpath, sep, exists
|
||||
from os import walk, environ
|
||||
from setuptools import setup, Extension
|
||||
|
||||
|
@ -14,10 +15,10 @@ import kivy
|
|||
cmdclass = {}
|
||||
|
||||
# add build rules for portable packages to cmdclass
|
||||
if sys.platform == 'win32':
|
||||
if platform == 'win32':
|
||||
from kivy.tools.packaging.win32.build import WindowsPortableBuild
|
||||
cmdclass['build_portable'] = WindowsPortableBuild
|
||||
elif sys.platform == 'darwin':
|
||||
elif platform == 'darwin':
|
||||
from kivy.tools.packaging.osx.build import OSXPortableBuild
|
||||
cmdclass['build_portable'] = OSXPortableBuild
|
||||
|
||||
|
@ -33,9 +34,27 @@ c_options = {
|
|||
'use_glew': False,
|
||||
'use_mesagl': False}
|
||||
|
||||
if sys.platform == 'win32':
|
||||
# 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
|
||||
|
||||
print 'Generate config.h'
|
||||
with open(join(dirname(__file__), 'kivy', 'graphics', 'config.h'), 'w') as fd:
|
||||
|
@ -53,17 +72,14 @@ with open(join(dirname(__file__), 'kivy', 'graphics', 'config.pxi'), 'w') as fd:
|
|||
ext_modules = []
|
||||
|
||||
# list all files to compile
|
||||
import fnmatch
|
||||
import os
|
||||
|
||||
pyx_files = []
|
||||
kivy_libs_dir = realpath(kivy.kivy_libs_dir)
|
||||
for root, dirnames, filenames in os.walk(join(dirname(__file__), 'kivy')):
|
||||
for root, dirnames, filenames in walk(join(dirname(__file__), 'kivy')):
|
||||
# ignore lib directory
|
||||
if realpath(root).startswith(kivy_libs_dir):
|
||||
continue
|
||||
for filename in fnmatch.filter(filenames, '*.pyx'):
|
||||
pyx_files.append(os.path.join(root, filename))
|
||||
for filename in fnfilter(filenames, '*.pyx'):
|
||||
pyx_files.append(join(root, filename))
|
||||
|
||||
# check for cython
|
||||
try:
|
||||
|
@ -73,7 +89,7 @@ except:
|
|||
have_cython = False
|
||||
|
||||
# create .c for every module
|
||||
if 'sdist' in sys.argv and have_cython:
|
||||
if 'sdist' in argv and have_cython:
|
||||
from Cython.Compiler.Main import compile
|
||||
print 'Generating C files...',
|
||||
compile(pyx_files)
|
||||
|
@ -87,8 +103,8 @@ if have_cython:
|
|||
# the end. More information can be found at
|
||||
# http://mail.python.org/pipermail/distutils-sig/2007-September/008204.html
|
||||
# The solution taken is http://pypi.python.org/pypi/setuptools_cython/
|
||||
if 'setuptools.extension' in sys.modules:
|
||||
m = sys.modules['setuptools.extension']
|
||||
if 'setuptools.extension' in modules:
|
||||
m = modules['setuptools.extension']
|
||||
m.Extension.__dict__ = m._Extension.__dict__
|
||||
else:
|
||||
pyx_files = ['%s.c' % x[:-4] for x in pyx_files]
|
||||
|
@ -97,19 +113,19 @@ if True:
|
|||
libraries = []
|
||||
include_dirs = []
|
||||
extra_link_args = []
|
||||
if sys.platform == 'win32':
|
||||
if platform == 'win32':
|
||||
libraries.append('opengl32')
|
||||
elif sys.platform == 'darwin':
|
||||
elif platform == 'darwin':
|
||||
# On OSX, it's not -lGL, but -framework OpenGL...
|
||||
extra_link_args = ['-framework', 'OpenGL']
|
||||
elif sys.platform.startswith('freebsd'):
|
||||
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 sys.platform == 'win32':
|
||||
if platform == 'win32':
|
||||
libraries.append('glew32')
|
||||
else:
|
||||
libraries.append('GLEW')
|
||||
|
|
Loading…
Reference in New Issue