Something inside Qt (Day 1)

来源:互联网 发布:成本估算软件 编辑:程序博客网 时间:2024/06/06 12:52

Question

What does Qt do after you ./configure when compiling Qt?

Tools

Qt source code, and configure output(with -v when ./configure).

configure

configure file is in fact a shell. Just like this:

#!/bin/sh#-------------------------------------------------------------------------------# script initialization#-------------------------------------------------------------------------------# the name of this scriptrelconf=`basename $0`# the directory of this script is the "source tree"relpath=`dirname $0`relpath=`(cd "$relpath"; /bin/pwd)`# the current directory is the "build tree" or "object tree"outpath=`/bin/pwd`...

This file tells us everything about configuring Qt.

First

Build qmake. Qt uses qmake to manage dependency, build and deployment. So building qmake is the very first thing to do. It calls g++ to compile source code in qtbase/qmake/, change .h&&.cpp into .o and put all .o file into executable file qmake in qtbase/bin.

g++ -o "../bin/qmake" project.o option.o property.o main.o ioutils.o proitems.o qmakevfs.o qmakeglobals.o qmakeparser.o qmakeevaluator.o qmakebuiltins.o makefile.o unixmake2.o unixmake.o mingw_make.o winmakefile.o projectgenerator.o meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o msvc_vcproj.o msvc_vcxproj.o msvc_nmake.o msvc_objectmodel.o msbuild_objectmodel.o cesdkhandler.o qtextcodec.o qutfcodec.o qstring.o qstring_compat.o qstringbuilder.o qtextstream.o qiodevice.o qdebug.o qmalloc.o qglobal.o qarraydata.o qbytearray.o qbytearraymatcher.o qdatastream.o qbuffer.o qlist.o qfiledevice.o qfile.o qfilesystementry.o qfilesystemengine.o qfsfileengine.o qfsfileengine_iterator.o qregexp.o qvector.o qbitarray.o qdir.o qdiriterator.o quuid.o qhash.o qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o qmap.o qmetatype.o qsettings.o qsystemerror.o qlibraryinfo.o qvariant.o qvsnprintf.o qlocale.o qlocale_tools.o qlinkedlist.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o qlogging.o qjson.o qjsondocument.o qjsonparser.o qjsonarray.o qjsonobject.o qjsonvalue.o qfilesystemengine_unix.o qfilesystemiterator_unix.o qfsfileengine_unix.o qlocale_unix.o  -Wl,--gc-sections

This is one of the compile outputs, after which qmake exists in qtbase/bin.

About qmake

qmake is more than a simple tool to generate Makefile. It contains essential env for Qt, including include_path, lib_path(of course Qt libs). That means, if you need to write a simple program using Qt libs, you don’t need to specify Qt lib_path if using qmake, just QT += widgets for example.

So, if you change the absolute path of qmake after building, qmake will no more work.

Second

Running configuration tests. Test code is in qtbase/config.tests. It does a lot of tests one by one, like this:

Determining architecture... ()g++ -c -pipe -g -Wall -W -fPIC  -I. -I../../mkspecs/linux-g++ -o arch.o arch.cppg++  -o arch arch.o        Found architecture in binaryCFG_ARCH="x86_64"CFG_CPUFEATURES=" mmx sse sse2"System architecture: 'x86_64'Host architecture: 'x86_64'C++11 auto-detection... ()g++ -c -pipe -O2 -std=c++0x -Wall -W -fPIC  -I. -I../../../mkspecs/linux-g++ -o c++11.o c++11.cppg++ -Wl,-O1 -o c++11 c++11.o    C++11 enabled.sse2 auto-detection... ()g++ -c -pipe -msse2 -g -Wall -W -fPIC  -I. -I../../../mkspecs/linux-g++ -o sse2.o sse2.cppg++  -o sse2 sse2.o    sse2 enabled....DB2 auto-detection... ()g++ -c -pipe -O2 -Wall -W -fPIC  -I. -I../../../mkspecs/linux-g++ -o db2.o db2.cppdb2.cpp:34:20: fatal error: sqlcli.h: No such file or directorycompilation terminated.Makefile:191: recipe for target 'db2.o' failedmake: *** [db2.o] Error 1DB2 disabled....

These tests are just like Qt source code’s guard. The guard detects the system and find if there exists some libs. If the essential libs are of absence, it will throw error and stop building.

So, how does it detect the system? Give an example of EGL,

“egl.cpp”

#include <EGL/egl.h>int main(int, char **){    EGLint x = 0;    EGLDisplay dpy = 0;    EGLContext ctx = 0;    eglDestroyContext(dpy, ctx);    return 0;}

“egl.pro”

SOURCES = egl.cppfor(p, QMAKE_LIBDIR_EGL) {    exists($$p):LIBS += -L$$p}!isEmpty(QMAKE_INCDIR_EGL): INCLUDEPATH += $$QMAKE_INCDIR_EGL!isEmpty(QMAKE_LIBS_EGL): LIBS += $$QMAKE_LIBS_EGLCONFIG -= qt

In fact, test code contains no logic code. It only include egl.h file to see whether it will throw errors.

From this special example, we know that if you want to use EGL, QMAKE_INCDIR_EGL and QMAKE_LIBS_EGL are very important, which must be specified in some file.

It then will print the configure result list and generate Makefile.

About config.tests

config.tests can determine yes or no for some env. Besides, in ./configure -opengl desktop …, those parameters after ./configure does the same. More over, you can directly edit configure file to change some env’s default value.

Third

Then start to make.

Tips

There are two important env in configure file: PLATFORM and XPLATFROM. PLATFORM is to specify which gcc to compile qmake, while XPLATFROM specify which gcc to compile test demo. The former is for the first step, and the latter is for the second step. [7.12]

0 0