Something inside Qt (Day 1)

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 script
relconf=`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.cpp
g++  -o arch arch.o    
    Found architecture in binary
CFG_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.cpp
g++ -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.cpp
g++  -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.cpp
db2.cpp:34:20: fatal error: sqlcli.h: No such file or directory
compilation terminated.
Makefile:191: recipe for target 'db2.o' failed
make: *** [db2.o] Error 1
DB2 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.cpp

for(p, QMAKE_LIBDIR_EGL) {
    exists($$p):LIBS += -L$$p
}

!isEmpty(QMAKE_INCDIR_EGL): INCLUDEPATH += $$QMAKE_INCDIR_EGL
!isEmpty(QMAKE_LIBS_EGL): LIBS += $$QMAKE_LIBS_EGL

CONFIG -= 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值