2 from distutils.spawn
import find_executable
10 from PyQt5
import QtCore
18 env = copy(os.environ)
19 env[
'QT_SELECT'] =
'5' 20 qmake_exe =
'qmake-qt5' if find_executable(
'qmake-qt5')
else 'qmake' 21 qtconfig = subprocess.check_output(
22 [qmake_exe,
'-query'], env=env, universal_newlines=
True)
23 qtconfig = dict(line.split(
':', 1)
for line
in qtconfig.splitlines())
25 'qt_archdata_dir': qtconfig[
'QT_INSTALL_DATA'],
26 'qt_data_dir': qtconfig[
'QT_INSTALL_DATA'],
27 'qt_dir': qtconfig[
'QT_INSTALL_PREFIX'],
28 'qt_inc_dir': qtconfig[
'QT_INSTALL_HEADERS'],
29 'qt_lib_dir': qtconfig[
'QT_INSTALL_LIBS'],
31 'qt_version': QtCore.QT_VERSION,
32 'qt_winconfig':
'shared exceptions',
34 if sys.platform ==
'darwin':
35 if os.path.exists(os.path.join(qtconfig[
'QT_INSTALL_LIBS'],
'QtCore.framework')):
36 pyqtconfig[
'qt_framework'] = 1
41 sipconfig.Configuration.__init__(self, [pyqtconfig])
43 macros = sipconfig._default_macros.copy()
44 macros[
'INCDIR_QT'] = qtconfig[
'QT_INSTALL_HEADERS']
45 macros[
'LIBDIR_QT'] = qtconfig[
'QT_INSTALL_LIBS']
46 macros[
'MOC'] =
'moc-qt5' if find_executable(
'moc-qt5')
else 'moc' 47 self.set_build_macros(macros)
52 Get the extra SIP flags needed by the imported qt module, and locate PyQt5 sip install files. 54 Note that this normally only includes those flags (-x and -t) that relate to SIP's versioning 58 sip_dir = config.pyqt_sip_dir
59 sip_flags = config.pyqt_sip_flags
60 return sip_dir, sip_flags
61 except AttributeError:
63 sip_flags = QtCore.PYQT_CONFIGURATION[
'sip_flags']
66 default_sip_dir = os.path.join(PyQt5.__path__[0],
'bindings')
67 if os.path.exists(default_sip_dir):
68 return default_sip_dir, sip_flags
71 default_sip_dir = os.path.join(sipconfig._pkg_config[
'default_sip_dir'],
'PyQt5')
72 if os.path.exists(default_sip_dir):
73 return default_sip_dir, sip_flags
76 default_sip_dir = os.path.join(sipconfig._pkg_config[
'default_sip_dir'],
'Qt5')
77 if os.path.exists(default_sip_dir):
78 return default_sip_dir, sip_flags
79 raise FileNotFoundError(
'The sip directory for PyQt5 could not be located. Please ensure' +
80 ' that PyQt5 is installed')
83 if len(sys.argv) != 9:
84 print(
'usage: %s build-dir sip-file output_dir include_dirs libs lib_dirs ldflags extra_defines' %
91 build_dir, sip_file, output_dir, include_dirs, libs, lib_dirs, ldflags, extra_defines = sys.argv[1:]
94 build_file =
'pyqtscripting.sbf' 102 os.makedirs(build_dir)
109 sip_bin = config.sip_bin
111 if sys.platform ==
'win32' and os.path.isdir(sip_bin):
117 '-b', os.path.join(build_dir, build_file),
121 cmd += sip_flags.split(
' ')
123 subprocess.check_call(cmd)
128 makefile = sipconfig.SIPModuleMakefile(
130 configuration=config,
131 build_file=build_file,
132 qt=[
'QtCore',
'QtGui']
137 default_platform_lib_function = sipconfig.SIPModuleMakefile.platform_lib
141 if not clib
or clib.isspace():
144 if os.path.isabs(clib)
or clib.startswith(
'-l'):
149 if libqt5_rename
and not framework
and clib.startswith(
'Qt')
and not clib.startswith(
'Qt5'):
150 return '-lQt5' + clib[2:]
155 sipconfig.SIPModuleMakefile.platform_lib = custom_platform_lib_function
161 paths = re.split(
'(?<=[^\\\\]) ', paths)
166 include_dir = include_dir.replace(
'\\',
'')
167 makefile.extra_include_dirs.append(include_dir)
169 makefile.extra_libs.append(lib)
171 lib_dir = lib_dir.replace(
'\\',
'')
172 makefile.extra_lib_dirs.append(lib_dir)
173 for ldflag
in ldflags.split(
'\\ '):
174 makefile.LFLAGS.append(ldflag)
175 for extra_define
in extra_defines.split(
' '):
176 makefile.extra_defines.append(extra_define)
179 makefile._target =
'"%s"' % os.path.join(output_dir, makefile._target)
182 if sys.platform ==
'win32':
183 makefile.extra_cxxflags.append(
'/std:c++14')
186 makefile.CXXFLAGS.append(
'/Zc:__cplusplus')
188 makefile.extra_cxxflags.append(
'-std=c++14')
194 libs = makefile.LIBS.as_list()
195 for i
in range(len(libs)):
196 libs[i] = libs[i].replace(
'$$[QT_INSTALL_LIBS]', config.build_macros()[
'LIBDIR_QT'])
197 makefile.LIBS.set(libs)