Friday, March 14, 2014

Building PoDoFo for Qt using MinGW

It is better to use the shipped MinGW in Qt, if you are going to use it in a Qt project. Open a command line by either typing mingw on your windows search or locate the installed Qt folder; then run inside an opened command line the following file: bin/qtenv2.bat. This will nicely setup your environment to use the MinGW shipped with Qt.

Better yet, use MSYS (http://www.mingw.org/wiki/Getting_Started).

Install the cool synaptic-like tool (mingw-get-setup.exe) to install MSYS and friends.
Then use it to install MSYS. No need to install MinGW because we will use the ones shipped with Qt.
Lastly, point the location of MinGW to the one that Qt ships with. This is important to avoid potential headaches. Create fstab inside /etc/:
#Win32_Path Mount_Point
d:/ProgramData/Qt/Tools/mingw48_32 /mingw

Dependencies

zlib (http://www.zlib.net/)

Qt already has zlib so no need to build for this. Yey!
Or, if you want to use the latest:
Download the windows compiled dll zip.
As stated in USAGE.txt, you can run the following to create a static library:
dlltool -D zlib1.dll -d lib/zlib.def -l lib/libzdll.a 

libjpeg (http://www.ijg.org/)

Using msys, just do the standard compilation jutsu:
./configure --prefix=/mingw
make
make install

libtiff (http://www.remotesensing.org/libtiff/build.html)

Using msys, just do the standard compilation jutsu:
./configure --prefix=/mingw --with-jpeg-include-dir=/mingw/include --with-jpeg-lib-dir=/mingw/lib
make
make check
make install

freetype (http://freetype.sourceforge.net/index2.html)

Using msys, just do the standard compilation jutsu:
./configure --prefix=/mingw --host=i686-pc-mingw32
make
make install

Ignore the rmdir errors..

PoDoFo

openssl 

Use the tar in msys so that the symbolic references will be preserved.
Using msys, just do the standard compilation jutsu:
./config
make
make test

libpng (http://libpng.sourceforge.net/index.html)

Copy makefile.msys from scripts/ to the package root directory with name Makefile.
Then just run make.

Cmake (http://www.cmake.org/files/v2.8/)

Because of a bug in the latest cmake (or the build script of PoDoFo is outdated..), we must use an older version: 2.8.3. http://www.daniweb.com/software-development/cpp/threads/438435/windres.exe-invalid-option-w-

Finally, to build PoDoFo itself

Create a podofo build dir:

mkdir podofo-debug

Run cmake for mingw:
podofo-debug>cmake.exe -G "MinGW Makefiles" ..\podofo-src -DCMAKE_INCLUDE_PATH=<Qt mingw install dir>\include;<Qt mingw install dir>\i686-w64-mingw32\include -DCMAKE_LIBRARY_PATH=<Qt mingw install dir>\lib;<Qt mingw install dir>\i686-w64-mingw32\lib -DPODOFO_BUILD_SHARED:BOOL=FALSE

Run make.
Extract headers and libraries built.

ToDo:
For release, libjpg-9.dll is searched by windows, I don't know the reason yet..
libjpg-9.dll is located in .libs/ of the libjpg build.