Tuesday, April 15, 2014

[Qt] Compiling Qt5.2.1 on Windows 8/VS 2013


Qt5. It's a miasma. It's a beast for me. It's something mysterious. I don't know if I should love Qt5 or hate it.
And I think that summarizes my thoughts about Qt5.

I first stumbled across the fifth iteration when some functionality in the product I was working on couldn't be done in existing Qt version (4.5.3 btw). So after looking around for the Oracle, I came to know that the functionality can be achieved by moving to Qt5.

Now our development platform (WinXP/CentOS 5.3/ Qt 4.5.3) was getting a bit too old. And it was all quite buggy to boot. So we decided to embark on the adventure of upgrading the base. Took us two months to upgrade the Linux side to CentOS6.3/ Qt5.0.1 and port the product to new Qt. But after that other high priority work kept us busy and we never got to get the Windows side up to speed.

But then came the fateful day two weeks ago when our IT Manager announced the upgradation of all our faithful old XP systems into Windows 8. And then as it happens, people go ahead and nobody asks the actual user, our PC's were upgraded to Win 8.


Now think, in the old workflow, we would develop on Win XP. And then do unit testing for both Windows and Linux. Usually Linux would need a few tweaks and that would end the development. We didn't have any development tools on Linux. We stuck to the faithful Visual Studio 2005. And it did work.

And now suddenly we are handed Windows 8 and the polished and shiny Visual Studio 2013. But nobody bothered to ask whether this combo was even desirable. So it came to our notice that we can't develop anything because...1. We don't have a compatible Qt version, 2. Visual Studio 2013 needs vsxprojects and the conversion from 2005 vcproj files somehow doesn't work at all. 3. We have by now turned into spittering globs of bio-mechanical matter who are so useless that we should be flushed into space if we are to be in a spaceship!!!

Thankfully the genius in us found a solution and set up virtual machines of XP with all our poor stuff and so we resumed work. But the shiny new windows 8 was still sitting there with next to useless Visual Studio 2013. And we had to do something about it. So I cleared some time (about a week) in my schedule (mind you it's not much crowded anyway!!! :D ) and started on this journey.

1. Prerequisites:
Building full Qt5 (with QtWebkit ) on Windows needs a lot of stuff. And sadly we needed QtWebkit for a few webviews that we have been using in our product. So the requirements:
[Qt pre-requisites]
DirectX SDK - needed for OPENGL/ANGLE stuff.
Windows SDK - Better to have it, But Windows SDK 8 failed to install. The turd would hang on one Cab file thet it couldn't download and it would quit. Sucks!

[Qt webkit pre-requisites]
Perl - install latest Active Perl. Add path to binary to Path Env Variable.
Python - install latest Python. Add path to Python binary to Path Env Variable.
Ruby - install latest Ruby too. Add path to Ruby binary to Path Env Variable.
Cygwin with make utility - Needed to build icu. Add path to cygwin bin to Path Env Variable.
ICU - Needed by QtWebkit. If you can get a binary icu lib well and good. But there was nothing for use with Visual Studio 2013.
Flex-Bison - Install flex-bison package. Add path to Path Env Variabl. Rename Win-flex and Win-bison to flex and bison respectively. Otherwise webkit builder complains about missing flex and bison.
gnuwin32 - Install the gnuwin32 package for gperf tool. Also add path to gperf binary to Path Env Variable.

2. Building:

A. Build ICU:

Following link includes proper instructions for building ICU for use with Qt:
http://qt-project.org/wiki/Compiling-ICU-with-MSVC

B. Build Qt:
For building Qt, I have prepared a script:
---------------------
:: BuildQt5
:: Run this from VS command prompt
set QTSRC=D:\QtSource\qtsrc-5.2.1
set QTBUILD=D:\QtSource\qt-5.2.1_build
set QMAKESPEC=win32-msvc2013
set PATH=%PATH%;C:\icu\dist\lib
set INCLUDE=%INCLUDE%;C:\icu\dist\include
set LIB=%LIB%;C:\icu\dist\lib
cd %QTBUILD%
%QTSRC%\configure -developer-build -opensource -nomake examples -nomake tests -plugin-sql-psql -I "C:\Program Files (x86)\PostgreSQL\9.1\include" -L "C:\Program Files (x86)\PostgreSQL\9.1\lib" -l libpq -debug-and-release -mp -confirm-license -prefix c:\Qt-5.2.1
:: nmake
:: nmake install
cd ..
---------------------
I run this in three phases; first keeping the configure line and let it configure Qt. Once I have all required options properly configured, I run nmake and later nmake install phases.
I am adding PostgreSQL database as plugin. Depending on your use you can add other databases like mySQL too.

Getting this configuration right was a major step. Then Qt normally takes about 3-4 hrs depending on your system. Mind you, this is whole Qt building. If you know exactly which modules you need, then you can just build those modules too.

Once Qt is built, I compile a small program like Hello World and confirm it working.

C. Build QtWebkit:
Previously QtWebkit would build along with Qt itself. But in Qt5 the developers have removed QtWebkit module as well as the switches or selecting / un-selecting it. The dependencies are ICU, Perl, Ruby, Python, gperf.

To build QtWebkit, first you need to build Webkit.

cd to %QTSOURCE%/qtwebkit
Ensure ICU library details are provided in environment:

set PATH=%PATH%;C:\icu\dist\lib
set INCLUDE=%INCLUDE%;C:\icu\dist\include
set LIB=%LIB%;C:\icu\dist\lib

Next, set path to sqlite sources:
SET SQLITE3SRCDIR=D:\QtSource\qtsrc521\qtbase\src\3rdparty\sqlite

And then, run the perl script to build webkit:
perl Tools\Scripts\build-webkit --qt --debug --no-webkit2

Then build QtWebkit:
qmake WebKit.pro
qmake
nmake

And if everything works out
nmake install

This will install QtWebkit module.

E. System configuration:
To use this Qt you need to do couple of settings:
1. Add Qt bin and lib paths to Path environment variable.
2. Create a new system environment variable QTDIR and assign it the path of Qt directory.

F. Build Qt Creator; Qwt etc
For all these the steps are simple:
cd to Source dir
qmake project file
qmake
nmake
nmake install

Or if you want to go via visual studio then
qmake -tp vc "project file"

This would generate the required vcxproj file which you can open with VS2013.

3. Test installed Qt.
Go to Qt sources and try out various examples provided in the modules. See if they build without any issues. This should give you confidence that Qt is built correctly and there's no problem anywhere.

Note: There are changes around with respect to integration with COM components and so if your project is using some COM components then you will get some errors like

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\INCLUDE\atliface.h
(80) : warning C4091: '' : ignored on left of 'interface' when no variable is de
clared
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\INCLUDE\atliface.h
(86) : error C2146: syntax error : missing ';' before identifier 'IAxWinAmbientD
ispatch'

In this case adding following
DEFINES +=NOMINMAX WIN32_LEAN_AND_MEAN
to pro file may help. And you may also need to revise the include order for the files.

No comments:

Post a Comment