第一步:准备
1.下载qt源码
http://mirrors.ustc.edu.cn/qtproject/official_releases/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.zip
也可以单独下载模块单独编译
single为整体打包,submodule为单独源码编译。
http://download.qt.io/official_releases/qt
并解压到C:\qt-everywhere-src-5.15.0
新建目标文件夹c:\qt-build-5.15
2.下载Perl解释器
https://www.activestate.com/activeperl
安装时候记得勾选添加到PATH
3.下载Python
安装时勾选添加到PATH
第二步:生成makefile文件
打开Native tools command prompt for vs 2019
cd到C:\qt-everywhere-src-5.15.0文件夹下
qt5
configure -confirm-license -opensource -platform win32-msvc -debug-and-release -force-debug-info -prefix "C:\\Users\\Documents\\code\\qt-5.15.1" -qt-sqlite -qt-pcre -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -skip qtwebengine -nomake tests -nomake examples -mp -no-feature-accessibility -no-feature-networklistmanager -c++std c++20
qt6
configure -c++std c++20 -debug-and-release -force-debug-info -prefix "C:\\Qt\\qt-6.1-build-32" -system-sqlite -system-zlib -nomake tests -nomake examples -no-feature-accessibility -no-feature-lcdnumber -no-feature-hijricalendar -no-feature-islamiccivilcalendar -no-feature-jalalicalendar -no-feature-movie -no-feature-networklistmanager -- -DCMAKE_OBJECT_PATH_MAX=260 -DBUILD_qttools=OFF
通过configure -h查看所有参数
参数解释:https://doc.qt.io/qt-5/configure-options.html
中文解释:https://www.cnblogs.com/chenfulin5/p/5798764.html
执行编译安装:(如果MOC出错,可能是不支持并行)
cmake --build . --parallel && cmake --install .
仅仅编译base源码才用到configure,编译完成后会生成qmake可执行文件。如果是编译submodule ,由于其使用自己的qmake编译系统,故需要执行qmake xxx.pro,生成makefile,然后直接nmake执行编译,make install转移到prefix目录。
如果是编译6.0的module,则通过运行(bin已经在环境变量的Path目录,所以直接qt-configure-module.bat . 就行)
/bin/qt-configure-module.bat .
生成config信息,然后该子模块下使用
cmake --build . --parallel && cmake --install .
执行编译。
参考:https://www.qt.io/blog/qt-6-build-system
第三步:开始编译
等待configure执行完毕,直接输入 nmake&& nmake install
如果是6.0的Cmake,则输入指令编译当前目录并将编译后文件写入到指定文件夹
cmake --build . --parallel && cmake --install .
第四步:创建vs项目
安装qt addin之后,设置qt版本为c:\qt-build-5.15目录, 同时设置项目属性,在c/c++代码生成目录下,设置运行库为MT(静态库)或MD(动态库)。
参考:https://doc.qt.io/qt-5/windows-building.html
附全部参数
-opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtcharts -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -no-feature-texthtmlparser -no-feature-textodfwriter -no-feature-concurrent -no-feature-effects -no-feature-sharedmemory -no-feature-systemsemaphore -no-feature-im -no-feature-process -no-feature-dom -no-feature-filesystemmodel -no-feature-filesystemwatcher -no-feature-graphicsview -no-feature-graphicseffect -no-feature-sizegrip -no-feature-calendarwidget -no-feature-printpreviewwidget -no-feature-keysequenceedit -no-feature-colordialog -no-feature-filedialog -no-feature-fontdialog -no-feature-printpreviewdialog -no-feature-progressdialog -no-feature-inputdialog -no-feature-errormessage -no-feature-wizard -no-feature-datawidgetmapper -no-feature-imageformat_bmp -no-feature-imageformat_ppm -no-feature-imageformat_xbm -no-feature-imageformat_png -no-feature-imageformat_jpeg -no-feature-image_heuristic_mask -no-feature-image_text -no-feature-colornames -no-feature-cups -no-feature-paint_debug -no-feature-freetype -no-feature-translation -no-feature-codecs -no-feature-big_codecs -no-feature-iconv -no-feature-ftp -no-feature-udpsocket -no-feature-networkproxy -no-feature-socks5 -no-feature-networkdiskcache -no-feature-bearermanagement -no-feature-completer -no-feature-fscompleter -no-feature-desktopservices -no-feature-mimetype -no-feature-systemtrayicon -no-feature-undocommand -no-feature-undostack -no-feature-undogroup -no-feature-undoview -no-feature-statemachine -no-feature-gestures -no-feature-dbus
////linux ubuntu 64
./configure -developer-build -confirm-license -opensource -linuxfb -prefix "/home/qt-5.15-build" -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdeclarative -skip qtdoc -skip qtgamepad -skip qtgraphicaleffects -skip qtimageformats -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtquickcontrols -skip qtquickcontrols2 -skip qtscript -skip qtscxml -skip qtsensors -skip qtserialbus -skip qtserialport -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtvirtualkeyboard -skip qtwayland -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns