Qt 配置选项

configure is a command-line tool which determines how to build Qt for a particular platform. Configure can exclude a feature in Qt as well as determine how Qt builds and deploys applications onto host platforms. This page discusses some of the configure options, but for the full list of options, enter the command configure -h . Configure should be run from the main Qt source directory.

Unless stated otherwise, the commands in this page are for the Linux platforms. On macOS and on Windows, the PATH and directory structure are different, therefore the commands will vary. Also, on Windows systems, the configure script is called configure.bat .

After running configure ,构建源采用 make 工具 (属于选取工具链)。

源目录 构建目录和安装目录

The source directory contains the source code that is obtained from the source package or git repository. The build directory is where the build-related files such as Makefiles, object files, and other intermediate files are stored. The 安装 directory is where the binaries and libraries are installed, for use either by the system or by the application.

It is recommended to keep these directories separate by shadow-building and using the -prefix option. This enables you to keep the Qt source tree clean from the build artifacts and binaries, which are stored in a separate directory. This method is very convenient if you want to have multiple builds from the same source tree, but for different configurations. To shadow-build, run configure from a separate directory:

mkdir ~/qt-build
cd ~/qt-build
~/qt-source/configure -prefix /opt/Qt5.9
qmake
					

配置采用 -prefix option means that the Qt binaries and libraries are installed into another directory, which is /opt/Qt5.9 in this case. Running qmake generates the Makefiles in the ~/qt-build directory and not in the source directory. After the Makefiles are in place, run the following commands to build the Qt binaries and libraries, and install them:

make
make install
					
					

模块和特征

Qt consists of different 模块 whose sources can be found in different directories inside the top-level source directory. Users can explicitly exclude specific top-level directories to limit build times. Furthermore, each Qt module might have features that can also be explicitly enabled or disabled.

排除 Qt 模块

配置的 -skip option allows top-level source directories to be excluded from the Qt build. Note that many directories contain multiple Qt modules. For example, to exclude Qt NFC and Qt Bluetooth from the Qt build, provide -skip qtconnectivity as the argument to configure.

./configure -skip qtconnectivity
					
					

包括或排除特征

The -feature- <feature> and -no-feature- <feature> 选项分别包括和排除特定特征。

例如,要禁用 可访问性 ,提供 -no-feature-accessibility 作为自变量:

./configure -no-feature-accessibility
					

使用 configure -list-features to show a list of all available features on the command line. Note that features can depend on other features, so disabling a feature might have side-effects on other features.

The Qt 配置工具 that is part of Qt for Device Creation allows the tweaking of features and dependencies through a convenient user interface.

第 3 方库

The Qt source packages include third-party libraries. To set whether Qt should use the system's versions of the libraries or to use the bundled version, pass either -system or -qt before the name of the library to configure.

下表汇总了第 3 方选项:

库名称 捆绑在 Qt 中 安装在系统中
zlib -qt-zlib -system-zlib
libjpeg -qt-libjpeg -system-libjpeg
libpng -qt-libpng -system-libpng
freetype -qt-freetype -system-freetype
PCRE -qt-pcre -system-pcre
HarfBuzz -NG -qt-harfbuzz -system-harfbuzz

It is also possible to disable support for these libraries by using -no 而不是 -qt . For example, to use the system's xcb library and disable zlib support, enter the following:

./configure -no-zlib -qt-libjpeg -qt-libpng -system-xcb
					

For a full list of options, consult the help with configure -help .

编译器选项

The -platform option sets the host platform and the compiler for building the Qt sources. The list of supported platforms and compilers is found in the 支持平台 page while the full list is available in qtbase/mkspecs 目录。

For example, on Ubuntu Linux systems, Qt can be compiled by several compilers such as clang or g++:

./configure -platform linux-clang
./configure -platform linux-g++
./configure -platform linux-g++-32
					

For Windows 机器, MinGW or Visual Studio toolchains can be used to compile Qt.

configure.bat -platform win32-g++
configure.bat -platform win32-msvc
					

Afterwards, the generated Makefiles will use the appropriate compiler commands.

交叉编译选项

To configure Qt for cross-platform development and deployment, the development toolchain for the target platform needs to be set up. This set up varies among the 支持平台 .

常见选项:

  • -xplatform - the target platform. Valid xplatform options are the same as the -platform options which are found in qtbase/mkspecs .
  • -device - a specific device or chipsets. The list of devices that configure is compatible with are found in qtbase/mkspecs/devices . For more information, visit the Devices Wiki 页面。
  • -device-option - sets additional qmake variables. For example, -device-option CROSS_COMPILE= <path-to-toolchain> provides the environment variable, CROSS_COMPILE , as needed by certain devices.

注意: Toolchains for non-desktop targets often come with a so-called sysroot which Qt needs to be configured against.

特定平台选项

The following pages provide guidelines on how to configure Qt for specific platform development:

用于 Windows 的 OpenGL 选项

On Windows, Qt can be configured with the system OpenGL or with ANGLE . By default, Qt is configured to use dynamic OpenGL. This means that it tries to use system OpenGL and falls back to ANGLE, which is bundled with Qt and depends on the DirectX SDK, if native OpenGL does not work. ANGLE enables running Qt applications that depend on OpenGL, without installing the latest OpenGL drivers. If ANGLE also fails, Qt will fall back to software rendering, which is the slowest but most safe of the rendering methods.

The -opengl option can be used to configure Qt to use the OpenGL in the target system, a different version of OpenGL ES (with or without ANGLE), or dynamically switch between the available OpenGL implementations.

configure.bat -opengl dynamic
					

With the dynamic option, Qt will try to use native OpenGL first. If that fails, it will fall back to ANGLE and finally to software rendering in case of ANGLE failing as well.

configure.bat -opengl desktop
					

With the desktop option, Qt uses the OpenGL installed on Windows, requiring that the OpenGL in the target Windows machine is compatible with the application. The -opengl option accepts two versions of OpenGL ES, es2 for OpenGL ES 2.0 or es1 for OpenGL ES Common Profile.

configure.bat -opengl es2
					

还可以使用 -opengl dynamic , which enable applications to dynamically switch between the available options at runtime. For more details about the benefits of using dynamic GL-switching, see 图形驱动程序 .

开发者构建

The -developer-build option is not meant for shipping applications, but can be used for developing Qt. Such a build contains more exported symbols than a standard build and compiles with a higher warning level.