Skip to content

Building Qt with PowerShell

jonwd7 edited this page Feb 22, 2014 · 32 revisions

[WIP]

Preface

This will guide you through using a PowerShell script to automatically download and compile Qt statically for you. There will be one script for MinGW and one for MSVC.

The install will default to C:\Qt\Static\{VERSION}\{PLATFORM} (e.g. .\5.2.1\mingw48_32 or .\5.2.1\win32-msvc2012)

Prerequisites

For MinGW
  • MinGW-build-Qt-Static.ps1 (PowerShell script) [Link forthcoming]
  • MinGW installed to QTDIR\Tools\mingw*
    • You can use MinGW-Builds-Install.exe to install any version you want to this path
    • You can also install the latest version supported by the Qt Online Installer (Maintenance Tool.exe)
For MSVC
    -QtSrcUrl    (Default: "http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.7z")
    -QtVersion   (Default: "5.2.1")
    -QtRoot      (Default: "C:\Qt")
    -QtStaticDir (Default: "$QtRoot\Static")
    -QtToolsDir  (Default: "$QtRoot\Tools")
    -NumJobs     (Default: 12)
    -MSVC        (Default: 2012) (Other: 2010)
    -Arch        (Default: "x86") (Other: "amd64")
    -Release     (Default: "debug-and-release") (Other: "release")
  • If using MSVC2010, pass in -MSVC 2010
  • If building for 64-bit, pass in -Arch amd64
  • To change number of jobs for CPU, pass in e.g. -NumJobs 8 (or your # of CPU cores)

Setting up PowerShell

  • Install PowerShell 3.0 or 4.0
  • Run PowerShell as Administrator
  • Enter:

    Set-ExecutionPolicy RemoteSigned
    ... and hit Return.

Building Qt

  • Run the script.
  • It will download the source package (5.2.1).
  • It will extract the source package to C:\Qt\src.
  • For MSVC, it will import your environment using the VS Command Prompt BAT file. For MinGW it will find your install of MinGW and modify the environment paths.
  • It will configure Qt, for example:
    ``` cmd /c "configure.bat -static -debug-and-release -platform win32-g++ -prefix $QtDir -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sql-sqlite -no-openssl -opensource -confirm-license ` -make libs -nomake tools -nomake examples -nomake tests"
    
    
  • It will compile Qt with N jobs where N = # of CPU threads. This will take anywhere from 1 hour to several hours.
  • It will install Qt to C:\Qt\Static\{VERSION}\{PLATFORM}.
  • After installing it will:
    • Patch CONFIG += static into the platform's qmake.conf
    • Patch the .prl files to point to the install directory
    • Create a qt.conf file in QTDIR\bin which defines the install location

After it builds you can add the version manually inside Qt Creator at Tools > Build & Run > Qt Versions

[Ignore Cleaning for now]

Cleaning Qt Build Directory

If you are finished with compiling Qt or are building multiple versions, you can:

A) Delete the folder located under C:\Qt\src and leave the .7z archive alone.
B) Alternatively, run jom clean or mingw32-make clean but these appear very unreliable and can actually destroy the integrity of the build folder. They also don't appear to do a good job of actually cleaning up.

With that said, option A is recommended. If you leave the .7z archive in the Qt src directory, the script will immediately extract it and will not try to download it again.


See also: http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW

Clone this wiki locally