Because this is the environment for Qt as a graphical interface development, heretics have recorded the experience of building Qt 4.6.3 before themselves; However, later, because they decided to get rid of the Qt SDK provided by Qt for construction and factory development, the official knowledge studied how to build it by themselves.
However, when GitLab CI/CD is introduced, it becomes to study how to install Qt SDK in Windows Docker.
After playing this part, I found that Qt is really great here... I thought there was no problem after the first time, but later Qt kept modifying his program installation, which often led to the cancellation and modification of the script for installing Qt SDK when it was necessary to rebuild the Docker image (2020 / 02)
Later, Qt directly removed the required installation program, used the online installation version, and then the download speed was too slow
So later, heretics had to study how to build Qt by themselves.
The version used this time is Visual Studio 2019, and the built Qt version is Qt 6.1.0. The original code can be downloaded from the official website (the page and download speed are very slow).
Prepare the build environment
According to the official Qt for Windows - Building from Source, you have built the Qt SDK. In addition to Visual Studio 2019, you also need the following tools:
CMake 3.16 + (official website)
Ninja (official website)
Perl (Heresy uses Strawberry Perl)
Python 3 (official website)
Because heretics build Qt through Docker, the tools needed are also written as Dockerfile to play ~
The following is the Dockerfile that can be disassembled and built for Qt 6.1.0:
#Escape=` # Use the latest Windows Server Core Image and NET Framework 4.8. from mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-20H2 # Restore the default Windows shell for proper batch processing. SHELL ["cmd", "/S", "/C"] # Download the Build Tools 2019 bootstrap. add to https://aka.ms/vs/16/release/vs_buildtools.exe C:TEMPvs_buildtools.exe add to https://aka.ms/vs/16/release/channel C:TEMPVisualStudio.chman # Install build tools, excluding workloads and components with known problems. function C:TEMPvs_buildtools.exe --quiet --wait --norestart --nocache ` --channelUri C:TEMPVisualStudio.chman ` --installChannelUri C:TEMPVisualStudio.chman ` --installPath C:BuildTools ` --add Microsoft.VisualStudio .Workload.VCTools ` --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 ` --add Microsoft.VisualStudio.Component.VC.ATLMFC ` --add Microsoft.VisualStudio.Component.Windows10SDK.19041 # Install 7-Zip add to https://www.7-zip.org/a/7z1900-x64.exe C:TEMP7z.exe function C:TEMP7z.exe /S /D=C:7Zip # Download CMake add to https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2-windows-x86_64.msi C:TEMPcmake.msi RUN C:TEMPcmake.msi /qn # Install Perl add to https://strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-64bit.msi C:TEMPstrawberry-perl.msi RUN C:TEMPstrawberry-perl.msi /qn # Install Python add to https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe C:TEMPpython.exe RUN c:temppython.exe /quiet InstallAllUsers=1 PrependPath=1 # Download Ninja add to https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip C:TEMPninja.zip RUN C:7Zip7z.exe x C:TEMPninja.zip -y -oc:ninja # Clean up downloaded files Run delete C:TEMP* /q # Add path RUN setx /M "path" "%path%;c:ninja;C:7Zip;C:Strawberryperlbin;C:Program FilesCMakebin" # Launch the developer command prompt with any other command you specify. entry point c:BuildToolsVCAuxiliaryBuildvcvars64.bat &&
After that, just execute:
docker build -t qtbuilder S:qtbuilder
You can create a Docker image called "qtbuilder" and support the construction of Qt SDK.
Of course, if you don't want to build with Docker, you can also install the above software directly on the computer, but just remember the path so that the system can find the program execution of the above environment.
Construction process
Ready to build
Next, we are going to start building ~ the first is the source code decompression of Qt.
Unzip it as "src-0.0-everywhere-0.6.ryt: where" after downloading it.
Then, the container of Docker is established and prepared to build ~
docker run -it --rm --isolation process --storage-opt size=64G -v S:qt-everywhere-src-6.1.0 :c:code qtbuilder cmd
This is the source code of Qt, which corresponds to the c:code path in Docker for access; So if the path is different, please modify the part of the scarlet letter by yourself.
In addition, it should be noted that building Qt will require a lot of hard disk space, so this article also increases the hard disk space inside Docker through "– storage opt size = 64g" (the default parameter should be 20GB). Otherwise, the problem of insufficient hard disk space will occur when building Qt itself; If you don't want to play in your own space, you have to control the volume mapping and relative path.
After entering Docker, execute the following instructions first:
mkdir c:build_debug c:build_release cd c:code_output cd c: build_debug c:codeconfigure -prefix c:code_output -debug cd c:build_release c:codeconfigure -prefix c:code_output -release
Three folders will be created here, build_debugļ¼build_release and_ output, the first two are used to place the files related to the construction process. One is the debugging version and the other is the distribution version.
Then there is the final Qt SDK file. This C:code is to sort the last required file into the external folder "s:qt-everywhere-src-6.1.0"; If you delete it directly like the other two data folders, the docker will disappear as soon as you close it.
The configuration part is to generate the files required by CMake through the script provided by Qt; "- prefix c:code_output build" in this article specifies when and where the library files will be built; The last "- debug" or "- release" tells it to build a debug or release.
If you like to build, debug and release one, just choose one.
For other parameters, please refer to the official documents.
Start building
After the above configuration is completed, you can build different versions in order.
In terms of debugging board, it is to execute:
cd c:build_debug cmake --build . cmake --install .
Start the debugging of building Qt SDK.
As Qt has made a clever function library to simulate hypertrophy, the construction process of this story will take time. It is suggested to find a better idle computer to run.
Among them, cmake build is to start the construction. After the construction is completed, the files will be scattered, which is trouble to deal with; Next, execute cmake --install and ask him to copy (install) the necessary files to the specified output location (_output), which can be used easily.
Heresy means that the output of the original version is set to the same as that of the original version. After running, you can put the real inspiration and results together.
So after the debug version is built, just execute:
cd c:build_release cmake --build . cmake --install .
You can build the release.
When the re is complete, you can turn off docker; At this point, you can find the Qt 6.1.0 SDK that can be built under "s: QT everywhere src-6.1.0_output"
The file constructed by heresy is about 2.6GB in size... Well, it's very reassuring ~ XD
note appended:
The README in the downloaded Qt 6.1.0 is still written Qt5... orz
The requirements written in it are also different.
Although the configuration provided by Qt can specify the "- debug and release" requirement to build debugging and release versions at the same time; However, although two versions were built at the same time in the process of cmake build, when he was asked to copy the file to the output path (cmake install), he only copied the version
Therefore, this paper still adopts the method of copying construction but setting.