qul_add_qml_module(<target> URI <uri> [QML_FILES <file paths...> [HEADERS <file paths...>] [SOURCES <file paths...>] [IMPORTS <uris...>] [OUTPUT_DIRECTORY <path>] [GENERATE_QMLTYPES] [INSTALL_HEADERS_LOCATION <path>] [INSTALL_HEADERS_COMPONENT <name>] [INSTALL_LIBRARY_LOCATION <path>] [INSTALL_LIBRARY_COMPONENT <name>] [INSTALL_LIBRARY_EXPORT <name>] )
Creates a CMake target for building a QML module static library with the given URI.
A QML module directory is produced in a subdirectory of the current build directory (see
OUTPUT_DIRECTORY
).
The target is set up such that application targets which link it can import the QML module.
Optionally, module installation can be set up with the
INSTALL_
自变量。
URI
argument is a dot-separated QML module URI, which must be imported in QML to use the module. For example, the URI "Ui.Buttons" would lead to a module to be imported as "import Ui.Buttons 1.0".
QML_FILES
,
HEADERS
,和
SOURCES
arguments list the files that are part of the module. They are convenience wrappers for other CMake commands:
Argument | File Type | Equivalent Command |
---|---|---|
QML_FILES
|
QML sources | qul_target_qml_sources |
HEADERS
|
C++ headers (may have exported types) | qul_target_generate_interfaces |
SOURCES
|
C++ source files |
target_sources
|
IMPORTS
argument can contain a list of QML module URIs that are dependencies of the new module, for example "IMPORTS
QtQuick
QtQuick
.Templates".
OUTPUT_DIRECTORY
argument can override the subdirectory under which the QML module is built. The default is
CMAKE_CURRENT_BINARY_DIR
. The module files are placed into a subdirectory based on the import URI. For example, the subdirectory for
QtQuick.Timeline
would be
QtQuick/Timeline
under the
OUTPUT_DIRECTORY
.
The QML module files are placed in a subdirectory of
OUTPUT_DIRECTORY
which is generated by taking the URI and replacing all "." with "/".
当
GENERATE_QMLTYPES
argument is used, a "plugins.qmltypes" file is generated for the module and placed next to the generated "qmldir" file.
The following files from
OUTPUT_DIRECTORY
are needed by users of the module:
.qml
files (listed in
QML_FILES
)
.h
files (from files in
QML_FILES
)
.fonts
files (from files in
QML_FILES
)
.qml
files (from headers in
HEADERS
)
Additionally, users of the module need access to the headers listed in
HEADERS
. They are never set up for installation by this command.
若
INSTALL_HEADERS_LOCATION
argument is present, the required files from
OUTPUT_DIRECTORY
are installed to the given path. Note that the subdirectory for the module URI will be appended to the path automatically.
可选
INSTALL_HEADERS_COMPONENT
argument controls the
COMPONENT
that is used for the CMake
install(DIRECTORY)
命令。
若
INSTALL_LIBRARY_LOCATION
argument is present, the compiled library is installed to the given location. The optional
INSTALL_LIBRARY_COMPONENT
and
INSTALL_LIBRARY_EXPORT
arguments specify the
COMPONENT
and
EXPORT
arguments that are passed to the CMake
install(TARGETS)
命令。
qul_add_qml_module(simple_qml_only_module URI MySimpleModule QML_FILES Foo.qml Bar.qml ) # myapp has QML files that "import MySimpleModule" and use Foo and Bar target_link_libraries(myapp simple_qml_only_module)
qul_add_qml_module(myqmlmodule URI MyOrg.Styles QML_FILES Foo.qml HEADERS include/backend.h SOURCES source/backend.cpp IMPORTS QtQuick.Templates OUTPUT_DIRECTORY # Means that files will be ${CMAKE_CURRENT_BINARY_DIR}/imports/MyOrg/Styles/... ${CMAKE_CURRENT_BINARY_DIR}/imports/ GENERATE_QMLTYPES INSTALL_HEADERS_LOCATION "${CMAKE_INSTALL_INCLUDEDIR}/qmlmodules" INSTALL_HEADERS_COMPONENT ModuleHeaders INSTALL_LIBRARY_LOCATION ${CMAKE_INSTALL_LIBDIR} INSTALL_LIBRARY_COMPONENT ObjectLibraries INSTALL_LIBRARY_EXPORT SharedExportName ) # Need to ensure that backend.h is installed and in the include path separately. install( DIRECTORY "include/" DESTINATION ${MY_MODULE_INSTALL_INCLUDE_PATH}) target_include_directories(myqmlmodule INTERFACE $<INSTALL_INTERFACE:${MY_MODULE_INSTALL_INCLUDE_PATH}>)
This command was introduced in Qt Quick Ultralite 1.3.