setup.py: changes to not force SDL2 or GStreamer if they are explicitly disabled + reduce the code that generates configuration.

This commit is contained in:
Mathieu Virbel 2015-01-18 01:32:16 +01:00
parent 59cf423844
commit 773f1d4da4
1 changed files with 41 additions and 30 deletions

View File

@ -14,7 +14,6 @@ from distutils.extension import Extension
from collections import OrderedDict from collections import OrderedDict
if sys.version > '3': if sys.version > '3':
PY3 = True PY3 = True
else: else:
PY3 = False PY3 = False
@ -69,7 +68,7 @@ c_options['use_opengl_es2'] = None
c_options['use_opengl_debug'] = False c_options['use_opengl_debug'] = False
c_options['use_glew'] = False c_options['use_glew'] = False
c_options['use_sdl'] = False c_options['use_sdl'] = False
c_options['use_sdl2'] = False c_options['use_sdl2'] = None
c_options['use_ios'] = False c_options['use_ios'] = False
c_options['use_mesagl'] = False c_options['use_mesagl'] = False
c_options['use_x11'] = False c_options['use_x11'] = False
@ -110,36 +109,37 @@ if not have_cython:
class KivyBuildExt(build_ext): class KivyBuildExt(build_ext):
def build_extensions(self): def build_extensions(self):
print('Build configuration is:') # build files
for opt, value in c_options.items():
print(' * {0} = {1}'.format(opt, value))
debug = bool(self.debug)
print(' * debug = {0}'.format(debug))
print('Generate config.h')
config_h_fn = expand('graphics', 'config.h') config_h_fn = expand('graphics', 'config.h')
config_pxi_fn = expand('graphics', 'config.pxi')
config_py_fn = expand('setupconfig.py')
# generate headers
config_h = '// Autogenerated file for Kivy C configuration\n' config_h = '// Autogenerated file for Kivy C configuration\n'
config_h += '#define __PY3 {0}\n'.format(int(PY3)) config_h += '#define __PY3 {0}\n'.format(int(PY3))
for k, v in c_options.items():
config_h += '#define __{0} {1}\n'.format(k.upper(), int(v))
self.update_if_changed(config_h_fn, config_h)
print('Generate config.pxi')
config_pxi_fn = expand('graphics', 'config.pxi')
# update the pxi only if the content changed
config_pxi = '# Autogenerated file for Kivy Cython configuration\n' config_pxi = '# Autogenerated file for Kivy Cython configuration\n'
config_pxi += 'DEF PY3 = {0}\n'.format(int(PY3)) config_pxi += 'DEF PY3 = {0}\n'.format(int(PY3))
for k, v in c_options.items():
config_pxi += 'DEF {0} = {1}\n'.format(k.upper(), int(v))
config_pxi += 'DEF DEBUG = {0}\n'.format(debug)
self.update_if_changed(config_pxi_fn, config_pxi)
print('Generate setupconfig.py')
config_py_fn = expand('setupconfig.py')
config_py = '# Autogenerated file for Kivy configuration\n' config_py = '# Autogenerated file for Kivy configuration\n'
config_py += 'PY3 = {0}\n'.format(int(PY3)) config_py += 'PY3 = {0}\n'.format(int(PY3))
for k, v in c_options.items():
config_py += '{0} = {1}\n'.format(k.upper(), int(v)) # generate content
print('Build configuration is:')
for opt, value in c_options.items():
value = int(bool(value))
print(' * {0} = {1}'.format(opt, value))
opt = opt.upper()
config_h += '#define __{0} {1}\n'.format(opt, value)
config_pxi += 'DEF {0} = {1}\n'.format(opt, value)
config_py += '{0} = {1}\n'.format(opt, value)
debug = bool(self.debug)
print(' * debug = {0}'.format(debug))
config_pxi += 'DEF DEBUG = {0}\n'.format(debug)
config_py += 'DEBUG = {0}\n'.format(debug) config_py += 'DEBUG = {0}\n'.format(debug)
print('Generate config.h')
self.update_if_changed(config_h_fn, config_h)
print('Generate config.pxi')
self.update_if_changed(config_pxi_fn, config_pxi)
print('Generate setupconfig.py')
self.update_if_changed(config_py_fn, config_py) self.update_if_changed(config_py_fn, config_py)
c = self.compiler.compiler_type c = self.compiler.compiler_type
@ -228,9 +228,9 @@ if platform == 'ios':
c_options['use_ios'] = True c_options['use_ios'] = True
c_options['use_sdl'] = True c_options['use_sdl'] = True
# detect gstreamer/sdl2, only on desktop # detect gstreamer, only on desktop
sdl2_flags = {} # works if we forced the options or in autodetection
if platform not in ('ios', 'android'): if platform not in ('ios', 'android') and c_options['use_gstreamer'] in (None, True):
if c_options['use_osx_frameworks'] and platform == 'darwin': if c_options['use_osx_frameworks'] and platform == 'darwin':
# check the existence of frameworks # check the existence of frameworks
@ -247,6 +247,20 @@ if platform not in ('ios', 'android'):
'-framework', 'GStreamer'], '-framework', 'GStreamer'],
'include_dirs': [join(f_path, 'Headers')]} 'include_dirs': [join(f_path, 'Headers')]}
else:
# use pkg-config approach instead
gst_flags = pkgconfig('gstreamer-1.0')
if 'libraries' in gst_flags:
c_options['use_gstreamer'] = True
# detect SDL2, only on desktop
# works if we forced the options or in autodetection
sdl2_flags = {}
if platform not in ('ios', 'android') and c_options['use_gstreamer'] in (None, True):
if c_options['use_osx_frameworks'] and platform == 'darwin':
# check the existence of frameworks
sdl2_valid = True sdl2_valid = True
sdl2_flags = { sdl2_flags = {
'extra_link_args': [ 'extra_link_args': [
@ -273,9 +287,6 @@ if platform not in ('ios', 'android'):
else: else:
# use pkg-config approach instead # use pkg-config approach instead
gst_flags = pkgconfig('gstreamer-1.0')
if 'libraries' in gst_flags:
c_options['use_gstreamer'] = True
sdl2_flags = pkgconfig('sdl2', 'SDL2_ttf', 'SDL2_image', 'SDL2_mixer') sdl2_flags = pkgconfig('sdl2', 'SDL2_ttf', 'SDL2_image', 'SDL2_mixer')
if 'libraries' in sdl2_flags: if 'libraries' in sdl2_flags:
c_options['use_sdl2'] = True c_options['use_sdl2'] = True