Showing posts with label qt. Show all posts
Showing posts with label qt. Show all posts

Friday, February 14, 2014

Build Qt5 Statically with Visual C++ 2013

1. ICU

1.1 Prerequisites

  • Download Cygwin installer from here
  • Install Cygwin and make sure make package is selected

1.2 Download ICU

  • Download ICU from here
  • Extract the zip file to C:\build\icu and make sure folder C:\build\icu\source exists
  • Open c:\build\icu\source\runConfigureICU
  • Replace all /MD to /MT (of course that will also replace /MDd to /MTd)

1.4 Build ICU

x86 version

:: Start a command prompt and setup x86 build env

cd c:\build\icu\source
set PATH=C:\cygwin\bin;%PATH%
dos2unix *
dos2unix -f configure
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86

:: Build the x86 static release version

mkdir c:\build\icu\build\x86-static-release && cd c:\build\icu\build\x86-static-release
bash ../../source/runConfigureICU Cygwin/MSVC --prefix=/cygdrive/c/build/icu/dist/x86-static-release --enable-static --disable-shared
make -j8 && make install

:: Build the x86 static debug version

mkdir c:\build\icu\build\x86-static-debug && cd c:\build\icu\build\x86-static-debug
bash ../../source/runConfigureICU --enable-debug --disable-release Cygwin/MSVC --prefix=/cygdrive/c/build/icu/dist/x86-static-debug --enable-static --disable-shared 
make && make install

::

x64 version

:: Start a command prompt and setup x64 build env

cd c:\build\icu\source
set PATH=C:\cygwin\bin;%PATH%
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64

:: Build the x64 static release version

mkdir c:\build\icu\build\x64-static-release && cd c:\build\icu\build\x64-static-release
bash ../../source/runConfigureICU Cygwin/MSVC --prefix=/cygdrive/c/build/icu/dist/x64-static-release --enable-static --disable-shared
make -j8 && make install

:: Build the x64 static debug version

mkdir c:\build\icu\build\x64-static-debug && cd c:\build\icu\build\x64-static-debug
bash ../../source/runConfigureICU --enable-debug --disable-release Cygwin/MSVC --prefix=/cygdrive/c/build/icu/dist/x64-static-debug --enable-static --disable-shared
make && make install

::

2. Qt

2.1 Prerequisites

2.2 Change files

  • Open c:\build\qt-everywhere-opensource-src-5.2.1\qtbase\mkspecs\win32-msvc2013\qmake.conf
    • Remove embed_manifest_dll embed_manifest_exe from the line CONFIG += line
    • Make the following change
QMAKE_CFLAGS_RELEASE    = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_DEBUG      = -Zi -MDd

to

QMAKE_CFLAGS_RELEASE    = -O2 -MT
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi -Fd$(DESTDIR)$(QMAKE_TARGET).pdb
QMAKE_CFLAGS_DEBUG      = -Zi -MTd -Fd$(DESTDIR)$(QMAKE_TARGET).pdb

2.3 Build Qt Base

x86-release version

  • Extract Qt Source to c:\build\qt-everywhere-opensource-src-5.2.1
  • Add Python, Ruby, Perl, Jom to PATH
  • Add GnuWin32 to PATH
:: Add GnuWin32 to PATH
set PATH=%PATH%;c:\build\qt-everywhere-opensource-src-5.2.1\gnuwin32\bin

:: Setup Visual C++ Environment

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86

:: Add ICU to INLCUDE, LIB, PATH

set INCLUDE=%INCLUDE%;c:\build\icu\dist\x86-static-release\include
set LIB=%LIB%;c:\build\icu\dist\x86-static-release\lib
set PATH=%PATH%;c:\build\icu\dist\x86-static-release\lib

:: Add OPENSSL to INLCUDE, LIB, PATH

set INCLUDE=%INCLUDE%;c:\build\\openssl\dist\x86-static-release\include
set LIB=%LIB%;c:\build\\openssl\dist\x86-static-release\lib
set PATH=%PATH%;c:\build\\openssl\dist\x86-static-release\lib

:: Create build directory

mkdir c:\build\qt-everywhere-opensource-src-5.2.1\build\x86-static-release
cd c:\build\qt-everywhere-opensource-src-5.2.1\build\x86-static-release

:: Configure

..\..\configure -prefix c:\build\qt-everywhere-opensource-src-5.2.1\dist\x86-static-release -platform win32-msvc2013 -static -release -c++11 -opensource -confirm-license -icu -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -openssl-linked -skip qtwebkit -nomake tests -nomake examples -mp -make-tool jom OPENSSL_LIBS="-lssleay32 -llibeay32 -lgdi32 -lcrypt32 -luser32 -ladvapi32"

:: Build and install

jom -j8
jom install

:: HACK: copy required libs manually

cp C:\build\qt-everywhere-opensource-src-5.2.1\build\x86-static-debug\qtbase\lib\translator_*.lib c:\build\qt-everywhere-opensource-src-5.2.1\dist\x86-static-release\lib
cp C:\build\qt-everywhere-opensource-src-5.2.1\build\x86-static-debug\qtbase\lib\preprocessor*.lib c:\build\qt-everywhere-opensource-src-5.2.1\dist\x86-static-release\lib

::

The steps to build debug version and x64 versions are similar to the ones above.

Sunday, January 19, 2014

Build Qt 5.2 with Visual C++ 2013

Prerequisites

Steps

  • Extract Qt Source to c:\build\qt-everywhere-opensource-src-5.2.0
  • Extract ICU to c:\build\icu
  • Setup Visual C++ Environment
  • Add Python, Ruby, Perl to PATH
  • Add GnuWin32 to PATH
    set PATH=%PATH%;c:\build\qt-everywhere-opensource-src-5.2.0\gnuwin32\bin

  • Add ICU to INLCUDE, LIB, PATH
    set INCLUDE=%INCLUDE%;c:\build\icu\inlcude
    set LIB=%LIB%;c:\build\icu\lib
    set PATH=%PATH%;c:\build\icu\lib

  • Configure
    configure -platform win32-msvc2013 -release -shared -c++11 -opensource -confirm-license -nomake tests -nomake examples -make-tool jom

  • Build
    jom

Thursday, January 2, 2014

Qt5 DEPENDPATH Breaking Changes

Today when trying to build an old project with Qt5, I got a lot of warning and errors like the one below.

WARNING: Failure to find: foo.cpp
...
Error: dependent 'foo.cpp' does not exist.

The warnings and errors are about the lines in a foo.pri file.

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += foo.h
SOURCES += foo.cpp

In my project, foo.pri exists in the same directory of foo.cpp and foo.h. With Qt4, wherever the foo.pri is included, the foo.cpp and foo.h will be added to source file list and header file list respectfully.

But obviously this won’t work with Qt5. After some googling, I found this post. Basically there is breaking changes of DEPENDPATH in qmake that shipped with Qt5.

Though it is far from being an elegant solution, the following lines fix the issue.

INCLUDEPATH += $$PWD
HEADERS += $$PWD/foo.h
SOURCES += $$PWD/foo.cpp