Warning, /frameworks/extra-cmake-modules/modules/ECMQmlModule.cmake is written in an unsupported language. File is not indexed.

0001 #
0002 # SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 #
0004 # SPDX-License-Identifier: BSD-3-Clause
0005 
0006 #[========================================================================[.rst:
0007 ECMQmlModule
0008 ------------
0009 
0010 This file contains helper functions to make it easier to create QML modules. It
0011 takes care of a number of things that often need to be repeated. It also takes
0012 care of special handling of QML modules between shared and static builds. When
0013 building a static version of a QML module, the relevant QML source files are
0014 bundled into the static library. When using a shared build, the QML plugin and
0015 relevant QML files are copied to the target's ``RUNTIME_OUTPUT_DIRECTORY`` to make
0016 it easier to run things directly from the build directory.
0017 
0018 Since 6.0.0, when using Qt 6, most functionality of this module has been
0019 implemented by upstream Qt. Most of the functions here will now forward to the
0020 similar Qt functions.
0021 
0022 Example usage:
0023 
0024 .. code-block:: cmake
0025 
0026     ecm_add_qml_module(ExampleModule URI "org.example.Example")
0027 
0028     target_sources(ExampleModule PRIVATE ExamplePlugin.cpp)
0029     target_link_libraries(ExampleModule PRIVATE Qt::Quick)
0030 
0031     ecm_target_qml_sources(ExampleModule SOURCES ExampleItem.qml) # This will have 1.0 as the default version
0032     ecm_target_qml_sources(ExampleModule SOURCES AnotherExampleItem.qml VERSION 1.5)
0033 
0034     ecm_finalize_qml_module(ExampleModule DESTINATION ${KDE_INSTALL_QMLDIR})
0035 
0036 
0037 ::
0038 
0039     ecm_add_qml_module(<target name>
0040         URI <module uri>
0041         [VERSION <module version>]
0042         [NO_PLUGIN] # Deprecated since 6.0.0 when using Qt 6
0043         [CLASSNAME <class name>] # Deprecated since 6.0.0 when using Qt 6, use CLASS_NAME instead
0044         [QT_NO_PLUGIN] # Since 6.0.0, when using Qt 6
0045         [GENERATE_PLUGIN_SOURCE] # Since 6.0.0, when using Qt 6
0046     )
0047 
0048 This will declare a new CMake target called ``<target name>``. The ``URI``
0049 argument is required and should be a proper QML module URI. The ``URI`` is used,
0050 among others, to generate a subdirectory where the module will be installed to.
0051 
0052 If the ``VERSION`` argument is specified, it is used to initialize the default
0053 version that is used by  ``ecm_target_qml_sources`` when adding QML files. If it
0054 is not specified, a  default of 1.0 is used. Additionally, if a version greater
0055 than or equal to 2.0 is specified, the major version is appended to the
0056 Qt5 installation path of the module.
0057 In case you don't specify and version, but specify a version for the individual sources, the latest
0058 will be set as the resulting version for this plugin. This will be used in the ECMFindQmlModule module.
0059 
0060 If the option ``NO_PLUGIN`` is set, a target is declared that is not expected to
0061 contain any C++ QML plugin.
0062 
0063 If the optional ``CLASSNAME`` argument is supplied, it will be used as class
0064 name in the generated QMLDIR file. If it is not specified, the target name will
0065 be used instead.
0066 
0067 You can add C++ and QML source files to the target using ``target_sources`` and
0068 ``ecm_target_qml_sources``, respectively.
0069 
0070 Since 5.91.0
0071 
0072 Since 6.0.0, when used with Qt 6, this will forward to ``qt_add_qml_module``. Any extra arguments will
0073 be forwarded as well. The ``NO_PLUGIN`` argument is deprecated and implies ``GENERATE_PLUGIN_SOURCE``,
0074 since modules in Qt 6 always require a plugin or backing target. If you want to use Qt's behaviour for
0075 ``NO_PLUGIN``, use ``QT_NO_PLUGIN`` instead. Additionally, to maintain backward compatibility, by
0076 default we pass ``NO_GENERATE_PLUGIN_SOURCE`` to ``qt_add_qml_module``. To have Qt generate the plugin
0077 sources, pass ``GENERATE_PLUGIN_SOURCE``.
0078 
0079 ::
0080 
0081     ecm_add_qml_module_dependencies(<target> DEPENDS <module string> [<module string> ...])
0082 
0083 Add the list of dependencies specified by the ``DEPENDS`` argument to be listed
0084 as dependencies in the generated QMLDIR file of ``<target>``.
0085 
0086 Since 5.91.0
0087 
0088 Since 6.0.0, this is deprecated and ignored when using Qt 6, instead use the
0089 ``DEPENDENCIES`` and ``IMPORTS`` arguments to ``ecm_add_qml_module``.
0090 
0091 ::
0092 
0093     ecm_target_qml_sources(<target> SOURCES <source.qml> [<source.qml> ...] [VERSION <version>] [PATH <path>] [PRIVATE])
0094 
0095 Add the list of QML files specified by the ``SOURCES`` argument as source files
0096 to the QML module target ``<target>``.
0097 
0098 If the optional ``VERSION`` argument is specified, all QML files will be added
0099 with the specified version. If it is not specified, they will use the version of
0100 the QML module target.
0101 
0102 If the optional ``PRIVATE`` argument is specified, the QML files will be
0103 included in the target but not in the generated qmldir file. Any version
0104 argument will be ignored.
0105 
0106 The optional ``PATH`` argument declares a subdirectory of the module where the
0107 files should be copied to. By default, files will be copied to the module root.
0108 
0109 This function will fail if ``<target>`` is not a QML module target or any of the
0110 specified files do not exist.
0111 
0112 Since 5.91.0
0113 
0114 Since 6.0.0, when used with Qt 6, this will forward to ``qt_target_qml_sources()``.
0115 The ``SOURCES`` argument will be translated to ``QML_SOURCES``. ``VERSION`` and
0116 ``PRIVATE`` will set Qt's ``QT_QML_SOURCE_VERSIONS`` and ``QT_QML_INTERNAL_TYPE``
0117 properties on ``SOURCES`` before calling ``qt_target_qml_sources()``. Since Qt
0118 includes the path relative to the current source dir, for each source file a
0119 resource alias will be generated with the path stripped. If the ``PATH`` argument
0120 is set, it will be prefixed to the alias. Any additional arguments will be passed
0121 to ``qt_target_qml_sources()``.
0122 
0123 ::
0124 
0125     ecm_finalize_qml_module(<target>
0126         [DESTINATION <QML install destination>] # Optional since 6.0
0127         [VERSION <Project Version>] # Added for 6.0 when using Qt 6
0128     )
0129 
0130 Finalize the specified QML module target. This must be called after all other
0131 setup (like adding sources) on the target has been done. It will perform a
0132 number of tasks:
0133 
0134 - It will generate a qmldir file from the QML files added to the target. If the
0135   module has a C++ plugin, this will also be included in the qmldir file.
0136 - If ``BUILD_SHARED_LIBS`` is off, a QRC file is generated from the QML files
0137   added to the target. This QRC file will be included when compiling the C++ QML
0138   module. The built static library will be installed in a subdirection of
0139   ``DESTINATION`` based on the QML module's uri. If this value is not set, KDE_INSTALL_QMLDIR will be used.
0140   Note that if ``NO_PLUGIN`` is set, a C++ QML plugin will be generated to include the QRC files.
0141 - If ``BUILD_SHARED_LIBS`` in on, all generated files, QML sources and the C++
0142   plugin will be installed in a subdirectory of ``DESTINATION`` based upon the
0143   QML module's uri. In addition, these files will also be copied to the target's
0144   ``RUNTIME_OUTPUT_DIRECTORY`` in a similar subdirectory.
0145 
0146 This function will fail if ``<target>`` is not a QML module target.
0147 
0148 Since 5.91.0
0149 
0150 Since 6.0.0, when using Qt 6, this will instead install the files generated
0151 by ``qt_add_qml_module``. The optional ``VERSION`` argument was added that will
0152 default to ``PROJECT_VERSION`` and which will write a file that is used by
0153 ``ECMFindQmlModule`` to detect the version of the QML module.
0154 
0155 #]========================================================================]
0156 
0157 include(${CMAKE_CURRENT_LIST_DIR}/QtVersionOption.cmake)
0158 
0159 # This is also used by ECMFindQmlModule, so needs to be available for both
0160 # Qt 5 and Qt 6.
0161 macro(_ecm_qmlmodule_uri_to_path ARG_OUTPUT ARG_PATH ARG_VERSION)
0162     string(REPLACE "." "/" _output "${ARG_PATH}")
0163 
0164     # If the major version of the module is >2.0, Qt expects a ".MajorVersion" suffix on the directory
0165     # However, we only need to do this in Qt5
0166     if ("${QT_MAJOR_VERSION}" STREQUAL "5" AND "${ARG_VERSION}" VERSION_GREATER_EQUAL 2.0)
0167         string(REGEX MATCH "^([0-9]+)" _version_major ${ARG_VERSION})
0168         set("${ARG_OUTPUT}" "${_output}.${_version_major}")
0169     else()
0170         set("${ARG_OUTPUT}" "${_output}")
0171     endif()
0172 endmacro()
0173 
0174 # The implementation for this has diverged significantly between Qt 5 and Qt 6
0175 # so it has been split to separate files.
0176 if ("${QT_MAJOR_VERSION}" STREQUAL "6")
0177     include(${CMAKE_CURRENT_LIST_DIR}/ECMQmlModule6.cmake)
0178     if (NOT COMMAND ecm_add_qml_module)
0179         message(FATAL_ERROR "Failed setting up ECMQmlModule")
0180     endif()
0181 elseif("${QT_MAJOR_VERSION}" STREQUAL "5")
0182     include(${CMAKE_CURRENT_LIST_DIR}/ECMQmlModule5.cmake)
0183 else()
0184     message(FATAL_ERROR "Could not determine Qt major version")
0185 endif()