qt configure script

If you want to build qt from source code, the first thing you would do is to run the Qt configure script.

Where is the Qt configure script? The Qt installation directory has a complex structure. If you install Qt in directory c:\Qt5.12.1\, the source code of Qt will be installed in directory c:\Qt5.12.1\5.12.1\Src\. There you can find the configure scripts: configure(for Linux) and configure.bat(for Windows). But those are just wrappers which actually call the configure/configure.bat in c:\Qt5.12.1\5.12.1\Src\qtbase\. Let’s see how the Qt configure script works. Here, we only study configure.bat in Windows.

You can cd to c:\Qt5.12.1\5.12.1\Src to run configure.bat. But that is not necessary. In fact, you can run configure.bat in any directory. For example, you can cd to c:\qtbuild\ and run c:\Qt5.12.1\5.12.1\Src\configure.bat. Now c:\Qt5.12.1\5.12.1\Src\configure.bat will create a directory qtbase in c:\qtbuild, cd to that directory, and call c:\Qt5.12.1\5.12.1\Src\qtbase\configure.bat -top-level

c:\Qt5.12.1\5.12.1\Src\qtbase\configure.bat is much more complex than c:\Qt5.12.1\5.12.1\Src\configure.bat. It mainly does the following work.

Check if the environment variables QMAKESPEC, XQMAKESPEC, QMAKEPATH, QMAKEFEATURES have already been set. If so, exit the configure script because qmake would be confused by these environment variables.

Set TOPQTSRC=c:\Qt5.12.1\5.12.1\Src, QTSRC=c:\Qt5.12.1\5.12.1\Src\qtbase, TOPQTDIR=c:\qtbuild, QTDIR=c:\qtbuild\qtbase

Parse the parameters you provided when running c:\Qt5.12.1\5.12.1\Src\configure.bat. You can specify the platform by providing -platform xxxx or –platform xxxx. It will set the PLATFORM variable to what you specify. For example, if you run “configure.bat -platform win32-g++”, PLATFORM will be set to win32-g++. However, if you specify the platform option as win32-msvc2012, win32-msvc2013, win32-msvc2015, or win32-msvc2017, the PLATFORM variable is set to win32-msvc. If you do not specify a platform, the configure script will try to infer the platform. How does it infer the platform? The platform is the compiler system on your computer. So the script checks if the following compilers exist on your PC: clang-cl.exe, cl.exe, icl.exe, g++.exe, perl.exe, jom.exe. If it finds icl.exe, the PLATFORM is set to win32-icc. If it finds cl.exe, the PLATFORM is set to win32-msvc. If it finds clang-cl.exe, the PLATFORM is set to win32-clang-msvc. If it finds g++.exe, the PLATFORM is set to win32-g++. Multiple compilers may co-exist on your computer. So the PLATFORM is determined in the above order, i.e., if both cl.exe and g++.exe are detected on your PC, the PLATFORM is set to win32-msvc, not  win32-g++. The script will abort if none of the compilers is detected.

Even the script detects one of the compilers, the configure script may also fail if the corresponding make spec is not found. For example, if the script detected g++.exe, but c:\Qt5.12.1\5.12.1\Src\qtbase\mkspecs\win32-g++\qmake.conf does not exist, the configuration script aborts.

The PLATFORM also determines the value of MAKE and tmpl. For win32-g++ platform, MAKE is set to mingw32-make and tmpl is set to unix. For other platforms, MAKE is set to nmake unless the script detected the existence of jom.exe, in which case MAKE is set to jom. tmpl is set to win32. You can bypass the determination process of MAKE by providing the -make-tool xxxx option to the configure.bat script.

Next, the configure script creates 3 directories in your build directory c:\qtbuild\qtbase\: mkspecs, bin, qmake, and cd to qmake to create a Makefile in that directory. The Makefile is used to generate qmake.exe. The configure script fills the Makefile with information from several sources. First, it reads the Qt versions from c:\Qt5.12.1\5.12.1\Src\qtbase\.qmake.conf, and writes the versions to the Makefile. Then, it copies the content of the Makefile templates into the Makefile. For example, if the tmpl is unix, three Makefile templates: c:\Qt5.12.1\5.12.1\Src\qtbase\qmake\Makefile.unix.win32, c:\Qt5.12.1\5.12.1\Src\qtbase\qmake\Makefile.unix.mingw, and c:\Qt5.12.1\5.12.1\Src\qtbase\qmake\Makefile.unix will be copied to the Makefile. After constructing the Makefile, the script runs the MAKE program in c:\qtbuild\qtbase\qmake\. For example, it will run mingw32-make under that directory. At this stage, you’ll see the familiar compiler commands running such as g++ ….. The generated intermediate files such as the .obj files are put in c:\qtbuild\qtbase\qmake\. The compiling process takes some time. Finally, the generated qmake.exe is put in c:\qtbuild\qtbase\bin\. After making qmake.exe, the configure script also generates a file c:\qtbuild\qtbase\bin\qt.conf.

Now qmake.exe is available, the configure script cds to c:\qtbuild\ and executes qmake.exe in that directory. The configure script completes its task and the following configuration work is done by qmake.exe. configure.bat only consumes a few arguments and passes most of the arguments to qmake.exe.

To summarize, although the Qt configure script appears complex, it does few things. What the configure script does is to prepare for the qmake including building qmake.exe and creating qt.conf that is used by qmake.exe.

 

 

 

 

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply