创建 Qt 插件目标。
命令的定义在
Core
组件对于
Qt6
package. Load the package with:
find_package(Qt6 COMPONENTS Core REQUIRED)
qt_add_plugin(target [SHARED | STATIC] [CLASS_NAME class_name] [OUTPUT_TARGETS variable_name] )
若
无版本命令
被禁用,使用
qt6_add_plugin()
代替。它支持如此命令的一组相同自变量。
Qt plugin targets have additional requirements over and above an ordinary CMake library target. The
qt_add_plugin()
command adds the necessary handling to ensure these requirements are met. It should be called rather than the built-in CMake
add_library()
command when defining a Qt plugin target.
By default, the plugin will be created as a
STATIC
library if Qt was built statically, or as a
MODULE
library otherwise. You can override this default by explicitly providing the
STATIC
or
SHARED
选项。
注意:
Non-static plugins are meant to be loaded dynamically at runtime, not linked to at build time. CMake differentiates between these two scenarios by providing the
MODULE
library type for dynamically loaded libraries, and the
SHARED
library type for libraries that may be linked to directly. This distinction is important for some toolchains (notably Visual Studio), due to the way symbol exports are handled. It may not be possible to link to
MODULE
libraries, and generating a
SHARED
library with no exported symbols can result in build-time errors. If the
SHARED
option is passed to
qt_add_plugin()
, it will therefore create a
MODULE
library rather than a
SHARED
库。
Every Qt plugin has a class name. By default, this will be the same as the
target
, but it can be overridden with the
CLASS_NAME
option. The class name corresponds to the name of the C++ class that declares the metadata for the plugin. For static plugins, it is also the name passed to
Q_IMPORT_PLUGIN
, which imports the plugin into an application and ensures it is available at run time.
If the plugin is built statically,
qt_add_plugin()
may define additional internal targets. These facilitate automatic importing of the plugin for any executable or shared library that links to the plugin. If the project installs the plugin and intends to make it available for other projects to link to, the project should also install these internal targets. The names of these targets can be obtained by providing the
OUTPUT_TARGETS
option, followed by the name of a variable in which to return the target list.