setup.py: autodetect gles 2 headers. Closes #22

This commit is contained in:
Mathieu Virbel 2011-02-01 20:46:39 +01:00
parent 258605ca81
commit 8871b201ae
1 changed files with 34 additions and 18 deletions

View File

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