第一步:準(zhǔn)備
1.下載qt源碼
http://mirrors.ustc.edu.cn/qtproject/official_releases/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.zip
也可以單獨(dú)下載模塊單獨(dú)編譯
single為整體打包皮获,submodule為單獨(dú)源碼編譯。
http://download.qt.io/official_releases/qt
并解壓到C:\qt-everywhere-src-5.15.0
新建目標(biāo)文件夾c:\qt-build-5.15
2.下載Perl解釋器
https://www.activestate.com/activeperl
安裝時(shí)候記得勾選添加到PATH
3.下載Python
安裝時(shí)勾選添加到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查看所有參數(shù)
參數(shù)解釋:https://doc.qt.io/qt-5/configure-options.html
中文解釋:https://www.cnblogs.com/chenfulin5/p/5798764.html
執(zhí)行編譯安裝:(如果MOC出錯(cuò)煌贴,可能是不支持并行)
cmake --build . --parallel && cmake --install .
僅僅編譯base源碼才用到configure刚操,編譯完成后會(huì)生成qmake可執(zhí)行文件。如果是編譯submodule 碰缔,由于其使用自己的qmake編譯系統(tǒng),故需要執(zhí)行qmake xxx.pro,生成makefile逮诲,然后直接nmake執(zhí)行編譯,make install轉(zhuǎn)移到prefix目錄幽告。
如果是編譯6.0的module梅鹦,則通過運(yùn)行(bin已經(jīng)在環(huán)境變量的Path目錄,所以直接qt-configure-module.bat . 就行)
/bin/qt-configure-module.bat .
生成config信息冗锁,然后該子模塊下使用
cmake --build . --parallel && cmake --install .
執(zhí)行編譯齐唆。
參考:https://www.qt.io/blog/qt-6-build-system
第三步:開始編譯
等待configure執(zhí)行完畢,直接輸入 nmake&& nmake install
如果是6.0的Cmake冻河,則輸入指令編譯當(dāng)前目錄并將編譯后文件寫入到指定文件夾
cmake --build . --parallel && cmake --install .
第四步:創(chuàng)建vs項(xiàng)目
安裝qt addin之后箍邮,設(shè)置qt版本為c:\qt-build-5.15目錄, 同時(shí)設(shè)置項(xiàng)目屬性叨叙,在c/c++代碼生成目錄下媒殉,設(shè)置運(yùn)行庫為MT(靜態(tài)庫)或MD(動(dòng)態(tài)庫)。
參考:https://doc.qt.io/qt-5/windows-building.html
附全部參數(shù)
-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