Skip to content

Building Qt with PowerShell

jonwd7 edited this page Feb 21, 2014 · 32 revisions

[WIP] [Don't get rid of the directory in source. Apparently as of now it doesn't install Qt correctly at all. Delete it and it will no longer link... I'm looking into it but I'm fed up to say the least.]

[Update: Apparently not all the locations to the build folder are getting patched during the install, and not even Qtbinpatcher.exe (a utility) fixes this. I had to manually search and replace the .prl files, despite also using a qt.conf file to define the paths. ]

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: win32-msvc2012)
  • If using MSVC2010, pass in -MSVC win32-msvc2010
  • 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 it builds you can add the version manually inside Qt Creator at Tools > Build & Run > Qt Versions

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