Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91621

Add a CMake wrapper for building a QML-friendly library

    XMLWordPrintable

Details

    Description

      A QML-friendly library should come with metatype generation enabled by default, the include directories set up so that any type registrations can be compiled, an option to enable QML type registration, a nice way to add linked libraries, and possibly more. I currently have to do this (and I don't know if it actually works):

      add_library(QmlBench
          STATIC
              qmlbench.cpp qmlbench.h
              testmodel.cpp testmodel.h
              qquickviewforeign.h
      )
      
      target_link_libraries(QmlBench
          PRIVATE
              Qt::Core
              Qt::Qml
              Qt::Gui
              Qt::Quick
      )
      
      target_include_directories(QmlBench PUBLIC
          $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
          $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
      )
      
      set_target_properties(QmlBench PROPERTIES
          QT_QML_MODULE_URI "QmlBench"
          QT_QML_MODULE_VERSION ${CMAKE_PROJECT_VERSION}
      )
      
      qt_enable_autogen_tool(QmlBench "moc" ON)
      qt_extract_metatypes(QmlBench)
      qt_qml_type_registration(QmlBench)
      

      QML-friendly should be the default for any Qt-based library. So, it should be called something generic like "qt_add_library".

      Furthermore, qt_add_qml_files should be able to attach QML files to any QML-friendly target. This is necessary for QML modules with QML files to have optional plugins: We need to compile the qmlcachegen-processed QML files into a library the plugin can link. The plugin should be an empty shell that only loads such a base library.

      For example, the QtTest import has a few QML files. The fact that it's currently optional means the plugin might not be loaded at all. Therefore, the qmlcachegen-compiled variants of the QML files may not be available at run time. This is not great as they will then be re-compiled on each invocation of any application that uses them.

      Instead, the QML files should be compiled into libQtQuickTest.so. If the user application links libQtQuickTest.so, the plugin won't be loaded. If the QML files are in libQtQuickTest.so, rather than in the plugin, they will still be available.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crscott Craig Scott
              ulherman Ulf Hermann
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: