Qtをソースコードからビルドした

OpenCVをビルドしようとしたら色々あってQtをビルドする方向になった。いろいろ大変だったのでメモを残しておく。

環境

環境はこんな感じ。

  • Qt 5.10.0
  • MinGW 7.1.0 (Pleiades All in One 4.7.0 に入ったいたやつ)
  • MSYS 1.0.19 (Pleiades All in One 4.7.0 に入ったいたやつ)
  • ActivePerl 5.24.3
  • Python 2.7.14 (Anaconda3)

手順は公式サイト*1を参考に、というよりほぼそのまま。

パスを通す

ビルド中に使うやつにパスを通す。細かいことをいうとMinGW、MSYS、gitとかもパスを通す。
Perlはgitからソースをもってくるのに必要なので先にパスを通す。ほかはソースを落としてからでOK。

  • qt5\qtbase\bin
  • qt5\gnuwin32\bin
  • qt5\qtrepotools\bin
  • Perl
  • Python

ソースコードのダウンロード(git clone)

git cloneしただけだとサブモジュール?のフォルダが空っぽになっている。Perlスクリプトを実行するとサブモジュールがcloneされるけど、一晩放置すると終わってる感じ。とても時間がかかる。

configure

configは最後に1つ引数を追加した。「-no-warnings-are-errors」を追加するとDebugビルドから「-Werror」指定が消える。というか、ついてないとコンパイル時の警告でエラーになる。
警告出るなら最初からこのオプションいらないんじゃ・・・

configure -developer-build -opensource -nomake examples -nomake tests -no-warnings-are-errors

ちなみにconfigureのオプションにどんなものがあるのかは、以下のJSONに書いてある。
qt5\qtbase\configure.json


今回configureした結果、以下の構成になった模様。

Configure summary:

Build type: win32-g++ (x86_64, CPU features: cx16 mmx sse sse2 sse3)
Configuration: sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c headersclean largefile optimize_debug precompile_header rdrnd shani private_tests shared debug_and_release release debug build_all c++11 c++14 c++1z concurrent dbus no-pkg-config release_tools stl
Build options:
Mode ................................... debug and release; default link: debug; optimized tools
Optimize debug build ................... yes
Optimize release build for size ........ no
Building shared libraries .............. yes
Using C++ standard ..................... C++1z
Using gold linker ...................... no
Using precompiled headers .............. yes
Using LTCG ............................. no
Target compiler supports:
SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
AVX .................................. AVX AVX2
AVX512 ............................... F ER CD PF DQ BW VL IFMA VBMI
Other x86 ............................ AES F16C RDRAND SHA
Build parts ............................ libs tools
App store compliance ................... no
Qt modules and options:
Qt Concurrent .......................... yes
Qt D-Bus ............................... yes
Qt D-Bus directly linked to libdbus .... no
Qt Gui ................................. yes
Qt Network ............................. yes
Qt Sql ................................. yes
Qt Testlib ............................. yes
Qt Widgets ............................. yes
Qt Xml ................................. yes
Support enabled for:
Using pkg-config ....................... no
QML debugging .......................... yes
udev ................................... no
Using system zlib ...................... yes
Qt Core:
DoubleConversion ....................... yes
Using system DoubleConversion ........ no
GLib ................................... no
iconv .................................. no
ICU .................................... no
Logging backends:
journald ............................. no
syslog ............................... no
slog2 ................................ no
Using system PCRE2 ..................... no
Qt Network:
getifaddrs() ........................... no
IPv6 ifname ............................ no
libproxy ............................... no
OpenSSL ................................ no
Qt directly linked to OpenSSL ........ no
SCTP ................................... no
Use system proxies ..................... yes
Qt Gui:
Accessibility .......................... yes
FreeType ............................... yes
Using system FreeType ................ no
HarfBuzz ............................... yes
Using system HarfBuzz ................ no
Fontconfig ............................. no
Image formats:
GIF .................................. yes
ICO .................................. yes
JPEG ................................. yes
Using system libjpeg ............... no
PNG .................................. yes
Using system libpng ................ no
EGL .................................... yes
OpenVG ................................. no
OpenGL:
ANGLE ................................ yes
Combined ANGLE Library ............... no
Desktop OpenGL ....................... no
Dynamic OpenGL ....................... no
OpenGL ES 2.0 ........................ yes
OpenGL ES 3.0 ........................ no
OpenGL ES 3.1 ........................ no
OpenGL ES 3.2 ........................ no
Vulkan ................................. yes
Session Management ..................... yes
Features used by QPA backends:
evdev .................................. no
libinput ............................... no
INTEGRITY HID .......................... no
mtdev .................................. no
tslib .................................. no
xkbcommon-evdev ........................ no
QPA backends:
DirectFB ............................... no
EGLFS .................................. no
LinuxFB ................................ no
VNC .................................... no
Mir client ............................. no
Windows:
Direct 2D ............................ yes
DirectWrite .......................... yes
DirectWrite 2 ........................ yes
Qt Widgets:
GTK+ ................................... no
Styles ................................. Fusion Windows WindowsVista
Qt PrintSupport:
CUPS ................................... no
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt SerialBus:
Socket CAN ............................. no
Socket CAN FD .......................... no
QtXmlPatterns:
XML schema support ..................... yes
Qt QML:
QML interpreter ........................ yes
QML network support .................... yes
Qt Quick:
Direct3D 12 ............................ no
AnimatedImage item ..................... yes
Canvas item ............................ yes
Support for Qt Quick Designer .......... yes
Flipable item .......................... yes
GridView item .......................... yes
ListView item .......................... yes
Path support ........................... yes
PathView item .......................... yes
Positioner items ....................... yes
ShaderEffect item ...................... yes
Sprite item ............................ yes
Qt Gamepad:
SDL2 ................................... no
Qt 3D:
Assimp ................................. yes
System Assimp .......................... no
Output Qt3D Job traces ................. no
Output Qt3D GL traces .................. no
Use SSE2 instructions .................. yes
Use AVX2 instructions .................. no
Aspects:
Render aspect ........................ yes
Input aspect ......................... yes
Logic aspect ......................... yes
Animation aspect ..................... yes
Extras aspect ........................ yes
Qt 3D GeometryLoaders:
Autodesk FBX ........................... no
Qt Wayland Client ........................ no
Qt Wayland Compositor .................... no
Qt Bluetooth:
BlueZ .................................. no
BlueZ Low Energy ....................... no
Linux Crypto API ....................... no
WinRT Bluetooth API (desktop & UWP) .... no
Qt Sensors:
sensorfw ............................... no
Qt Quick Controls 2:
Styles ................................. Default Fusion Imagine Material Universal
Qt Quick Templates 2:
Hover support .......................... yes
Multi-touch support .................... yes
Qt Positioning:
Gypsy GPS Daemon ....................... no
WinRT Geolocation API .................. no
Qt Location:
Geoservice plugins:
OpenStreetMap ........................ yes
HERE ................................. yes
Esri ................................. yes
Mapbox ............................... yes
MapboxGL ............................. yes
Itemsoverlay ......................... yes
Qt Multimedia:
ALSA ................................... no
GStreamer 1.0 .......................... no
GStreamer 0.10 ......................... no
Video for Linux ........................ no
OpenAL ................................. no
PulseAudio ............................. no
Resource Policy (libresourceqt5) ....... no
Windows Audio Services ................. no
DirectShow ............................. yes
Windows Media Foundation ............... no
Media player backend ................... DirectShow
Qt WebEngine:
Embedded build ......................... no
Pepper Plugins ......................... yes
Printing and PDF ....................... yes
Proprietary Codecs ..................... no
Spellchecker ........................... yes
Native Spellchecker .................... no
WebRTC ................................. yes
Use System Ninja ....................... no
Geolocation ............................ yes

これで終わらない

configureにオプションを追加してもReleaseビルドから「-Werror」オプションが削除されない。
いやがらせかな?
対応策がわかなかったのでエラーになるMakefileを片っ端から「-Werror」という文字列を削除して回った。
今回「-Werror」を消したのは以下のファイル。

  • qt5\qtactiveqt\src\activeqt\Makefile.axshared.Release
  • qt5\qt3d\src\core\Makefile.Release
  • qt5\qt3d\src\logic\Makefile.Release
  • qt5\qt3d\src\render\Makefile.Release
  • qt5\qt3d\src\quick3d\quick3dscene2d\Makefile.Release
  • qt5\qt3d\src\quick3d\quick3dextras\Makefile.Release

もういっそのこと一括置き換えで削除しても良かったのでは・・・

ビルド

makeを打つだけ。すっごい時間かかる。2/2 07:00 ごろから始めて、エラーになっては「Werror」を消して再makeの繰り返しで終わったのが 2/6 08:30 くらい。丸4日PC走りっぱ。
電気代怖い

うちのPCがオンボロ(i7 920、mem6GB)なせいか、並列ビルドするとなぜかスローダウンしたり固まったりするので試してないけど、大丈夫な人はmakeの「-j」オプションとかで並列ビルドすると幸せになれるらしい。

動作確認

公式サイトのサンプル*2をビルドしてみた。

  • ソース一式を用意
  • 「qt5\qtbase\bin」にパスを通す
  • qmake
  • make

でビルドできた。

こんな感じで動いてるっぽい。たぶん。