mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Make the process for detecting python compile flags more robust
Now follows the implementation in python3-config Also add OpenGL.framework when building on OS X
This commit is contained in:
41
setup.py
41
setup.py
@@ -24,10 +24,11 @@ is_travis = os.environ.get('TRAVIS') == 'true'
|
|||||||
|
|
||||||
|
|
||||||
cflags = ldflags = cc = ldpaths = None
|
cflags = ldflags = cc = ldpaths = None
|
||||||
|
PKGCONFIG = os.environ.get('PKGCONFIG_EXE', 'pkg-config')
|
||||||
|
|
||||||
|
|
||||||
def pkg_config(pkg, *args):
|
def pkg_config(pkg, *args):
|
||||||
return list(filter(None, shlex.split(subprocess.check_output(['pkg-config', pkg] + list(args)).decode('utf-8'))))
|
return list(filter(None, shlex.split(subprocess.check_output([PKGCONFIG, pkg] + list(args)).decode('utf-8'))))
|
||||||
|
|
||||||
|
|
||||||
def cc_version():
|
def cc_version():
|
||||||
@@ -41,6 +42,23 @@ def cc_version():
|
|||||||
return ver
|
return ver
|
||||||
|
|
||||||
|
|
||||||
|
def get_python_flags(cflags):
|
||||||
|
cflags.extend('-I' + sysconfig.get_path(x) for x in 'include platinclude'.split())
|
||||||
|
libs = []
|
||||||
|
libs += sysconfig.get_config_var('LIBS').split()
|
||||||
|
libs += sysconfig.get_config_var('SYSLIBS').split()
|
||||||
|
if sysconfig.get_config_var('PYTHONFRAMEWORK'):
|
||||||
|
for var in 'data include scripts'.split():
|
||||||
|
val = sysconfig.get_path(var)
|
||||||
|
if val and '/Python.framework' in val:
|
||||||
|
libs.append('-F' + val[:val.index('/Python.framework')])
|
||||||
|
libs += ['-framework', sysconfig.get_config_var('PYTHONFRAMEWORK')]
|
||||||
|
else:
|
||||||
|
libs += ['-lpython' + sysconfig.get_config_var('VERSION') + sys.abiflags]
|
||||||
|
libs += sysconfig.get_config_var('LINKFORSHARED').split()
|
||||||
|
return libs
|
||||||
|
|
||||||
|
|
||||||
def init_env(debug=False, asan=False):
|
def init_env(debug=False, asan=False):
|
||||||
global cflags, ldflags, cc, ldpaths
|
global cflags, ldflags, cc, ldpaths
|
||||||
ccver = cc_version()
|
ccver = cc_version()
|
||||||
@@ -67,9 +85,9 @@ def init_env(debug=False, asan=False):
|
|||||||
ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
|
ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
|
||||||
|
|
||||||
cflags.append('-pthread')
|
cflags.append('-pthread')
|
||||||
if not is_travis and subprocess.Popen('pkg-config --atleast-version=2 glew'.split()).wait() != 0:
|
if not is_travis and subprocess.Popen([PKGCONFIG, 'glew', '--atleast-version=2']).wait() != 0:
|
||||||
try:
|
try:
|
||||||
ver = subprocess.check_output('pkg-config --modversion glew'.split()).decode('utf-8').strip()
|
ver = subprocess.check_output([PKGCONFIG, 'glew', '--modversion']).decode('utf-8').strip()
|
||||||
major = int(re.match(r'\d+', ver).group())
|
major = int(re.match(r'\d+', ver).group())
|
||||||
except Exception:
|
except Exception:
|
||||||
ver = 'not found'
|
ver = 'not found'
|
||||||
@@ -80,23 +98,10 @@ def init_env(debug=False, asan=False):
|
|||||||
cflags.extend(pkg_config('freetype2', '--cflags-only-I'))
|
cflags.extend(pkg_config('freetype2', '--cflags-only-I'))
|
||||||
cflags.extend(pkg_config('glfw3', '--cflags-only-I'))
|
cflags.extend(pkg_config('glfw3', '--cflags-only-I'))
|
||||||
ldflags.append('-shared')
|
ldflags.append('-shared')
|
||||||
cflags.append('-I' + sysconfig.get_config_var('CONFINCLUDEPY'))
|
pylib = get_python_flags(cflags)
|
||||||
if isosx:
|
if isosx:
|
||||||
fd = sysconfig.get_config_var('LIBDIR')
|
glfw_ldflags = pkg_config('--libs', '--static', 'glfw3') + ['-framework', 'OpenGL']
|
||||||
try:
|
|
||||||
fd = fd[:fd.index('/Python.framework')]
|
|
||||||
except ValueError:
|
|
||||||
fd = sysconfig.get_config_var('LIBDEST')
|
|
||||||
fd = fd[:fd.index('/Python.framework')]
|
|
||||||
pylib = ['-F' + fd, '-framework', 'Python']
|
|
||||||
glfw_ldflags = pkg_config('--libs', '--static', 'glfw3')
|
|
||||||
else:
|
else:
|
||||||
lib = sysconfig.get_config_var('LDLIBRARY')
|
|
||||||
if lib.startswith('lib'):
|
|
||||||
lib = lib[3:]
|
|
||||||
if lib.endswith('.so'):
|
|
||||||
lib = lib[:-3]
|
|
||||||
pylib = ['-L' + sysconfig.get_config_var('LIBDIR'), '-l' + lib]
|
|
||||||
glfw_ldflags = pkg_config('glfw3', '--libs')
|
glfw_ldflags = pkg_config('glfw3', '--libs')
|
||||||
ldpaths = pylib + \
|
ldpaths = pylib + \
|
||||||
pkg_config('glew', '--libs') + pkg_config('freetype2', '--libs') + glfw_ldflags
|
pkg_config('glew', '--libs') + pkg_config('freetype2', '--libs') + glfw_ldflags
|
||||||
|
|||||||
Reference in New Issue
Block a user