sip_configure.py
Go to the documentation of this file.
00001 from copy import copy
00002 import os
00003 import re
00004 import subprocess
00005 import sys
00006 
00007 import sipconfig
00008 try:
00009     from PyQt4.pyqtconfig import Configuration
00010 except ImportError:
00011     # PyQt >= 4.11 has no pyqtconfig module if built with configure-ng.py
00012     from PyQt4 import QtCore
00013 
00014     class Configuration(sipconfig.Configuration):
00015         def __init__(self):
00016             env = copy(os.environ)
00017             env['QT_SELECT'] = '4'
00018             qtconfig = subprocess.check_output(
00019                 ['qmake', '-query'], env=env, universal_newlines=True)
00020             qtconfig = dict(line.split(':', 1) for line in qtconfig.splitlines())
00021             pyqtconfig = {
00022                 'qt_archdata_dir': qtconfig['QT_INSTALL_DATA'],
00023                 'qt_data_dir': qtconfig['QT_INSTALL_DATA'],
00024                 'qt_dir': qtconfig['QT_INSTALL_PREFIX'],
00025                 'qt_inc_dir': qtconfig['QT_INSTALL_HEADERS'],
00026                 'qt_lib_dir': qtconfig['QT_INSTALL_LIBS'],
00027                 'qt_threaded': 1,
00028                 'qt_version': QtCore.QT_VERSION,
00029                 'qt_winconfig': 'shared',
00030             }
00031             sipconfig.Configuration.__init__(self, [pyqtconfig])
00032 
00033             macros = sipconfig._default_macros.copy()
00034             macros['INCDIR_QT'] = qtconfig['QT_INSTALL_HEADERS']
00035             macros['LIBDIR_QT'] = qtconfig['QT_INSTALL_LIBS']
00036             macros['MOC'] = 'moc-qt4'
00037             self.set_build_macros(macros)
00038 
00039 if len(sys.argv) != 8:
00040     print('usage: %s build-dir sip-file output_dir include_dirs libs lib_dirs ldflags' % sys.argv[0])
00041     sys.exit(1)
00042 
00043 # The SIP build folder, the SIP file, the output directory, the include directories, the libraries, the library directories and the linker flags.
00044 build_dir, sip_file, output_dir, include_dirs, libs, lib_dirs, ldflags = sys.argv[1:]
00045 
00046 # The name of the SIP build file generated by SIP and used by the build system.
00047 build_file = 'pyqtscripting.sbf'
00048 
00049 # Get the PyQt configuration information.
00050 config = Configuration()
00051 
00052 # Get the extra SIP flags needed by the imported qt module.  Note that
00053 # this normally only includes those flags (-x and -t) that relate to SIP's
00054 # versioning system.
00055 try:
00056     sip_dir = config.pyqt_sip_dir
00057     sip_flags = config.pyqt_sip_flags
00058 except AttributeError:
00059     # sipconfig.Configuration does not have a pyqt_sip_dir or pyqt_sip_flags attribute
00060     sip_dir = sipconfig._pkg_config['default_sip_dir'] + '/PyQt4'
00061     sip_flags = QtCore.PYQT_CONFIGURATION['sip_flags']
00062 
00063 try:
00064     os.makedirs(build_dir)
00065 except OSError:
00066     pass
00067 
00068 # Run SIP to generate the code.  Note that we tell SIP where to find the qt
00069 # module's specification files using the -I flag.
00070 cmd = [
00071     config.sip_bin,
00072     '-c', build_dir,
00073     '-b', os.path.join(build_dir, build_file),
00074     '-I', sip_dir,
00075     '-w'
00076 ]
00077 cmd += sip_flags.split(' ')
00078 cmd.append(sip_file)
00079 subprocess.check_call(cmd)
00080 
00081 # Create the Makefile.  The QtModuleMakefile class provided by the
00082 # pyqtconfig module takes care of all the extra preprocessor, compiler and
00083 # linker flags needed by the Qt library.
00084 makefile = sipconfig.SIPModuleMakefile(
00085     dir=build_dir,
00086     configuration=config,
00087     build_file=build_file,
00088     qt=['QtCore', 'QtGui']
00089 )
00090 
00091 # hack to override makefile behavior which always prepend -l to libraries which is wrong for absolute paths
00092 default_platform_lib_function = sipconfig.SIPModuleMakefile.platform_lib
00093 
00094 
00095 def custom_platform_lib_function(self, clib, framework=0):
00096     if os.path.isabs(clib):
00097         return clib
00098     return default_platform_lib_function(self, clib, framework)
00099 sipconfig.SIPModuleMakefile.platform_lib = custom_platform_lib_function
00100 
00101 
00102 # split paths on whitespace
00103 # while dealing with whitespaces within the paths if they are escaped with backslashes
00104 def split_paths(paths):
00105     paths = re.split('(?<=[^\\\\]) ', paths)
00106     return paths
00107 
00108 for include_dir in split_paths(include_dirs):
00109     include_dir = include_dir.replace('\\', '')
00110     makefile.extra_include_dirs.append(include_dir)
00111 for lib in split_paths(libs):
00112     makefile.extra_libs.append(lib)
00113 for lib_dir in split_paths(lib_dirs):
00114     lib_dir = lib_dir.replace('\\', '')
00115     makefile.extra_lib_dirs.append(lib_dir)
00116 for ldflag in ldflags.split('\\ '):
00117     makefile.LFLAGS.append(ldflag)
00118 
00119 # redirect location of generated library
00120 makefile._target = '"%s"' % os.path.join(output_dir, makefile._target)
00121 
00122 # Generate the Makefile itself
00123 makefile.generate()


python_qt_binding
Author(s): Dave Hershberger, Dorian Scholz, Dirk Thomas
autogenerated on Sat Apr 2 2016 03:35:05