作者:Loaden
转自:http://bbs.youkuaiyun.com/topics/380072935
Qt5的编译官方有一篇wiki:http://developer.qt.nokia.com/wiki/Building_Qt_5_from_Git
简要的总结下我的体会,欢迎补充完善、批评指正。
1.First clone the top-level qt5 git repository:
1
|
git clone git:
//gitorious.org/qt/qt5.git qt5
|
这一行不用说了,自然是将Qt5的代码克隆。不过,如果你只是初次克隆Qt5的代码,会很惊讶:为何克隆后的代码只有十几MB?
原来,Qt5已经实现了Qt的模块化,详见: http://labs.qt.nokia.com/2011/05/12/qt-modules-maturity-level-the-list/
所以可以在克隆得到的Qt5源码根目录下看到:.gitmodules 文件,其内容部分摘录如下:
1
2
3
4
5
6
7
8
9
10
|
[submodule
"qtbase"
]
path = qtbase
url = git:
//gitorious.org/qt/qtbase.git
[submodule
"qtsvg"
]
path = qtsvg
url = git:
//gitorious.org/qt/qtsvg.git
[submodule
"qtdeclarative"
]
path = qtdeclarative
url = git:
//gitorious.org/qt/qtdeclarative.git
...
|
这时,有Git基础的朋友一定会想到:
1
2
|
git submodule init
git submodule update
|
不过,请不要这样做!
2. Following the README file we initialize the repository. This clones the various sub-modules of Qt5:
1
|
./init-repository
|
这是一个perl脚本。如果是在msys-git下,会发现Perl的版本不够。
我们需要安装一个Windows版本的Perl: http://www.activestate.com/activeperl/downloads
安装好以后,Perl就添加到PATH环境变量中去了。
在MSVC的控制台下执行:
1
|
perl init-repository --help
|
注意,不是直接执行init-repository,要用perl来执行它。看看帮助:大致了解下有哪些功能。
3. 注意它的三个小提示:
1
2
3
|
Hint1: If you’re going to contribute to Qt 5, you’ll need to pass the —codereview-username <Jira/Gerrit username> option to set up a “gerrit” remote
for
all the sub-modules.
Hint2: If you’re having problems downloading the webkit repository (which is quite big), you can pass —no-webkit.
Hint3: If you’re behind a firewall, pass —http
|
4. 我的方法:
1
|
perl init-repository -f --codereview-username loaden
|
这样就可以实现子模块的批处理了。特别要注意的是:在处理这些子模块时,其实是git clone了这些子模块,以致于他们可以独立使用。在qt5\qtbase目录下可以找到.git目录。
这与git submodule update的结果是不一样的!!
同时我使用了codereview的用户名,是为了可以创建一个名为gerrit的远程仓库,可以将贡献的代码推送进去,类似:
1
|
git push gerrit HEAD:refs/
for
/master
|
5. 源码下载是非常慢的,因为QtWebkit达到了1.7GB。源码下载完成后,进入Qt5源码目录,配置环境变量:
1
|
set PATH=%CD%\qtbase\bin;%PATH%
|
之后echo看一下结果是否正确:
1
|
echo %PATH%
|
6. 建议直接在Qt5的源码目录下执行配置!
1
|
configure -confirm-license -opensource -release -shared -platform win32-msvc2010 -fast -no-stl -no-qt3support -nomake examples -nomake demos -nomake tests
|
7. 编译全部模块,直接执行nmake就可以了。如果只编译一个模块,可以这样:
1
|
nmake module-qtbase
|
双击打开Qt5目录下的Makefile文件,可以看到有这些模块:
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
|
SUBTARGETS = \
module-qtbase \
module-qtsvg \
module-qtphonon \
module-qtxmlpatterns \
module-qtdeclarative \
module-qttools \
module-qttranslations \
module-qtdoc \
module-qlalr \
module-qtqa \
module-qtlocation \
module-qtactiveqt \
module-qtsensors \
module-qtsystems \
module-qtmultimedia \
module-qtfeedback \
module-qtquick3d \
module-qtdocgallery \
module-qtpim \
module-qtconnectivity \
module-qtwayland \
module-qtjsondb \
sub-qtwebkit-pri \
module-qtwebkit-examples-and-demos
|
欢迎交流!