Skip to content
Permalink
Browse files

Fix building of headless QPA extension on Arch

  • Loading branch information...
kovidgoyal committed Apr 29, 2014
1 parent 4b73ada commit fce51f8b1d793857f42489a5308dcee701fdb6bc
Showing with 34 additions and 19 deletions.
  1. +19 −12 setup/build_environment.py
  2. +15 −7 setup/extensions.py
@@ -43,24 +43,23 @@
ICU = os.environ.get('ICU_DIR', r'Q:\icu')

QMAKE = '/Volumes/sw/qt/bin/qmake' if isosx else 'qmake'
if find_executable('qmake-qt4'):
QMAKE = find_executable('qmake-qt4')
elif find_executable('qmake'):
QMAKE = find_executable('qmake')
for x in ('qmake-qt5', 'qt5-qmake', 'qmake'):
q = find_executable(x)
if q:
QMAKE = q
break
QMAKE = os.environ.get('QMAKE', QMAKE)

# QT5XX: Change this to real qmake detection
QMAKE = '/opt/qt5/bin/qmake'

PKGCONFIG = find_executable('pkg-config')
PKGCONFIG = os.environ.get('PKG_CONFIG', PKGCONFIG)

def run_pkgconfig(name, envvar, default, flag, prefix):
ans = []
if envvar:
ans = os.environ.get(envvar, default)
ans = [x.strip() for x in ans.split(os.pathsep)]
ans = [x for x in ans if x and (prefix=='-l' or os.path.exists(x))]
ev = os.environ.get(envvar, None)
if ev:
ans = [x.strip() for x in ev.split(os.pathsep)]
ans = [x for x in ans if x and (prefix=='-l' or os.path.exists(x))]
if not ans:
try:
raw = subprocess.Popen([PKGCONFIG, flag, name],
@@ -70,7 +69,7 @@ def run_pkgconfig(name, envvar, default, flag, prefix):
except:
print 'Failed to run pkg-config:', PKGCONFIG, 'for:', name

return ans
return ans or ([default] if default else [])

def pkgconfig_include_dirs(name, envvar, default):
return run_pkgconfig(name, envvar, default, '--cflags-only-I', '-I')
@@ -90,16 +89,24 @@ def consolidate(envvar, default):
def readvar(name):
return re.search('%s:(.+)$' % name, qraw, flags=re.M).group(1).strip()


pyqt = {x:readvar(y) for x, y in (
('inc', 'QT_INSTALL_HEADERS'), ('lib', 'QT_INSTALL_LIBS')
)}
c = sipconfig.Configuration()
pyqt['sip_bin'] = c.sip_bin
from PyQt5.QtCore import PYQT_CONFIGURATION
pyqt['sip_flags'] = PYQT_CONFIGURATION['sip_flags']
pyqt['default_sip_dir'] = c.default_sip_dir
def get_sip_dir(q):
for x in ('', 'PyQt5', 'sip/PyQt5'):
base = os.path.join(q, x)
if os.path.exists(os.path.join(base, 'QtWidgets')):
return base
return q
pyqt['pyqt_sip_dir'] = get_sip_dir(c.default_sip_dir)
pyqt['sip_inc_dir'] = c.sip_inc_dir

glib_flags = subprocess.check_output([PKGCONFIG, '--libs', 'glib-2.0']) if islinux else ''
qt_inc = pyqt['inc']
qt_lib = pyqt['lib']
ft_lib_dirs = []
@@ -16,7 +16,7 @@
msvc, MT, win_inc, win_lib, win_ddk, magick_inc_dirs, magick_lib_dirs,
magick_libs, chmlib_lib_dirs, sqlite_inc_dirs, icu_inc_dirs,
icu_lib_dirs, win_ddk_lib_dirs, ft_libs, ft_lib_dirs, ft_inc_dirs,
zlib_libs, zlib_lib_dirs, zlib_inc_dirs, is64bit)
zlib_libs, zlib_lib_dirs, zlib_inc_dirs, is64bit, glib_flags)
MT
isunix = islinux or isosx or isbsd

@@ -345,8 +345,8 @@ def preflight(self, obj_dir, compiler, linker, builder, cflags, ldflags):
cc = cxx = msvc.cc
cflags = '/c /nologo /MD /W3 /EHsc /DNDEBUG'.split()
ldflags = '/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt.lib'.split()
#cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
#ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
# cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
# ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
if is64bit:
cflags.append('/GS-')

@@ -471,8 +471,8 @@ def build(self, ext, dest):
self.info('\n\n', ' '.join(cmd), '\n\n')
self.check_call(cmd)
if iswindows:
#manifest = dest+'.manifest'
#cmd = [MT, '-manifest', manifest, '-outputresource:%s;2'%dest]
# manifest = dest+'.manifest'
# cmd = [MT, '-manifest', manifest, '-outputresource:%s;2'%dest]
# self.info(*cmd)
# self.check_call(cmd)
# os.remove(manifest)
@@ -506,6 +506,13 @@ def build_headless(self):
target = self.dest('headless')
if not self.newer(target, headers + sources + others):
return
# Arch monkey patches qmake as a result of which it fails to add
# glib-2.0 to the list of library dependencies. Compiling QPA
# plugins uses the static libQt5PlatformSupport.a which needs glib
# to be specified after it for linking to succeed, so we add it to
# QMAKE_LIBS_PRIVATE (we cannot use LIBS as that would put -lglib-2.0
# before libQt5PlatformSupport.

pro = textwrap.dedent(
'''\
TARGET = headless
@@ -518,8 +525,9 @@ def build_headless(self):
OTHER_FILES = {others}
DESTDIR = {destdir}
CONFIG -= create_cmake # Prevent qmake from generating a cmake build file which it puts in the calibre src directory
QMAKE_LIBS_PRIVATE += {glib}
''').format(
headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d(target))
headers=' '.join(headers), sources=' '.join(sources), others=' '.join(others), destdir=self.d(target), glib=glib_flags)
bdir = self.j(self.d(self.SRC), 'build', 'headless')
if not os.path.exists(bdir):
os.makedirs(bdir)
@@ -542,7 +550,7 @@ def build_sip_files(self, ext, src_dir):
sbf = self.j(src_dir, self.b(sipf)+'.sbf')
if self.newer(sbf, [sipf]+ext.headers):
cmd = [pyqt['sip_bin'], '-w', '-c', src_dir, '-b', sbf, '-I'+
pyqt['default_sip_dir']+'/sip/PyQt5'] + shlex.split(pyqt['sip_flags']) + [sipf]
pyqt['pyqt_sip_dir']] + shlex.split(pyqt['sip_flags']) + [sipf]
self.info(' '.join(cmd))
self.check_call(cmd)
self.info('')

0 comments on commit fce51f8

Please sign in to comment.
You can’t perform that action at this time.