-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure.py
More file actions
181 lines (149 loc) · 5.51 KB
/
configure.py
File metadata and controls
181 lines (149 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from PyQt5.QtCore import PYQT_CONFIGURATION as pyqt_config
from distutils import sysconfig
import os, sipconfig, sys
class HostPythonConfiguration(object):
def __init__(self):
self.platform=sys.platform
self.version=sys.hexversion>>8
self.inc_dir=sysconfig.get_python_inc()
self.venv_inc_dir=sysconfig.get_python_inc(prefix=sys.prefix)
self.module_dir=sysconfig.get_python_lib(plat_specific=1)
if sys.platform=='win32':
self.data_dir=sys.prefix
self.lib_dir=sys.prefix+'\\libs'
else:
self.data_dir=sys.prefix+'/share'
self.lib_dir=sys.prefix+'/lib'
class TargetQtConfiguration(object):
def __init__(self, qmake):
pipe=os.popen(' '.join([qmake, '-query']))
for l in pipe:
l=l.strip()
tokens=l.split(':', 1)
if isinstance(tokens, list):
if len(tokens) != 2:
error("Unexpected output from qmake: '%s'\n" % l)
name,value=tokens
else:
name=tokens
value=None
name=name.replace('/', '_')
setattr(self, name, value)
pipe.close()
if __name__=="__main__":
from argparse import ArgumentParser
parser=ArgumentParser(description="Configure PyMyLabel module.")
parser.add_argument(
'-q', '--qmake',
dest="qmake",
type=str,
default="qmake",
help="Path to qmake executable"
)
parser.add_argument(
'-s', '--sip-extras',
dest="sip_extras",
type=str,
default="",
help="Extra arguments to sip"
)
args=parser.parse_args()
qmake_exe=args.qmake
if not qmake_exe.endswith('qmake'):
qmake_exe=os.path.join(qmake_exe,'qmake')
if os.system(' '.join([qmake_exe, '-v']))!=0:
if sys.platform=='win32':
print("Make sure you have a working Qt qmake on your PATH.")
else:
print(
"Use the --qmake argument to explicitly specify a "
"working Qt qmake."
)
exit(1)
sip_args=args.sip_extras
pyconfig=HostPythonConfiguration()
py_sip_dir=os.path.join(pyconfig.data_dir, 'sip', 'PyQt5')
sip_inc_dir=pyconfig.venv_inc_dir
qtconfig=TargetQtConfiguration(qmake_exe)
inc_dir=os.path.abspath(os.path.join(".","src"))
lib_dir=inc_dir
dest_pkg_dir="PyMyLabel"
sip_files_dir=os.path.abspath(os.path.join(".","sip"))
output_dir =os.path.abspath(os.path.join(".", "modules"))
build_file="PyMyLabel.sbf"
build_path = os.path.join(output_dir, build_file)
if not os.path.exists(output_dir): os.mkdir(output_dir)
sip_file = os.path.join(sip_files_dir, "PyMyLabel.sip")
config=sipconfig.Configuration()
config.default_mod_dir=( "/usr/local/lib/python%i.%i/dist-packages" %
( sys.version_info.major, sys.version_info.minor ) )
cmd=" ".join([
config.sip_bin,
pyqt_config['sip_flags'],
sip_args,
'-I', sip_files_dir,
'-I', py_sip_dir,
'-I', config.sip_inc_dir,
'-I', inc_dir,
"-c", output_dir,
"-b", build_path,
"-w",
"-o",
sip_file,
])
print(cmd)
if os.system(cmd)!=0: sys.exit(1)
makefile=sipconfig.SIPModuleMakefile(
config,
build_file,
dir=output_dir,
install_dir=dest_pkg_dir
)
makefile.extra_defines+=['MYLABEL_LIBRARY','QT_CORE_LIB', 'QT_GUI_LIB', 'QT_WIDGETS_LIB']
makefile.extra_include_dirs+=[os.path.abspath(inc_dir), qtconfig.QT_INSTALL_HEADERS]
makefile.extra_lib_dirs+=[qtconfig.QT_INSTALL_LIBS, os.path.join('..','src')]
makefile.extra_libs+=['MyLabel']
if sys.platform=='darwin':
makefile.extra_cxxflags+=['-F'+qtconfig.QT_INSTALL_LIBS, '-std=c++11']
makefile.extra_include_dirs+=[
os.path.join(qtconfig.QT_INSTALL_LIBS,'QtCore.framework','Headers'),
os.path.join(qtconfig.QT_INSTALL_LIBS,'QtGui.framework','Headers'),
os.path.join(qtconfig.QT_INSTALL_LIBS,'QtWidgets.framework','Headers'),
]
makefile.extra_lflags+=[
'-F'+qtconfig.QT_INSTALL_LIBS,
"-framework QtWidgets",
"-framework QtGui",
"-framework QtCore",
"-framework DiskArbitration",
"-framework IOKit",
"-framework OpenGL",
"-framework AGL",
]
elif sys.platform=='win32':
makefile.extra_include_dirs+=[
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtCore"),
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtGui"),
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtWidgets"),
]
makefile.extra_lib_dirs+=[os.path.join('..','src','release')]
makefile.extra_libs+=['Qt5Core','Qt5Gui','Qt5Widgets']
elif sys.platform=="linux":
makefile.extra_cxxflags+=['-std=c++11']
makefile.extra_include_dirs+=[
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtCore"),
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtGui"),
os.path.join(qtconfig.QT_INSTALL_HEADERS, "QtWidgets"),
]
makefile.generate()
sipconfig.ParentMakefile(
configuration = config,
subdirs = ["src", output_dir],
).generate()
os.chdir("src")
qmake_cmd=qmake_exe
if sys.platform=="win32": qmake_cmd+=" -spec win32-msvc2010"
print()
print(qmake_cmd)
os.system(qmake_cmd)
sys.exit()