Qt配置选项

Qt Configure Options

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.

configure是一个命令行工具,用于确定如何为特定平台构建Qt。Configure可以排除Qt中的一个功能,也可以确定Qt如何在主机平台上构建和部署应用程序。本页讨论了一些配置选项,但要查看完整的选项列表,请输入命令configure-h。configure应从Qt源代码主目录运行。

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.

除非另有说明,否则本页中的命令适用于Linux平台。在macOS和Windows上,PATH和目录结构不同,因此命令也会有所不同。此外,在Windows系统上,配置脚本为configure.bat。

After running configure, build the sources with the make tool belonging to the chosen toolchain.

运行configure后,使用属于所选工具链的make工具构建源代码。

Source, Build, and Install Directories

源码、构建和安装目录

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 install directory is where the binaries and libraries are installed, for use either by the system or by the application.

源代码目录包含从源代码包或git存储库获得的源代码。构建目录是存储构建相关文件(如Makefiles、目标文件和其他中间文件)的地方。安装目录是安装二进制文件和库的位置,供系统或应用程序使用。

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:

建议通过阴影构建和使用-prefix选项将这些目录分开。这能够使Qt源代码树与存储在单独目录中的构建工件和二进制文件保持干净。如果想从同一个源代码树中生成多个版本,但针对不同的配置,这种方法非常方便。要进行影子构建,请从单独的目录运行configure:

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

Configuring with the -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:

使用-prefix选项进行配置意味着Qt二进制文件和库被安装到另一个目录中,在本例中为/opt/Qt5.9。运行qmake会在~/qt-build目录中生成Makefiles,而不是在源代码目录中。Makefiles就绪后,运行以下命令构建Qt二进制文件和库,并安装它们:

make
make install

Modules and Features

模块和功能

Qt consists of different modules 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由不同的模块组成,其源代码可以在顶级源代码目录内的不同目录中找到。用户可以明确排除特定的顶级目录以限制构建时间。此外,每个Qt模块可能都有可以显式启用或禁用的功能。

Excluding Qt Modules

不包括Qt模块

Configure's -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选项允许从Qt构建中排除顶级源代码目录。请注意,许多目录包含多个Qt模块。例如,要从Qt构建中排除Qt NFC和Qt蓝牙,请提供-skip qtconnectivity作为配置参数。

./configure -skip qtconnectivity

Including or Excluding Features

包含或排除功能

The -feature-<feature> and -no-feature-<feature> options include and exclude specific features, respectively.

-feature-<feature>和-no feature-<feature>选项分别包含和排除特定功能。

For example, to disable Accessibility, provide -no-feature-accessibility as the argument:

​例如,要禁用辅助功能,请提供-no-feature-accessibility作为参数:

./configure -no-feature-accessibility

Use 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.

使用configure -list-features在命令行上显示所有可用功能的列表。请注意,功能可能依赖于其他功能,因此禁用功能可能会对其他功能产生副作用。

The Qt Configuration Tool that is part of Qt for Device Creation allows the tweaking of features and dependencies through a convenient user interface.

​Qt配置工具是Qt for Device Creation的一部分,它允许通过方便的用户界面调整功能和依赖关系。

Third-Party Libraries

第三方的函数库

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.

Qt源代码包包括第三方库。要设置Qt是应该使用系统版本的库还是使用捆绑版本,请在要配置的库名称前传递-system或-qt。

The table below summarizes the third-party options:

下表总结了第三方选项:

Library NameBundled in QtInstalled in System
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 instead of -qt. For example, to use the system's xcb library and disable zlib support, enter the following:

也可以使用-no代替-qt来禁用对这些库的支持。例如,要使用系统的xcb库并禁用zlib支持,请输入以下命令:

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

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

有关选项的完整列表,请参阅configure -help的帮助。

Compiler Options

编译选项

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 supported platforms page while the full list is available in qtbase/mkspecs directory.

​-platform选项设置构建Qt源代码的宿主平台和编译器。支持的平台和编译器列表可以在支持的平台页面中找到,而完整列表可以在qtbase/mkspec目录中找到。

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

例如,在Ubuntu Linux系统上,Qt可以由clang或g++等几种编译器编译:

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

For Windows machines, either MinGW or Visual Studio toolchains can be used to compile Qt.

​对于Windows机器,可以使用MinGW或Visual Studio工具链来编译Qt。

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

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

之后,生成的Makefile将使用适当的编译器命令。

Cross-Compilation Options

交叉编译选项

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 Supported Platforms.

​要配置Qt进行跨平台开发和部署,需要设置目标平台的开发工具链。此设置因支持的平台而异。

Common options are:

常见选项包括:

  • -xplatform - the target platform. Valid xplatform options are the same as the -platform options which are found in qtbase/mkspecs.
  • -xplatform-目标平台。有效的xplatform选项与qtbase/mkspec中的platform选项相同。
  • -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 page.
  • -device-特定的设备或芯片组。配置与兼容的设备列表可以在qtbase/mkspecs/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.
  • -device-option-设置其他qmakes变量。例如,-device-option CROSS_COMPILE=<path-to-toolchain> 根据某些设备的需要提供环境变量CROSS_COPILE。

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

注意:非桌面目标的工具链通常附带一个所谓的sysroot,需要对Qt进行配置。

Specific Options for Platforms

平台的具体选项

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

以下页面提供了如何为特定平台开发配置Qt的指南:

OpenGL Options for Windows

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.

​在Windows上,Qt可以用OpenGL系统或ANGLE配置。默认情况下,Qt配置为使用动态OpenGL。这意味着,如果原生OpenGL不起作用,它会尝试使用系统OpenGL,并退回到ANGLE,ANGLE与Qt捆绑在一起,依赖于DirectX SDK。ANGLE允许运行依赖于OpenGL的Qt应用程序,而无需安装最新的OpenGL驱动程序。如果ANGLE也失败了,Qt将退回到软件渲染,这是最慢但最安全的渲染方法。

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.

-opengl选项可用于配置Qt在目标系统中使用opengl、不同版本的openGL ES(有或没有ANGLE),或在可用的opengl实现之间动态切换。

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.

使用dynamic 选项,Qt将首先尝试使用原生OpenGL。如果失败,它将回到ANGLE,最后在ANGLE失败的情况下回到软件渲染。

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.

通过desktop 选项,Qt使用安装在Windows上的OpenGL,要求目标Windows计算机中的OpenGL与应用程序兼容。-opengl选项接受两个版本的opengl ES,es2用于opengl ES 2.0,es1用于opengl ES通用配置文件。

configure.bat -opengl es2

You can also use -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 Graphics Drivers.

​还可以使用-opengl dynamic,它使应用程序能够在运行时在可用选项之间动态切换。有关使用动态GL切换的好处的更多详细信息,请参阅图形驱动程序。

Developer Builds

开发人员构建

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.

-developer-build选项不适用于发布应用程序,但可用于开发Qt。这样的构建包含的导出符号比标准构建多,并且编译时具有更高的警告级别。

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值