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.

No comments:

Post a Comment