Programming Reference:Building Qt for BCI2000 (obsolete): Difference between revisions

From BCI2000 Wiki
Jump to navigation Jump to search
 
(46 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This document describes how to build Qt for installation in the BCI2000 source tree.
This document describes how to build Qt for installation in the BCI2000 source tree. It is current as of Qt 5.3.


'''Note:''' Following this procedure is only required if you are a member of the BCI2000 team, and if your task is to update the Qt build coming with BCI2000. In case you just want to build BCI2000 against a version of Qt outside the source tree, modify the file <tt>BCI2000/build/cmake/FindQt.cmake</tt>, line 10, to read <tt>SET( USE_STD_QT TRUE )</tt>, and re-run CMake.
'''Note:''' Following this procedure is only required if you are a member of the BCI2000 team, and if your task is to update the Qt build coming with BCI2000. In case you just want to build BCI2000 against a version of Qt outside the source tree, run CMake a first time, then open the file <tt>BCI2000/build/CMakeCache.txt</tt> in the CMake GUI, or in a text editor, and set the value of the USE_EXTERNAL_QT option to "ON".


*Download and install Qt on your machine.
==Build and copy MSVC libraries and auxiliary files==
==Build and copy MSVC libraries and auxiliary files==
*In the file <tt>qt/mkspecs/win32-msvc2008/qmake.conf</tt>, add <tt>-Fd$(DESTDIR)$(QMAKE_TARGET).pdb</tt> as a compiler option to <tt>QMAKE_CFLAGS_DEBUG</tt>. In <tt>QMAKE_CFLAGS_RELEASE</tt> and <tt>QMAKE_CFLAGS_DEBUG</tt>, replace the <tt>-MD</tt> and <tt>-MDd</tt> with <tt>-MT</tt> and  <tt>-MTd</tt>, respectively.
*Download the Qt source code [http://qt-project.org/downloads] to your machine.
*Open the VS2008 console window from the start menu, and from the Qt installation's <tt>qt</tt> directory, run <tt>configure</tt> with the following options:
*Outside the Qt source tree, create a directory tree, e.g. <tt>d:\Qt\5.3\build-msvc12</tt>. A Qt build may require an enormous amount of temporary disk space (50GB and more), so it is recommended to build Qt on a separate (virtual) empty disk drive.
-platform win32-msvc2008
*Into the newly created empty build directory, place a <tt>do_configure.bat</tt> script file with the following content:
-static
 
-no-sql-sqlite
c:\Qt\5.3\Src\configure ^
-no-qt3support
-platform win32-msvc2012 ^
-fast
-static ^
-qt-zlib
-prefix d:\Qt\deployment\qt-5.3.2\win32-msvc2012 ^
-qt-gif
-headerdir ..\include ^
-qt-libpng
-no-vcproj -mp ^
-qt-libmng
-no-openssl -no-qml-debug ^
-no-libtiff
-opengl desktop ^
-no-libjpeg
-skip qtdeclarative ^
-no-phonon
-skip qtquick1 ^
-no-webkit
-skip qtquickcontrols ^
-no-scripttools
-skip qtscript ^
-no-style-plastique
-skip qtwebkit ^
-no-style-motif
-skip qtwebkit-examples ^
-no-style-cde
-skip qtxmlpatterns ^
-nomake tests ^
-nomake examples
 
*This should be a single command line, so make sure that the caret character is actually the last character in each line, and not followed by white space.
*Note that the first path should point to your Qt source location, and the "prefix" path should point to a location on your build drive. This is the path that will contain Qt headers and libraries after the build.
*In your Qt source directory, open the file <tt>qtbase/mkspecs/win32-msvc2012/qmake.conf</tt> in a text editor. In <tt>QMAKE_CFLAGS_RELEASE</tt> and <tt>QMAKE_CFLAGS_DEBUG</tt>, replace the <tt>-MD</tt> and <tt>-MDd</tt> with <tt>-MT</tt> and  <tt>-MTd</tt>, respectively.
*Open an appropriate Visual Studio console window from the start menu. Whether you build a 64 or 32 bit version of Qt will depend on the type of VS Command Prompt you choose.
*Change directory to the build directory containing the script described above, and execute it.
*When prompted for the type of license, choose "Open Source", and answer "yes" when asked whether you accept the terms of the license.
*When prompted for the type of license, choose "Open Source", and answer "yes" when asked whether you accept the terms of the license.
*Run <tt>nmake</tt> in the following directories:
*Run <tt>nmake</tt> as suggested by <tt>configure</tt>.
**<tt>qt/src/corelib</tt>,
*After a successful build, <tt>nmake install</tt> will copy libraries and headers to the location specified by the <tt>-prefix</tt> option.
**<tt>qt/src/gui</tt>,
*The following files must be present in bin:
**<tt>qt/src/winmain</tt>,
**<tt>qt/src/opengl</tt>.
*Copy the following files from <tt>qt/bin</tt> to <tt>BCI2000/src/extlib/qt/msvc/bin</tt>:
findtr
idc.exe
  moc.exe
  moc.exe
  qmake.exe
  qmake.exe
  rcc.exe
  rcc.exe
syncqt
  uic.exe
  uic.exe
  libgcc_s_dw2-1.dll
   
mingwm10.dll
*For 64-bit versions of the libraries, proceed as above, but run <tt>configure</tt> and <tt>nmake</tt> steps from a 64-bit Visual Studio command line prompt. The target directory should be named <tt>win32-amd64-msvc2012</tt> for MSVC 2012 64-bit builds.
Make sure to leave the <tt>qt.conf</tt> file unaffected.
<!--
*From <tt>qt/lib</tt>, copy the following files to <tt>BCI2000/src/extlib/qt/msvc/lib</tt>:
QtCore.lib
QtCored.lib
QtCored.pdb
QtGui.lib
QtGuid.lib
QtGuid.pdb
qtmain.lib
qtmaind.lib
qtmaind.pdb
QtOpenGL.lib
QtOpenGLd.lib
QtOpenGLd.pdb
*From <tt>qt/mkspecs</tt>, copy the file <tt>qconfig.pri</tt>, and recursively copy the contents of the <tt>features</tt> directory and all the <tt>win32-msvc*</tt> directories to <tt>BCI2000/src/extlib/qt/msvc/mkspecs</tt>.
*In <tt>BCI2000/src/extlib/qt/msvc/mkspecs/win32-msvc2008/qmake.conf</tt>, remove the <tt>-Fd$(DESTDIR)$(QMAKE_TARGET).pdb</tt> compiler option from <tt>QMAKE_CFLAGS_DEBUG</tt>.
 
===Note: Why do we need debug libraries and pdb files?===
For the stripped-down version of Qt provided in the BCI2000 source tree, no source code is available, and debugging information in the Qt libraries cannot be used for debugging. Thus, it appears that always linking to the release version of the Qt libraries would be sufficient, saving considerable space in the SVN data base, and download time for the user. Unfortunately, it turns out that this is not sufficient, and that both debugging versions of the Qt libraries, and associated pdb files, are required in the BCI2000 source tree.
*MSVC does not cleanly separate between compile and link stages. Rather, the compiler provides /M switches that determine the runtime libraries to be used in the linking stage.
*Due to this dependency of object code on certain runtime libraries, it is not cleanly possible to link together static libraries compiled with one /M switch with application code compiled with another /M switch. Thus, we need to provide both release and debug versions of the Qt libraries.
*Without the '''pdb''' files, thousands of LNK4099 warnings are generated by the linker.
*LNK4099 indicates that no debugging information can be found for the static libraries being linked into a BCI2000 executable. Suppressing this warning would be the appropriate thing to do, as no source files are available for the Qt libs anyway.
**MSVC does not offer a command line switch/project setting for suppressing linker warnings.
**For each source file inside a static library, and for each BCI2000 executable, separate LNK4099 warnings are generated, adding up to thousands of them.
*Trying the -Z7 switch (to include debug information in the libraries themselves) when building Qt as well as BCI2000 resulted in build failures, so we switched back to -Zi (pdb files).
*The <tt>-Fd$(DESTDIR)$(QMAKE_TARGET).pdb</tt> compiler option is required in order to produce correctly named pdb files in the appropriate location, i.e. in the qt library directory.
 
==Build and copy mingw libraries and auxiliary files==
==Build and copy mingw libraries and auxiliary files==
*From the Qt installation's <tt>qt</tt> directory, run <tt>configure</tt> with the following options:
*From the Qt installation's <tt>qt</tt> directory, run <tt>configure</tt> with the following options:
Line 76: Line 50:
  -fast  
  -fast  
  -qt-zlib
  -qt-zlib
-qt-gif
  -qt-libpng  
  -qt-libpng  
  -qt-libmng  
  -qt-libmng  
Line 87: Line 60:
  -no-style-motif  
  -no-style-motif  
  -no-style-cde  
  -no-style-cde  
The full command line is:
configure -platform win32-g++ -static -no-sql-sqlite -no-qt3support -fast -qt-zlib -qt-libpng -qt-libmng -no-libtiff -no-libjpeg -no-phonon -no-webkit -no-scripttools -no-style-plastique -no-style-motif -no-style-cde
*When prompted for the type of license, choose "Open Source", and answer "yes" when asked whether you accept the terms of the license.
*When prompted for the type of license, choose "Open Source", and answer "yes" when asked whether you accept the terms of the license.
*Open a console window, and run <tt>mingw32-make</tt> in the following directories:
*If you have previously done a full build, open a console window, and run <tt>mingw32-make</tt> in the following directories:
**<tt>qt/src/corelib</tt>,
**<tt>qt/src/corelib</tt>,
**<tt>qt/src/gui</tt>,
**<tt>qt/src/gui</tt>,
**<tt>qt/src/winmain</tt>,
**<tt>qt/src/opengl</tt>.
**<tt>qt/src/opengl</tt>.
*When the build is finished, copy the following files from <tt>qt/bin</tt> to <tt>BCI2000/src/extlib/qt/mingw/bin</tt>:
*Otherwise, run <tt>mingw32-make</tt> from the <tt>qt/src</tt> directory.
findtr
*When the build is finished, copy the following files from <tt>qt/bin</tt> to <tt>qt-x.y.z/win32-g++/bin</tt>:
  idc.exe
  idc.exe
  moc.exe
  moc.exe
  qmake.exe
  qmake.exe
  rcc.exe
  rcc.exe
syncqt
  uic.exe
  uic.exe
  libgcc_s_dw2-1.dll
  libgcc_s_dw2-1.dll
  mingwm10.dll
  mingwm10.dll
If the DLL files do not exist, they are not required.
Leave the <tt>qt.conf</tt> file in place, don't modify it.
Leave the <tt>qt.conf</tt> file in place, don't modify it.
*From <tt>qt/lib</tt>, copy the following files to <tt>BCI2000/src/extlib/qt/mingw/lib</tt>:
*From <tt>qt/lib</tt>, copy the following files to <tt>qt-x.y.z/win32-g++/lib</tt>:
  libQtCore.a
  libQtCore.a
libQtCored.a
  libQtGui.a
  libQtGui.a
libQtGuid.a
libqtmain.a
libqtmaind.a
  libQtOpenGL.a
  libQtOpenGL.a
libQtOpenGLd.a
*From <tt>qt/mkspecs</tt>, copy the file <tt>qconfig.pri</tt>, and recursively copy the contents of directories <tt>features</tt>, <tt>common</tt>, and <tt>win32-g++</tt> to <tt>qt-x.y.z/win32-g++/mkspecs</tt>.
*From <tt>qt/mkspecs</tt>, copy the file <tt>qconfig.pri</tt>, and recursively copy the contents of directories <tt>features</tt>, <tt>common</tt>, and <tt>win32-g++</tt> to <tt>BCI2000/src/extlib/qt/mingw/mkspecs</tt>.


==Copy Qt include files to the BCI2000 directory==
==Add configuration information==
*To each of the <tt>bin</tt> directories created in previous steps, add a file <tt>qt.conf</tt> with the following content:
[Paths]
Prefix=
Documentation=../doc
Headers=../../include
Libraries=../lib
Binaries=
Plugins=../plugins
Data=..
Translations=../translations
Settings=
Examples=
Demos=
 
==Prepare Qt include files for external use==
*Most header files point to header files in the <tt>qt/src</tt> header files. We don't want to provide the entire <tt>qt/src</tt> directory, so we need to replace these header files with the content of the files they point to. There is a <tt>fixheader</tt> tool provided in the BCI2000 source tree at <tt>build/buildutils/fixheader.cpp</tt>. Under cygwin, execute
*Most header files point to header files in the <tt>qt/src</tt> header files. We don't want to provide the entire <tt>qt/src</tt> directory, so we need to replace these header files with the content of the files they point to. There is a <tt>fixheader</tt> tool provided in the BCI2000 source tree at <tt>build/buildutils/fixheader.cpp</tt>. Under cygwin, execute
  make fixheader
  g++ fixheader.cpp -o fixheader
from that directory to build the executable. Then, cd to the <tt>qt/include/Qt</tt> directory of your Qt installation, and execute
from that directory to build the executable. Then, cd to the <tt>qt/include/Qt</tt> directory of your Qt installation, and execute
  for i in `find *.h`; do /full/path/to/fixheader $i; done
  for i in `find *.h`; do /full/path/to/fixheader $i; done
Repeat this step for the <tt>QtCore</tt>, <tt>QtGui</tt>, and <tt>QtOpenGL</tt> include directories.
Repeat this step for the <tt>QtCore</tt>, <tt>QtGui</tt>, and <tt>QtOpenGL</tt> include directories.
*Copy the contents of the directory <tt>qt/include/Qt</tt> into <tt>BCI2000/src/extlib/qt/include/Qt</tt>, omitting the <tt>private</tt> directory.
*Copy the contents of the directory <tt>qt/include/Qt</tt> into <tt>qt-x.y.z/include/Qt</tt>, omitting the <tt>private</tt> directory.
*Likewise, copy the <tt>QtCore</tt>, <tt>QtGui</tt>, and <tt>QtOpenGL</tt> include directories to <tt>BCI2000/src/extlib/qt/include</tt>, omitting the respective <tt>private</tt> directories.
*Likewise, copy the <tt>QtCore</tt>, <tt>QtGui</tt>, <tt>QtOpenGL</tt> include directories to <tt>qt-x.y.z/include</tt>, omitting the respective <tt>private</tt> directories.
 
==Hide debugging information in MSVC libraries==
*Despite current MSVC compilers store debugging information in .pdb files, .lib files still contain traditional debugging information. In addition, .lib debugging information refers to .pdb files, and the MSVC linker will issue a large number of warnings if it cannot find those .pdb files.
*Basically, we might use GNU binutils, which are able to handle COFF binaries, in order to strip debugging information from those libraries. However, it seems that MSVC compilers store information in such a way that it is not possible to remove arbitrary sections without breaking the files. Thus, we keep all sections but change names of debugging sections such that the MSVC linker will not be able to identify them as such. While this has the disadvantage of retaining large file sizes, it still provides the benefit of fast linking, and suppression of linker warnings.
*To hide debugging information, open a cygwin shell, and cd to the qt lib directory that contains MSVC libraries. There, execute
/full/path/to/build/buildutils/strip_msvc_lib.sh *
-->
 
==Upload Qt to the BCI2000 server==
*Create a self-extracting 7z archive from each subfolder of the <tt>qt-x.y.z</tt> directory. In order to expand correctly, the archive must contain the <tt>qt-x.y.z</tt> directory as well.
*For CMake to find an archive on the server, it must be located at the following http path: <tt>/externals/qt/qt-x.y.z.subdirname</tt>
Note that archives may not have an <tt>.exe</tt> file extension on the server. It will be added when the file is downloaded by CMake (see <tt>BCI2000/build/cmake/FindQt.cmake</tt> for details).


==See also==
==See also==

Latest revision as of 18:58, 10 July 2020

This document describes how to build Qt for installation in the BCI2000 source tree. It is current as of Qt 5.3.

Note: Following this procedure is only required if you are a member of the BCI2000 team, and if your task is to update the Qt build coming with BCI2000. In case you just want to build BCI2000 against a version of Qt outside the source tree, run CMake a first time, then open the file BCI2000/build/CMakeCache.txt in the CMake GUI, or in a text editor, and set the value of the USE_EXTERNAL_QT option to "ON".

Build and copy MSVC libraries and auxiliary files

  • Download the Qt source code [1] to your machine.
  • Outside the Qt source tree, create a directory tree, e.g. d:\Qt\5.3\build-msvc12. A Qt build may require an enormous amount of temporary disk space (50GB and more), so it is recommended to build Qt on a separate (virtual) empty disk drive.
  • Into the newly created empty build directory, place a do_configure.bat script file with the following content:
c:\Qt\5.3\Src\configure ^
-platform win32-msvc2012 ^
-static ^
-prefix d:\Qt\deployment\qt-5.3.2\win32-msvc2012 ^
-headerdir ..\include ^
-no-vcproj -mp ^
-no-openssl -no-qml-debug ^
-opengl desktop ^
-skip qtdeclarative ^
-skip qtquick1 ^
-skip qtquickcontrols ^
-skip qtscript ^
-skip qtwebkit ^
-skip qtwebkit-examples ^
-skip qtxmlpatterns ^
-nomake tests ^
-nomake examples 
  • This should be a single command line, so make sure that the caret character is actually the last character in each line, and not followed by white space.
  • Note that the first path should point to your Qt source location, and the "prefix" path should point to a location on your build drive. This is the path that will contain Qt headers and libraries after the build.
  • In your Qt source directory, open the file qtbase/mkspecs/win32-msvc2012/qmake.conf in a text editor. In QMAKE_CFLAGS_RELEASE and QMAKE_CFLAGS_DEBUG, replace the -MD and -MDd with -MT and -MTd, respectively.
  • Open an appropriate Visual Studio console window from the start menu. Whether you build a 64 or 32 bit version of Qt will depend on the type of VS Command Prompt you choose.
  • Change directory to the build directory containing the script described above, and execute it.
  • When prompted for the type of license, choose "Open Source", and answer "yes" when asked whether you accept the terms of the license.
  • Run nmake as suggested by configure.
  • After a successful build, nmake install will copy libraries and headers to the location specified by the -prefix option.
  • The following files must be present in bin:
moc.exe
qmake.exe
rcc.exe
uic.exe

  • For 64-bit versions of the libraries, proceed as above, but run configure and nmake steps from a 64-bit Visual Studio command line prompt. The target directory should be named win32-amd64-msvc2012 for MSVC 2012 64-bit builds.

Upload Qt to the BCI2000 server

  • Create a self-extracting 7z archive from each subfolder of the qt-x.y.z directory. In order to expand correctly, the archive must contain the qt-x.y.z directory as well.
  • For CMake to find an archive on the server, it must be located at the following http path: /externals/qt/qt-x.y.z.subdirname

Note that archives may not have an .exe file extension on the server. It will be added when the file is downloaded by CMake (see BCI2000/build/cmake/FindQt.cmake for details).

See also

Programming Reference:Build System