-
Notifications
You must be signed in to change notification settings - Fork 4
/
sipconfig.py
2548 lines (1993 loc) · 86.1 KB
/
sipconfig.py
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This module is intended to be used by the build/installation scripts of
# extension modules created with SIP. It provides information about file
# locations, version numbers etc., and provides some classes and functions.
#
# Copyright (c) 2009 Riverbank Computing Limited <info@riverbankcomputing.com>
#
# This file is part of SIP.
#
# This copy of SIP is licensed for use under the terms of the SIP License
# Agreement. See the file LICENSE for more details.
#
# SIP is supplied WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
import sys
import os
import stat
import string
import re
# These are installation specific values created when SIP was configured.
_pkg_config = {
'default_bin_dir': 'C:\\Python26_64',
'default_mod_dir': 'C:\\Python26_64\\Lib\\site-packages',
'default_sip_dir': 'C:\\Python26_64\\sip',
'platform': 'win32-msvc2008',
'py_conf_inc_dir': 'C:\\Python26_64\\include',
'py_inc_dir': 'C:\\Python26_64\\include',
'py_lib_dir': 'C:\\Python26_64\\libs',
'py_version': 0x020601,
'sip_bin': 'C:\\Python26_64\\sip',
'sip_config_args': '',
'sip_inc_dir': 'C:\\Python26_64\\include',
'sip_mod_dir': 'C:\\Python26_64\\Lib\\site-packages',
'sip_version': 0x040900,
'sip_version_str': '4.9-snapshot-20090808',
'universal': ''
}
_default_macros = {
'AIX_SHLIB': '',
'AR': '',
'CC': 'cl',
'CFLAGS': '-nologo -Zm200 -Zc:wchar_t-',
'CFLAGS_CONSOLE': '',
'CFLAGS_DEBUG': '-Zi -MDd',
'CFLAGS_EXCEPTIONS_OFF': '',
'CFLAGS_EXCEPTIONS_ON': '',
'CFLAGS_MT': '',
'CFLAGS_MT_DBG': '',
'CFLAGS_MT_DLL': '',
'CFLAGS_MT_DLLDBG': '',
'CFLAGS_RELEASE': '-O2 -MD',
'CFLAGS_RTTI_OFF': '',
'CFLAGS_RTTI_ON': '',
'CFLAGS_SHLIB': '',
'CFLAGS_STL_OFF': '',
'CFLAGS_STL_ON': '',
'CFLAGS_THREAD': '',
'CFLAGS_WARN_OFF': '-W0',
'CFLAGS_WARN_ON': '-W3',
'CHK_DIR_EXISTS': 'if not exist',
'CONFIG': 'qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe',
'COPY': 'copy /y',
'CXX': 'cl',
'CXXFLAGS': '-nologo -Zm200 -Zc:wchar_t-',
'CXXFLAGS_CONSOLE': '',
'CXXFLAGS_DEBUG': '-Zi -MDd',
'CXXFLAGS_EXCEPTIONS_OFF': '',
'CXXFLAGS_EXCEPTIONS_ON': '-EHsc',
'CXXFLAGS_MT': '',
'CXXFLAGS_MT_DBG': '',
'CXXFLAGS_MT_DLL': '',
'CXXFLAGS_MT_DLLDBG': '',
'CXXFLAGS_RELEASE': '-O2 -MD',
'CXXFLAGS_RTTI_OFF': '',
'CXXFLAGS_RTTI_ON': '-GR',
'CXXFLAGS_SHLIB': '',
'CXXFLAGS_STL_OFF': '',
'CXXFLAGS_STL_ON': '-EHsc',
'CXXFLAGS_THREAD': '',
'CXXFLAGS_WARN_OFF': '-W0',
'CXXFLAGS_WARN_ON': '-W3 -w34100 -w34189',
'DEFINES': 'UNICODE WIN32 QT_LARGEFILE_SUPPORT',
'DEL_FILE': 'del',
'EXTENSION_PLUGIN': '',
'EXTENSION_SHLIB': '',
'INCDIR': '',
'INCDIR_OPENGL': '',
'INCDIR_X11': '',
'LFLAGS': '/NOLOGO',
'LFLAGS_CONSOLE': '/SUBSYSTEM:CONSOLE',
'LFLAGS_CONSOLE_DLL': '',
'LFLAGS_DEBUG': '/DEBUG',
'LFLAGS_DLL': '/DLL',
'LFLAGS_OPENGL': '',
'LFLAGS_PLUGIN': '',
'LFLAGS_RELEASE': '/INCREMENTAL:NO',
'LFLAGS_SHLIB': '',
'LFLAGS_SONAME': '',
'LFLAGS_THREAD': '',
'LFLAGS_WINDOWS': '''/SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'"''',
'LFLAGS_WINDOWS_DLL': '',
'LIB': 'lib /NOLOGO',
'LIBDIR': '',
'LIBDIR_OPENGL': '',
'LIBDIR_X11': '',
'LIBS': '',
'LIBS_CONSOLE': '',
'LIBS_CORE': 'kernel32.lib user32.lib shell32.lib uuid.lib ole32.lib advapi32.lib ws2_32.lib',
'LIBS_GUI': 'gdi32.lib comdlg32.lib oleaut32.lib imm32.lib winmm.lib winspool.lib ws2_32.lib ole32.lib user32.lib advapi32.lib',
'LIBS_NETWORK': 'ws2_32.lib',
'LIBS_OPENGL': 'opengl32.lib glu32.lib gdi32.lib user32.lib',
'LIBS_RT': '',
'LIBS_RTMT': '',
'LIBS_THREAD': '',
'LIBS_WINDOWS': '',
'LIBS_X11': '',
'LINK': 'link',
'LINK_SHLIB': '',
'LINK_SHLIB_CMD': '',
'MAKEFILE_GENERATOR': 'MSVC.NET',
'MKDIR': 'mkdir',
'RANLIB': '',
'RPATH': '',
'STRIP': ''
}
# The stack of configuration dictionaries.
_config_stack = []
class Configuration(object):
"""The class that represents SIP configuration values.
"""
def __init__(self, sub_cfg=None):
"""Initialise an instance of the class.
sub_cfg is the list of sub-class configurations. It should be None
when called normally.
"""
# Find the build macros in the closest imported module from where this
# was originally defined.
self._macros = None
for cls in self.__class__.__mro__:
if cls is object:
continue
mod = sys.modules[cls.__module__]
if hasattr(mod, "_default_macros"):
self._macros = mod._default_macros
break
if sub_cfg:
cfg = sub_cfg
else:
cfg = []
cfg.append(_pkg_config)
global _config_stack
_config_stack = cfg
def __getattr__(self, name):
"""Allow configuration values and user options to be handled as
instance variables.
name is the name of the configuration value or user option.
"""
for cfg in _config_stack:
try:
return cfg[name]
except KeyError:
pass
raise AttributeError("\"%s\" is not a valid configuration value or user option" % name)
def build_macros(self):
"""Return the dictionary of platform specific build macros.
"""
return self._macros
def set_build_macros(self, macros):
"""Set the dictionary of build macros to be use when generating
Makefiles.
macros is the dictionary of platform specific build macros.
"""
self._macros = macros
class _UniqueList:
"""A limited list that ensures all its elements are unique.
"""
def __init__(self, value=None):
"""Initialise the instance.
value is the initial value of the list.
"""
if value is None:
self._list = []
else:
self._list = value
def append(self, value):
"""Append a value to the list if it isn't already present.
value is the value to append.
"""
if value not in self._list:
self._list.append(value)
def lextend(self, value):
"""A normal list extend ignoring the uniqueness.
value is the list of elements to append.
"""
self._list.extend(value)
def extend(self, value):
"""Append each element of a value to a list if it isn't already
present.
value is the list of elements to append.
"""
for el in value:
self.append(el)
def as_list(self):
"""Return the list as a raw list.
"""
return self._list
class _Macro:
"""A macro that can be manipulated as a list.
"""
def __init__(self, name, value):
"""Initialise the instance.
name is the name of the macro.
value is the initial value of the macro.
"""
self._name = name
self.set(value)
def set(self, value):
"""Explicitly set the value of the macro.
value is the new value. It may be a string, a list of strings or a
_UniqueList instance.
"""
self._macro = []
if isinstance(value, _UniqueList):
value = value.as_list()
if type(value) == list:
self.extend(value)
else:
self.append(value)
def append(self, value):
"""Append a value to the macro.
value is the value to append.
"""
if value:
self._macro.append(value)
def extend(self, value):
"""Append each element of a value to the macro.
value is the list of elements to append.
"""
for el in value:
self.append(el)
def remove(self, value):
"""Remove a value from the macro. It doesn't matter if the value
wasn't present.
value is the value to remove.
"""
try:
self._macro.remove(value)
except:
pass
def as_list(self):
"""Return the macro as a list.
"""
return self._macro
class Makefile:
"""The base class for the different types of Makefiles.
"""
def __init__(self, configuration, console=0, qt=0, opengl=0, python=0,
threaded=0, warnings=1, debug=0, dir=None,
makefile="Makefile", installs=None, universal=''):
"""Initialise an instance of the target. All the macros are left
unchanged allowing scripts to manipulate them at will.
configuration is the current configuration.
console is set if the target is a console (rather than windows) target.
qt is set if the target uses Qt. For Qt v4 a list of Qt libraries may
be specified and a simple non-zero value implies QtCore and QtGui.
opengl is set if the target uses OpenGL.
python is set if the target #includes Python.h.
debug is set to generated a debugging version of the target.
threaded is set if the target requires thread support. It is
automatically set if the target uses Qt and Qt has thread support
enabled.
warnings is set if compiler warning messages are required.
debug is set if debugging symbols should be generated.
dir is the directory for build files and Makefiles.
makefile is the name of the Makefile.
installs is a list of extra install targets. Each element is a two
part list, the first of which is the source and the second is the
destination. If the source is another list then it is a set of source
files and the destination is a directory.
universal is the name of the SDK if the target is a MacOS/X universal
binary.
"""
if qt:
if not hasattr(configuration, "qt_version"):
error("The target uses Qt but pyqtconfig has not been imported.")
# For Qt v4 interpret Qt support as meaning link against the core
# and GUI libraries (which corresponds to the default qmake
# configuration). Also allow a list of Qt v4 modules to be
# specified.
if configuration.qt_version >= 0x040000:
if type(qt) != list:
qt = ["QtCore", "QtGui"]
self._threaded = configuration.qt_threaded
else:
self._threaded = threaded
if sys.platform != "darwin":
universal = ''
self.config = configuration
self.console = console
self._qt = qt
self._opengl = opengl
self._python = python
self._warnings = warnings
self._debug = debug
self._dir = dir
self._makefile = makefile
self._installs = installs
self._universal = universal
self._finalised = 0
# Copy the macros and convert them all to instance lists.
macros = configuration.build_macros()
for m in list(macros.keys()):
# Allow the user to override the default.
try:
val = getattr(configuration, m)
except AttributeError:
val = macros[m]
# These require special handling as they are (potentially) a set of
# space separated values rather than a single value that might
# contain spaces.
if m in ("DEFINES", "CONFIG") or m[:6] in ("INCDIR", "LIBDIR"):
val = val.split()
# We also want to treat lists of libraries in the same way so that
# duplicates get eliminated.
if m[:4] == "LIBS":
val = val.split()
self.__dict__[m] = _Macro(m, val)
# This is used to alter the configuration more significantly than can
# be done with just configuration files.
self.generator = self.optional_string("MAKEFILE_GENERATOR", "UNIX")
# These are what configuration scripts normally only need to change.
self.extra_cflags = []
self.extra_cxxflags = []
self.extra_defines = []
self.extra_include_dirs = []
self.extra_lflags = []
self.extra_lib_dirs = []
self.extra_libs = []
# Get these once and make them available to sub-classes.
if sys.platform == "win32":
def_copy = "copy"
def_rm = "del"
def_mkdir = "mkdir"
def_chk_dir_exists = "if not exist"
else:
def_copy = "cp -f"
def_rm = "rm -f"
def_mkdir = "mkdir -p"
def_chk_dir_exists = "test -d"
self.copy = self.optional_string("COPY", def_copy)
self.rm = self.optional_string("DEL_FILE", def_rm)
self.mkdir = self.optional_string("MKDIR", def_mkdir)
self.chkdir = self.optional_string("CHK_DIR_EXISTS", def_chk_dir_exists)
def finalise(self):
"""Finalise the macros by doing any consolidation that isn't specific
to a Makefile.
"""
# Extract the things we might need from the Windows Qt configuration.
# Note that we used to think that if Qt was built with exceptions, RTTI
# and STL support enabled then anything that linked against it also
# needed the same flags. However, detecting this was broken for some
# time and nobody complained. For the moment we'll leave the code in
# but it will never be used.
if self._qt:
wcfg = self.config.qt_winconfig.split()
win_shared = ("shared" in wcfg)
win_exceptions = ("exceptions" in wcfg)
win_rtti = ("rtti" in wcfg)
win_stl = ("stl" in wcfg)
else:
win_shared = 1
win_exceptions = 0
win_rtti = 0
win_stl = 0
# Get what we are going to transform.
cflags = _UniqueList()
cflags.extend(self.extra_cflags)
cflags.extend(self.optional_list("CFLAGS"))
cxxflags = _UniqueList()
cxxflags.extend(self.extra_cxxflags)
cxxflags.extend(self.optional_list("CXXFLAGS"))
defines = _UniqueList()
defines.extend(self.extra_defines)
defines.extend(self.optional_list("DEFINES"))
incdir = _UniqueList(["."])
incdir.extend(self.extra_include_dirs)
incdir.extend(self.optional_list("INCDIR"))
lflags = _UniqueList()
lflags.extend(self.extra_lflags)
lflags.extend(self.optional_list("LFLAGS"))
libdir = _UniqueList()
libdir.extend(self.extra_lib_dirs)
libdir.extend(self.optional_list("LIBDIR"))
# Handle MacOS/X universal binaries.
if self._universal:
unicflags = ('-arch ppc -arch i386 -isysroot %s' % self._universal).split()
unilflags = ('-arch ppc -arch i386 -Wl,-syslibroot,%s' % self._universal).split()
cflags.lextend(unicflags)
cxxflags.lextend(unicflags)
lflags.lextend(unilflags)
# Don't use a unique list as libraries may need to be searched more
# than once. Also MacOS/X uses the form "-framework lib" so we don't
# want to lose the multiple "-framework".
libs = []
for l in self.extra_libs:
libs.append(self.platform_lib(l))
if self._qt:
libs.extend(self._dependent_libs(l))
libs.extend(self.optional_list("LIBS"))
rpaths = _UniqueList()
for l in self.extra_lib_dirs:
# Ignore relative directories. This is really a hack to handle
# SIP v3 inter-module linking.
if os.path.dirname(l) not in ("", ".", ".."):
rpaths.append(l)
if self._python:
incdir.append(self.config.py_inc_dir)
incdir.append(self.config.py_conf_inc_dir)
if sys.platform == "cygwin":
libdir.append(self.config.py_lib_dir)
py_lib = "python%u.%u" % ((self.config.py_version >> 16), ((self.config.py_version >> 8) & 0xff))
libs.append(self.platform_lib(py_lib))
elif sys.platform == "win32":
libdir.append(self.config.py_lib_dir)
py_lib = "python%u%u" % ((self.config.py_version >> 16), ((self.config.py_version >> 8) & 0xff))
# For Borland use the OMF version of the Python library if it
# exists, otherwise assume that Python was built with Borland
# and use the normal library.
if self.generator == "BMAKE":
bpy_lib = py_lib + "_bcpp"
bpy_lib_path = os.path.join(self.config.py_lib_dir, self.platform_lib(bpy_lib))
if os.access(bpy_lib_path, os.F_OK):
py_lib = bpy_lib
if self._debug:
py_lib = py_lib + "_d"
if self.generator != "MINGW":
cflags.append("/D_DEBUG")
cxxflags.append("/D_DEBUG")
libs.append(self.platform_lib(py_lib))
if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):
if win_exceptions:
cflags_exceptions = "CFLAGS_EXCEPTIONS_ON"
cxxflags_exceptions = "CXXFLAGS_EXCEPTIONS_ON"
else:
cflags_exceptions = "CFLAGS_EXCEPTIONS_OFF"
cxxflags_exceptions = "CXXFLAGS_EXCEPTIONS_OFF"
cflags.extend(self.optional_list(cflags_exceptions))
cxxflags.extend(self.optional_list(cxxflags_exceptions))
if win_rtti:
cflags_rtti = "CFLAGS_RTTI_ON"
cxxflags_rtti = "CXXFLAGS_RTTI_ON"
else:
cflags_rtti = "CFLAGS_RTTI_OFF"
cxxflags_rtti = "CXXFLAGS_RTTI_OFF"
cflags.extend(self.optional_list(cflags_rtti))
cxxflags.extend(self.optional_list(cxxflags_rtti))
if win_stl:
cflags_stl = "CFLAGS_STL_ON"
cxxflags_stl = "CXXFLAGS_STL_ON"
else:
cflags_stl = "CFLAGS_STL_OFF"
cxxflags_stl = "CXXFLAGS_STL_OFF"
cflags.extend(self.optional_list(cflags_stl))
cxxflags.extend(self.optional_list(cxxflags_stl))
if self._debug:
if win_shared:
cflags_mt = "CFLAGS_MT_DLLDBG"
cxxflags_mt = "CXXFLAGS_MT_DLLDBG"
else:
cflags_mt = "CFLAGS_MT_DBG"
cxxflags_mt = "CXXFLAGS_MT_DBG"
cflags_debug = "CFLAGS_DEBUG"
cxxflags_debug = "CXXFLAGS_DEBUG"
lflags_debug = "LFLAGS_DEBUG"
else:
if win_shared:
cflags_mt = "CFLAGS_MT_DLL"
cxxflags_mt = "CXXFLAGS_MT_DLL"
else:
cflags_mt = "CFLAGS_MT"
cxxflags_mt = "CXXFLAGS_MT"
cflags_debug = "CFLAGS_RELEASE"
cxxflags_debug = "CXXFLAGS_RELEASE"
lflags_debug = "LFLAGS_RELEASE"
if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):
if self._threaded:
cflags.extend(self.optional_list(cflags_mt))
cxxflags.extend(self.optional_list(cxxflags_mt))
if self.console:
cflags.extend(self.optional_list("CFLAGS_CONSOLE"))
cxxflags.extend(self.optional_list("CXXFLAGS_CONSOLE"))
cflags.extend(self.optional_list(cflags_debug))
cxxflags.extend(self.optional_list(cxxflags_debug))
lflags.extend(self.optional_list(lflags_debug))
if self._warnings:
cflags_warn = "CFLAGS_WARN_ON"
cxxflags_warn = "CXXFLAGS_WARN_ON"
else:
cflags_warn = "CFLAGS_WARN_OFF"
cxxflags_warn = "CXXFLAGS_WARN_OFF"
cflags.extend(self.optional_list(cflags_warn))
cxxflags.extend(self.optional_list(cxxflags_warn))
if self._threaded:
cflags.extend(self.optional_list("CFLAGS_THREAD"))
cxxflags.extend(self.optional_list("CXXFLAGS_THREAD"))
lflags.extend(self.optional_list("LFLAGS_THREAD"))
if self._qt:
if self.generator != "UNIX" and win_shared:
defines.append("QT_DLL")
if not self._debug:
defines.append("QT_NO_DEBUG")
if self.config.qt_version >= 0x040000:
for mod in self._qt:
# Note that qmake doesn't define anything for QtHelp.
if mod == "QtCore":
defines.append("QT_CORE_LIB")
elif mod == "QtGui":
defines.append("QT_GUI_LIB")
elif mod == "QtNetwork":
defines.append("QT_NETWORK_LIB")
elif mod == "QtOpenGL":
defines.append("QT_OPENGL_LIB")
elif mod == "QtScript":
defines.append("QT_SCRIPT_LIB")
elif mod == "QtScriptTools":
defines.append("QT_SCRIPTTOOLS_LIB")
elif mod == "QtSql":
defines.append("QT_SQL_LIB")
elif mod == "QtTest":
defines.append("QT_TEST_LIB")
elif mod == "QtWebKit":
defines.append("QT_WEBKIT_LIB")
elif mod == "QtXml":
defines.append("QT_XML_LIB")
elif mod == "QtXmlPatterns":
defines.append("QT_XMLPATTERNS_LIB")
elif mod == "phonon":
defines.append("QT_PHONON_LIB")
elif self._threaded:
defines.append("QT_THREAD_SUPPORT")
# Handle library directories.
libdir_qt = self.optional_list("LIBDIR_QT")
libdir.extend(libdir_qt)
rpaths.extend(libdir_qt)
if self.config.qt_version >= 0x040000:
# For Windows: the macros that define the dependencies on
# Windows libraries.
wdepmap = {
"QtCore": "LIBS_CORE",
"QtGui": "LIBS_GUI",
"QtNetwork": "LIBS_NETWORK",
"QtOpenGL": "LIBS_OPENGL"
}
# For Windows: the dependencies between Qt libraries.
qdepmap = {
"QtAssistant": ("QtCore", "QtGui", "QtNetwork"),
"QtGui": ("QtCore", ),
"QtHelp": ("QtCore", "QtGui", "QtSql"),
"QtNetwork": ("QtCore", ),
"QtOpenGL": ("QtCore", "QtGui"),
"QtScript": ("QtCore", ),
"QtScriptTools": ("QtCore", "QtGui", "QtScript"),
"QtSql": ("QtCore", ),
"QtSvg": ("QtCore", "QtGui", "QtXml"),
"QtTest": ("QtCore", "QtGui"),
"QtWebKit": ("QtCore", "QtGui", "QtNetwork"),
"QtXml": ("QtCore", ),
"QtXmlPatterns": ("QtCore", "QtNetwork"),
"phonon": ("QtCore", "QtGui"),
"QtDesigner": ("QtCore", "QtGui"),
"QAxContainer": ("QtCore", "QtGui")
}
# The QtSql .prl file doesn't include QtGui as a dependency (at
# least on Linux) so we explcitly set the dependency here for
# everything.
if "QtSql" in self._qt:
if "QtGui" not in self._qt:
self._qt.append("QtGui")
# With Qt v4.2.0, the QtAssistantClient library is now a shared
# library on UNIX. The QtAssistantClient .prl file doesn't
# include QtGui and QtNetwork as a dependency any longer. This
# seems to be a bug in Qt v4.2.0. We explicitly set the
# dependencies here.
if self.config.qt_version >= 0x040200 and "QtAssistant" in self._qt:
if "QtGui" not in self._qt:
self._qt.append("QtGui")
if "QtNetwork" not in self._qt:
self._qt.append("QtNetwork")
for mod in self._qt:
lib = self._qt4_module_to_lib(mod)
libs.append(self.platform_lib(lib, self._is_framework(mod)))
if sys.platform == "win32":
# On Windows the dependent libraries seem to be in
# qmake.conf rather than the .prl file and the
# inter-dependencies between Qt libraries don't seem to
# be anywhere.
deps = _UniqueList()
if mod in list(wdepmap.keys()):
deps.extend(self.optional_list(wdepmap[mod]))
if mod in list(qdepmap.keys()):
for qdep in qdepmap[mod]:
# Ignore the dependency if it is explicitly
# linked.
if qdep not in self._qt:
libs.append(self.platform_lib(self._qt4_module_to_lib(qdep)))
if qdep in list(wdepmap.keys()):
deps.extend(self.optional_list(wdepmap[qdep]))
libs.extend(deps.as_list())
else:
libs.extend(self._dependent_libs(lib, self._is_framework(mod)))
else:
# Windows needs the version number appended if Qt is a DLL.
qt_lib = self.config.qt_lib
if self.generator in ("MSVC", "MSVC.NET", "BMAKE") and win_shared:
qt_lib = qt_lib + version_to_string(self.config.qt_version).replace(".", "")
if self.config.qt_edition == "non-commercial":
qt_lib = qt_lib + "nc"
libs.append(self.platform_lib(qt_lib, self.config.qt_framework))
libs.extend(self._dependent_libs(self.config.qt_lib))
# Handle header directories.
try:
specd_base = self.config.qt_data_dir
except AttributeError:
specd_base = self.config.qt_dir
specd = os.path.join(specd_base, "mkspecs", "default")
if not os.access(specd, os.F_OK):
specd = os.path.join(specd_base, "mkspecs", self.config.platform)
incdir.append(specd)
qtincdir = self.optional_list("INCDIR_QT")
if qtincdir:
if self.config.qt_version >= 0x040000:
for mod in self._qt:
if mod == "QAxContainer":
incdir.append(os.path.join(qtincdir[0], "ActiveQt"))
elif self._is_framework(mod):
if mod == "QtAssistant" and self.config.qt_version < 0x040202:
mod = "QtAssistantClient"
incdir.append(os.path.join(libdir_qt[0], mod + ".framework", "Headers"))
else:
incdir.append(os.path.join(qtincdir[0], mod))
# This must go after the module include directories.
incdir.extend(qtincdir)
if self._opengl:
incdir.extend(self.optional_list("INCDIR_OPENGL"))
lflags.extend(self.optional_list("LFLAGS_OPENGL"))
libdir.extend(self.optional_list("LIBDIR_OPENGL"))
libs.extend(self.optional_list("LIBS_OPENGL"))
if self._qt or self._opengl:
incdir.extend(self.optional_list("INCDIR_X11"))
libdir.extend(self.optional_list("LIBDIR_X11"))
libs.extend(self.optional_list("LIBS_X11"))
if self._threaded:
libs.extend(self.optional_list("LIBS_THREAD"))
libs.extend(self.optional_list("LIBS_RTMT"))
else:
libs.extend(self.optional_list("LIBS_RT"))
if self.console:
libs.extend(self.optional_list("LIBS_CONSOLE"))
libs.extend(self.optional_list("LIBS_WINDOWS"))
lflags.extend(self._platform_rpaths(rpaths.as_list()))
# Save the transformed values.
self.CFLAGS.set(cflags)
self.CXXFLAGS.set(cxxflags)
self.DEFINES.set(defines)
self.INCDIR.set(incdir)
self.LFLAGS.set(lflags)
self.LIBDIR.set(libdir)
self.LIBS.set(libs)
# Don't do it again because it has side effects.
self._finalised = 1
def _add_manifest(self, target=None):
"""Add the link flags for creating a manifest file.
"""
if target is None:
target = "$(TARGET)"
self.LFLAGS.append("/MANIFEST")
self.LFLAGS.append("/MANIFESTFILE:%s.manifest" % target)
def _is_framework(self, mod):
"""Return true if the given Qt module is a framework.
"""
return (self.config.qt_framework and (self.config.qt_version >= 0x040200 or mod != "QtAssistant"))
def _qt4_module_to_lib(self, mname):
"""Return the name of the Qt4 library corresponding to a module.
mname is the name of the module.
"""
if mname == "QtAssistant":
if self.config.qt_version >= 0x040202 and sys.platform == "darwin":
lib = mname
else:
lib = "QtAssistantClient"
else:
lib = mname
if self._debug:
if sys.platform == "win32":
lib = lib + "d"
elif self.config.qt_version < 0x040200 or sys.platform == "darwin":
lib = lib + "_debug"
if sys.platform == "win32" and "shared" in self.config.qt_winconfig.split():
if (mname in ("QtCore", "QtDesigner", "QtGui", "QtHelp",
"QtNetwork", "QtOpenGL", "QtScript", "QtScriptTools",
"QtSql", "QtSvg", "QtTest", "QtWebKit", "QtXml",
"QtXmlPatterns", "phonon") or
(self.config.qt_version >= 0x040200 and mname == "QtAssistant")):
lib = lib + "4"
return lib
def optional_list(self, name):
"""Return an optional Makefile macro as a list.
name is the name of the macro.
"""
return self.__dict__[name].as_list()
def optional_string(self, name, default=""):
"""Return an optional Makefile macro as a string.
name is the name of the macro.
default is the default value
"""
s = ' '.join(self.optional_list(name))
if not s:
s = default
return s
def required_string(self, name):
"""Return a required Makefile macro as a string.
name is the name of the macro.
"""
s = self.optional_string(name)
if not s:
raise ValueError("\"%s\" must have a non-empty value" % name)
return s
def _platform_rpaths(self, rpaths):
"""Return a list of platform specific rpath flags.
rpaths is the cannonical list of rpaths.
"""
flags = []
prefix = self.optional_string("RPATH")
if prefix:
for r in rpaths:
flags.append(_quote(prefix + r))
return flags
def platform_lib(self, clib, framework=0):
"""Return a library name in platform specific form.
clib is the library name in cannonical form.
framework is set of the library is implemented as a MacOS framework.
"""
if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):
plib = clib + ".lib"
elif sys.platform == "darwin" and framework:
plib = "-framework " + clib
else:
plib = "-l" + clib
return plib
def _dependent_libs(self, clib, framework=0):
"""Return a list of additional libraries (in platform specific form)
that must be linked with a library.
clib is the library name in cannonical form.
framework is set of the library is implemented as a MacOS framework.
"""
prl_libs = []
if self.generator in ("MSVC", "MSVC.NET", "BMAKE"):
prl_name = os.path.join(self.config.qt_lib_dir, clib + ".prl")
elif sys.platform == "darwin" and framework:
prl_name = os.path.join(self.config.qt_lib_dir, clib + ".framework", clib + ".prl")
else:
prl_name = os.path.join(self.config.qt_lib_dir, "lib" + clib + ".prl")
if os.access(prl_name, os.F_OK):
try:
f = open(prl_name, "r")
except IOError:
error("Unable to open \"%s\"" % prl_name)
line = f.readline()
while line:
line = line.strip()
if line and line[0] != "#":
eq = line.find("=")
if eq > 0 and line[:eq].strip() == "QMAKE_PRL_LIBS":
prl_libs = line[eq + 1:].split()
break
line = f.readline()
f.close()
return prl_libs
def parse_build_file(self, filename):
"""
Parse a build file and return the corresponding dictionary.
filename is the name of the build file. If it is a dictionary instead
then its contents are validated.
"""
if type(filename) == dict:
bfname = "dictionary"
bdict = filename
else:
if self._dir:
bfname = os.path.join(self._dir, filename)
else:
bfname = filename
bdict = {}
try:
f = open(bfname, "r")
except IOError:
error("Unable to open \"%s\"" % bfname)
line_nr = 1
line = f.readline()
while line:
line = line.strip()
if line and line[0] != "#":
eq = line.find("=")
if eq <= 0:
error("\"%s\" line %d: Line must be in the form 'name = value value...'." % (bfname, line_nr))
bdict[line[:eq].strip()] = line[eq + 1:].strip()
line_nr = line_nr + 1
line = f.readline()
f.close()
# Check the compulsory values.
for i in ("target", "sources"):
try:
bdict[i]
except KeyError:
error("\"%s\" is missing from \"%s\"." % (i, bfname))
# Get the optional values.
for i in ("headers", "moc_headers"):
try:
bdict[i]