Support Qt5 behind --qtver=5 option
Now you can build Mozc with Qt5 behind a build option on OS X. To do
that, add an option as follows.
python build_mozc.py gyp --qtver=5
BUG=#327
TEST=
REF_BUG=26887740
REF_CL=114060144
REF_TIME=2016-02-08T02:32:42+09:00
REF_TIME_RAW=1454866362 +0900
Hiroyuki Komatsu
8 years ago
338 | 338 | parser.add_option('--gypdir', dest='gypdir', |
339 | 339 | help='Specifies the location of GYP to be used.') |
340 | 340 | parser.add_option('--noqt', action='store_true', dest='noqt', default=False) |
341 | parser.add_option('--qtver', dest='qtver', choices=('4', '5'), default='4') | |
341 | 342 | parser.add_option('--version_file', dest='version_file', |
342 | 343 | help='use the specified version template file', |
343 | 344 | default='mozc_version_template.txt') |
487 | 488 | elif target_platform == 'Mac': |
488 | 489 | targets = [SRC_DIR + '/mac/mac.gyp:DiskImage'] |
489 | 490 | elif target_platform == 'Windows': |
491 | # TODO(yukawa, komatsu): Support Qt5 | |
490 | 492 | targets = ['out_win/%s:mozc_win32_build32' % options.configuration] |
491 | 493 | build_dir = os.path.abspath(os.path.join( |
492 | 494 | GetBuildBaseName(options, target_platform), |
672 | 674 | if options.branding: |
673 | 675 | gyp_options.extend(['-D', 'branding=%s' % options.branding]) |
674 | 676 | |
677 | # Qt configurations | |
675 | 678 | if options.noqt or target_platform in ['Android', 'NaCl']: |
676 | 679 | gyp_options.extend(['-D', 'use_qt=NO']) |
677 | 680 | gyp_options.extend(['-D', 'qt_dir=']) |
680 | 683 | gyp_options.extend(['-D', 'qt_dir=']) |
681 | 684 | |
682 | 685 | # Check if Qt libraries are installed. |
683 | system_qt_found = PkgExists('QtCore >= 4.0', 'QtCore < 5.0', | |
684 | 'QtGui >= 4.0', 'QtGui < 5.0') | |
686 | if options.qtver == '5': | |
687 | system_qt_found = PkgExists('Qt5Core', 'Qt5Gui', 'Qt5Widgets') | |
688 | else: | |
689 | system_qt_found = PkgExists('QtCore >= 4.0', 'QtCore < 5.0', | |
690 | 'QtGui >= 4.0', 'QtGui < 5.0') | |
685 | 691 | if not system_qt_found: |
686 | PrintErrorAndExit('Qt4 is required to build GUI Tool. ' | |
692 | PrintErrorAndExit('Qt is required to build GUI Tool. ' | |
687 | 693 | 'Specify --noqt to skip building GUI Tool.') |
694 | ||
688 | 695 | else: |
689 | 696 | gyp_options.extend(['-D', 'use_qt=YES']) |
690 | 697 | if options.qtdir: |
691 | 698 | gyp_options.extend(['-D', 'qt_dir=%s' % os.path.abspath(options.qtdir)]) |
692 | 699 | else: |
693 | 700 | gyp_options.extend(['-D', 'qt_dir=']) |
701 | gyp_options.extend(['-D', 'qt_ver=%s' % options.qtver]) | |
694 | 702 | |
695 | 703 | if options.target_platform == 'Windows' and options.wix_dir: |
696 | 704 | gyp_options.extend(['-D', 'use_wix=YES']) |
47 | 47 | def ParseOption(): |
48 | 48 | """Parse command line options.""" |
49 | 49 | parser = optparse.OptionParser() |
50 | parser.add_option('--qtver', dest='qtver', choices=('4', '5'), default='4') | |
50 | 51 | parser.add_option('--qtdir', dest='qtdir') |
51 | 52 | parser.add_option('--target', dest='target') |
52 | 53 | |
78 | 79 | if not opt.target: |
79 | 80 | PrintErrorAndExit('--target option is mandatory.') |
80 | 81 | |
82 | qtver = opt.qtver | |
81 | 83 | qtdir = os.path.abspath(opt.qtdir) |
82 | 84 | target = os.path.abspath(opt.target) |
83 | 85 | |
84 | 86 | # Changes the reference to QtCore framework from the target application |
85 | 87 | # From: /path/to/qt/lib/QtCore.framework/Versions/4/QtCore |
86 | 88 | # To: @executable_path/../../../MozcTool.app/Contents/Frameworks/... |
87 | qtcore_framework = GetFrameworkPath('QtCore', '4') | |
89 | qtcore_framework = GetFrameworkPath('QtCore', qtver) | |
88 | 90 | InstallNameTool(target, |
89 | 91 | '%s/lib/%s' % (qtdir, qtcore_framework), |
90 | 92 | GetReferenceTo(qtcore_framework)) |
91 | 93 | |
92 | 94 | # Changes the reference to QtGui framework from the target application |
93 | qtgui_framework = GetFrameworkPath('QtGui', '4') | |
95 | qtgui_framework = GetFrameworkPath('QtGui', qtver) | |
94 | 96 | InstallNameTool(target, |
95 | 97 | '%s/lib/%s' % (qtdir, qtgui_framework), |
96 | 98 | GetReferenceTo(qtgui_framework)) |
99 | ||
100 | if qtver == '5': | |
101 | # Changes the reference to QtWidgets framework from the target application | |
102 | qtwidgets_framework = GetFrameworkPath('QtWidgets', '5') | |
103 | InstallNameTool(target, | |
104 | '%s/lib/%s' % (qtdir, qtwidgets_framework), | |
105 | GetReferenceTo(qtwidgets_framework)) | |
97 | 106 | |
98 | 107 | # Change the reference to $(branding)Tool_lib from the target application |
99 | 108 | # From: @executable_path/../Frameworks/MozcTool_lib.framework/... |
48 | 48 | def ParseOption(): |
49 | 49 | """Parse command line options.""" |
50 | 50 | parser = optparse.OptionParser() |
51 | parser.add_option('--qtver', dest='qtver', choices=('4', '5'), default='4') | |
51 | 52 | parser.add_option('--qtdir', dest='qtdir') |
52 | 53 | parser.add_option('--target', dest='target') |
53 | 54 | |
74 | 75 | '%s/%s.framework/Resources' % (target, qtlib), |
75 | 76 | recursive=True) |
76 | 77 | |
77 | # For codesign, Info.plist should be copied to Resources/. | |
78 | CopyFiles(['%s/lib/%s.framework/Contents/Info.plist' % (qtdir, qtlib)], | |
79 | '%s/%s.framework/Resources/Info.plist' % (target, qtlib)) | |
78 | if version == '4': | |
79 | # For codesign, Info.plist should be copied to Resources/. | |
80 | CopyFiles(['%s/lib/%s.framework/Contents/Info.plist' % (qtdir, qtlib)], | |
81 | '%s/%s.framework/Resources/Info.plist' % (target, qtlib)) | |
80 | 82 | |
81 | 83 | |
82 | def ChangeReferences(qtdir, qtlib, version, target, ref_to, references=None): | |
84 | def ChangeReferences(qtdir, path, version, target, ref_to, references=None): | |
83 | 85 | """Change the references of frameworks, by using install_name_tool.""" |
84 | framework_path = GetFrameworkPath(qtlib, version) | |
85 | 86 | |
86 | 87 | # Change id |
87 | 88 | cmd = ['install_name_tool', |
88 | '-id', '%s/%s' % (ref_to, framework_path), | |
89 | '%s/%s' % (target, framework_path)] | |
89 | '-id', '%s/%s' % (ref_to, path), | |
90 | '%s/%s' % (target, path)] | |
90 | 91 | RunOrDie(cmd) |
91 | 92 | |
92 | 93 | if not references: |
98 | 99 | change_cmd = ['install_name_tool', '-change', |
99 | 100 | '%s/lib/%s' % (qtdir, ref_framework_path), |
100 | 101 | '%s/%s' % (ref_to, ref_framework_path), |
101 | '%s/%s' % (target, framework_path)] | |
102 | '%s/%s' % (target, path)] | |
102 | 103 | RunOrDie(change_cmd) |
103 | 104 | |
104 | 105 | |
111 | 112 | if not opt.target: |
112 | 113 | PrintErrorAndExit('--target option is mandatory.') |
113 | 114 | |
115 | qtver = opt.qtver | |
114 | 116 | qtdir = os.path.abspath(opt.qtdir) |
115 | 117 | target = os.path.abspath(opt.target) |
116 | 118 | |
117 | CopyQt(qtdir, 'QtCore', '4', target) | |
118 | CopyQt(qtdir, 'QtGui', '4', target, copy_resources=True) | |
119 | ref_to = '@executable_path/../../../GuiTool.app/Contents/Frameworks' | |
120 | if qtver == '5': | |
121 | CopyQt(qtdir, 'QtCore', '5', target, copy_resources=True) | |
122 | CopyQt(qtdir, 'QtGui', '5', target, copy_resources=True) | |
123 | CopyQt(qtdir, 'QtWidgets', '5', target, copy_resources=True) | |
124 | CopyQt(qtdir, 'QtPrintSupport', '5', target, copy_resources=True) | |
119 | 125 | |
120 | ref_to = '@executable_path/../../../GuiTool.app/Contents/Frameworks' | |
121 | ChangeReferences(qtdir, 'QtCore', '4', target, ref_to) | |
122 | ChangeReferences(qtdir, 'QtGui', '4', target, ref_to, references=['QtCore']) | |
126 | ChangeReferences(qtdir, GetFrameworkPath('QtCore', '5'), | |
127 | '5', target, ref_to) | |
128 | ChangeReferences(qtdir, GetFrameworkPath('QtGui', '5'), | |
129 | '5', target, ref_to, | |
130 | references=['QtCore']) | |
131 | ChangeReferences(qtdir, GetFrameworkPath('QtWidgets', '5'), | |
132 | '5', target, ref_to, | |
133 | references=['QtCore', 'QtGui']) | |
134 | ChangeReferences(qtdir, GetFrameworkPath('QtPrintSupport', '5'), | |
135 | '5', target, ref_to, | |
136 | references=['QtCore', 'QtGui', 'QtWidgets']) | |
137 | ||
138 | libqcocoa = 'QtCore.framework/Resources/plugins/platforms/libqcocoa.dylib' | |
139 | CopyFiles(['%s/plugins/platforms/libqcocoa.dylib' % qtdir], | |
140 | '%s/%s' % (target, libqcocoa)) | |
141 | ChangeReferences(qtdir, libqcocoa, '5', target, ref_to, | |
142 | references=['QtCore', 'QtGui', | |
143 | 'QtWidgets', 'QtPrintSupport']) | |
144 | else: | |
145 | CopyQt(qtdir, 'QtCore', '4', target) | |
146 | CopyQt(qtdir, 'QtGui', '4', target, copy_resources=True) | |
147 | ||
148 | ChangeReferences(qtdir, GetFrameworkPath('QtCore', '4'), | |
149 | '4', target, ref_to) | |
150 | ChangeReferences(qtdir, GetFrameworkPath('QtGui', '4'), | |
151 | '4', target, ref_to, references=['QtCore']) | |
123 | 152 | |
124 | 153 | |
125 | 154 | if __name__ == '__main__': |
916 | 916 | 'postbuild_name': 'Change the reference to frameworks.', |
917 | 917 | 'action': [ |
918 | 918 | 'python', '../build_tools/change_reference_mac.py', |
919 | '--qtver', '<(qt_ver)', | |
919 | 920 | '--qtdir', '<(qt_dir)', |
920 | 921 | '--target', |
921 | 922 | '${BUILT_PRODUCTS_DIR}/GuiTool_lib.framework/Versions/A/GuiTool_lib', |
965 | 966 | '<(PRODUCT_DIR)/GuiTool_lib.framework', |
966 | 967 | ], |
967 | 968 | }, |
969 | 'conditions': [ | |
970 | ['qt_ver==5', { | |
971 | 'mac_bundle_resources': ['../data/mac/qt.conf'], | |
972 | }], | |
973 | ], | |
968 | 974 | # We include this gypi file here because the variables |
969 | 975 | # in a condition cannot be refferred from the gypi file |
970 | 976 | # included outside from the condition. |
976 | 982 | 'postbuild_name': 'Change the reference to frameworks.', |
977 | 983 | 'action': [ |
978 | 984 | 'python', '../build_tools/change_reference_mac.py', |
985 | '--qtver', '<(qt_ver)', | |
979 | 986 | '--qtdir', '<(qt_dir)', |
980 | 987 | '--target', |
981 | 988 | '${BUILT_PRODUCTS_DIR}/<(product_name).app/Contents/MacOS/<(product_name)', |
985 | 992 | 'postbuild_name': 'Copy Qt frameworks to the frameworks directory.', |
986 | 993 | 'action': [ |
987 | 994 | 'python', '../build_tools/copy_qt_frameworks_mac.py', |
995 | '--qtver', '<(qt_ver)', | |
988 | 996 | '--qtdir', '<(qt_dir)', |
989 | 997 | '--target', '${BUILT_PRODUCTS_DIR}/<(product_name).app/Contents/Frameworks/', |
990 | 998 | ], |
34 | 34 | 'sources': [ |
35 | 35 | 'tool/mozc_tool_main.cc', |
36 | 36 | ], |
37 | 'conditions': [ | |
38 | ['qt_ver==5', { | |
39 | 'mac_bundle_resources': ['../data/mac/qt.conf'], | |
40 | }], | |
41 | ], | |
37 | 42 | 'dependencies': [ |
38 | 43 | 'gen_mozc_tool_info_plist', |
39 | 44 | 'mozc_tool_lib', |
43 | 48 | 'postbuild_name': 'Change the reference to frameworks', |
44 | 49 | 'action': [ |
45 | 50 | 'python', '../build_tools/change_reference_mac.py', |
51 | '--qtver', '<(qt_ver)', | |
46 | 52 | '--qtdir', '<(qt_dir)', |
47 | 53 | '--target', |
48 | 54 | '${BUILT_PRODUCTS_DIR}/<(product_name).app/Contents/MacOS/<(product_name)', |
36 | 36 | 'variables': { |
37 | 37 | 'conditions': [ |
38 | 38 | ['target_platform=="Linux"', { |
39 | 'qt_cflags': ['<!@(pkg-config --cflags QtGui QtCore)'], | |
40 | 'qt_include_dirs': [], | |
39 | 'conditions': [ | |
40 | ['qt_ver==5', { | |
41 | 'qt_cflags': ['<!@(pkg-config --cflags Qt5Widgets Qt5Gui Qt5Core)'], | |
42 | 'qt_include_dirs': [], | |
43 | }, { | |
44 | 'qt_cflags': ['<!@(pkg-config --cflags QtGui QtCore)'], | |
45 | 'qt_include_dirs': [], | |
46 | }], | |
47 | ], | |
41 | 48 | }, 'qt_dir', { |
42 | 49 | 'qt_cflags': [], |
43 | 50 | 'qt_include_dirs': ['<(qt_dir)/include'], |
62 | 69 | 'AdditionalLibraryDirectories': [ |
63 | 70 | '<(qt_dir)/lib', |
64 | 71 | ], |
65 | 'AdditionalDependencies': [ | |
66 | 'QtCored4.lib', | |
67 | 'QtGuid4.lib', | |
72 | 'conditions': [ | |
73 | ['qt_ver==5', { | |
74 | 'AdditionalDependencies': [ | |
75 | 'Qt5Cored.lib', | |
76 | 'Qt5Guid.lib', | |
77 | 'Qt5Widgetsd.lib', | |
78 | ], | |
79 | }, { | |
80 | 'AdditionalDependencies': [ | |
81 | 'QtCored4.lib', | |
82 | 'QtGuid4.lib', | |
83 | ], | |
84 | }], | |
68 | 85 | ], |
69 | 86 | }, |
70 | 87 | }, |
75 | 92 | 'AdditionalLibraryDirectories': [ |
76 | 93 | '<(qt_dir)/lib', |
77 | 94 | ], |
78 | 'AdditionalDependencies': [ | |
79 | 'QtCore4.lib', | |
80 | 'QtGui4.lib', | |
95 | 'conditions': [ | |
96 | ['qt_ver==5', { | |
97 | 'AdditionalDependencies': [ | |
98 | 'Qt5Core.lib', | |
99 | 'Qt5Gui.lib', | |
100 | 'Qt5Widgets.lib', | |
101 | ], | |
102 | }, { | |
103 | 'AdditionalDependencies': [ | |
104 | 'QtCore4.lib', | |
105 | 'QtGui4.lib', | |
106 | ], | |
107 | }], | |
81 | 108 | ], |
82 | 109 | }, |
83 | 110 | }, |
97 | 124 | 'mac_framework_dirs': [ |
98 | 125 | '<(qt_dir)/lib', |
99 | 126 | ], |
100 | 'libraries': [ | |
101 | '<(qt_dir)/lib/QtCore.framework', | |
102 | '<(qt_dir)/lib/QtGui.framework', | |
127 | 'conditions': [ | |
128 | ['qt_ver==5', { | |
129 | 'libraries': [ | |
130 | '<(qt_dir)/lib/QtCore.framework', | |
131 | '<(qt_dir)/lib/QtGui.framework', | |
132 | '<(qt_dir)/lib/QtWidgets.framework', | |
133 | ] | |
134 | }, { | |
135 | 'libraries': [ | |
136 | '<(qt_dir)/lib/QtCore.framework', | |
137 | '<(qt_dir)/lib/QtGui.framework', | |
138 | ] | |
139 | }], | |
103 | 140 | ], |
104 | 141 | }, |
105 | 142 | }], |
109 | 146 | ] |
110 | 147 | }], |
111 | 148 | ['target_platform=="Linux"', { |
112 | 'libraries': [ | |
113 | '<!@(pkg-config --libs QtGui QtCore)', | |
149 | 'conditions': [ | |
150 | ['qt_ver==5', { | |
151 | 'libraries': [ | |
152 | '<!@(pkg-config --libs Qt5Widgets Qt5Gui Qt5Core)', | |
153 | ], | |
154 | }, { | |
155 | 'libraries': [ | |
156 | '<!@(pkg-config --libs QtGui QtCore)', | |
157 | ], | |
158 | }], | |
114 | 159 | ], |
115 | 160 | }], |
116 | 161 | # Workarounds related with clang. |
33 | 33 | 'variables': { |
34 | 34 | 'conditions': [ |
35 | 35 | ['target_platform=="Linux"', { |
36 | 'moc_path': '<!(pkg-config --variable=moc_location QtGui)', | |
36 | 'conditions': [ | |
37 | ['qt_ver==5', { | |
38 | 'moc_path': '<!(pkg-config --variable=host_bins Qt5Core)/moc', | |
39 | }, { | |
40 | 'moc_path': '<!(pkg-config --variable=moc_location QtGui)', | |
41 | }], | |
42 | ], | |
37 | 43 | }, 'qt_dir', { |
38 | 44 | 'moc_path': '<(qt_dir)/bin/moc<(EXECUTABLE_SUFFIX)', |
39 | 45 | }, { |
33 | 33 | 'variables': { |
34 | 34 | 'conditions': [ |
35 | 35 | ['target_platform=="Linux"', { |
36 | # seems that --variable=rcc_location is not supported | |
37 | 'rcc_path': '<!(pkg-config --variable=exec_prefix QtGui)/bin/rcc', | |
36 | 'conditions': [ | |
37 | ['qt_ver==5', { | |
38 | 'rcc_path': '<!(pkg-config --variable=host_bins Qt5Core)/rcc', | |
39 | }, { | |
40 | # seems that --variable=rcc_location is not supported | |
41 | 'rcc_path': '<!(pkg-config --variable=exec_prefix QtGui)/bin/rcc', | |
42 | }], | |
43 | ], | |
38 | 44 | }, 'qt_dir', { |
39 | 45 | 'rcc_path': '<(qt_dir)/bin/rcc<(EXECUTABLE_SUFFIX)', |
40 | 46 | }, { |
33 | 33 | 'variables': { |
34 | 34 | 'conditions': [ |
35 | 35 | ['target_platform=="Linux"', { |
36 | 'uic_path': '<!(pkg-config --variable=uic_location QtGui)', | |
36 | 'conditions': [ | |
37 | ['qt_ver==5', { | |
38 | 'uic_path': '<!(pkg-config --variable=host_bins Qt5Core)/uic', | |
39 | }, { | |
40 | 'uic_path': '<!(pkg-config --variable=uic_location QtGui)', | |
41 | }], | |
42 | ], | |
37 | 43 | }, 'qt_dir', { |
38 | 44 | 'uic_path': '<(qt_dir)/bin/uic<(EXECUTABLE_SUFFIX)', |
39 | 45 | }, { |