Build System Integration

The Qt Interface Framework Generator is fully integrated in qmake and CMake to generate all or part of a project.

In it's simplest form, qmake/CMake can generate all the source code and the project only needs to configure the type of project to build.

For complex setups, you can combine generated code with application specific code to extend and use the generated code.

QMake

Example:

CONFIG += ifcodegen

QT_FOR_CONFIG += interfaceframework
!qtConfig(ifcodegen): error("No ifcodegen available")

IFCODEGEN_TEMPLATE = frontend
IFCODEGEN_SOURCES = example.qface
IFCODEGEN_MODULE_NAME = myModule
IFCODEGEN_OUTPUT_DIR = myOutputDir
IFCODEGEN_ANNOTATIONS = annotation.yaml

The following qmake variables are available:

IFCODEGEN_TEMPLATEfrontend (default), simulator_backend
IFCODEGEN_SOURCESA single .qface input file.
IFCODEGEN_MODULE_NAMEOptional. The name of the module that is using the generated code.
IFCODEGEN_OUTPUT_DIRThe output folder where the generated code is placed. The default location is the current build folder.
IFCODEGEN_ANNOTATIONSA list of additional annotation files in YAML format. For more information, see the Annotations Option.
IFCODEGEN_IMPORT_PATHA list of import paths, which are considered when an Interface Definition Language (IDL) file uses an import statement. For more information, see the Import Option.

For more details on the generator's command line arguments, see Use the Generator.

Note: Since the ifcodegen has specific system dependencies, it may not be available in all QtInterfaceFramework installations. In this case, the ifcodegen qmake feature is also not available and this can result in build errors.

In this case, use the following code snippet that makes sure the build stops and provides a meaningful error message:

QT_FOR_CONFIG += interfaceframework
!qtConfig(ifcodegen): error("No ifcodegen available")

CMake

In CMake the following functions and variables are provided by the QtInterfaceFramework package.

Variables

IFCODEGEN_VERBOSE

Enable verbose logging for all ifcodegen functions.

QT_IFCODEGEN_TEMPLATE_SEARCH_PATH

Search path for ifcodegen templates.

Commands

qt_ifcodegen_add_plugin

Adds a plugin target which is generated by ifcodegen using a qface IDL file.

qt_ifcodegen_add_qml_module

Adds a QML module which is generated by ifcodegen using a qface IDL file.

qt_ifcodegen_extend_target

Extends a target with files generated from a qface IDL file.

qt_ifcodegen_generate

Generates files from a qface IDL file.

qt_ifcodegen_import_variables

Generates files from a qface IDL file and provides variables for use within CMake.

qt_set_ifcodegen_variable

Sets the variable to the given value within an ifcodegen template.

QtModule Support

CMake

The integration also supports generating code that you can subsequently compile into a Qt module. The following shows how you can use CMake to build a module named MyModule:

qt_ifcodegen_generate(
    IDL_FILES mymodule.qface
    TEMPLATE frontend
    MODULE_NAME QtMyModule
)
qt_internal_add_module(MyModule
    LIBRARIES
        Qt::CorePrivate
        Qt::InterfaceFrameworkPrivate
    PUBLIC_LIBRARIES
        Qt::Core
        Qt::InterfaceFramework
    PRIVATE_MODULE_INTERFACE
        Qt::CorePrivate
        Qt::InterfaceFrameworkPrivate
)
qt_ifcodegen_extend_target(MyModule
    NO_GENERATE
    IDL_FILES mymodule.qface
)

Before defining the module, the code needs to be generated as it has to be available for syncqt at this point. Afterwards the generated code is used to extend the module target.

SyncQt

In addition to the project file for the module library, the sync.profile also needs to be changed, as it's used to call the syncqt.pl script that generates the forwarding headers. Usually, the sync.profile is setup to search for these headers in the source folders. Using $out_basedir, you can also extend the script to search in the build folder.

...
%modules = ( # path to module name map
    "QtMyModule" => "$basedir/src/mymodule;$out_basedir/src/mymodule"
);
...

QML Type Registration

Depending on the build system used and the version of the QtInterfaceFramework module, there are several ways for generating QML plugins and registering the QML types.

CMake

The preferred way in CMake is to use the new QML Type registration system, which is available in the QtInterfaceFramework module from version 6.3 onwards. In that version the generated code is already using the new registration macros and provides all the necessary information for CMake to generate the rest. Since 6.8 the new convenient CMake macros can be used to generate a QML module:

qt_ifcodegen_add_qml_module(MyModule
    IDL_FILES mymodule.qface
    TEMPLATE frontend
)

Before 6.8

qt_ifcodegen_extend_target(MyModule
    NO_GENERATE
    PREFIX MYMODULE
    IDL_FILES mymodule.qface
    TEMPLATE frontend
)

qt_add_qml_module(MyModule
    URI ${MYMODULE_URI}
    VERSION ${MYMODULE_VERSION}
    RESOURCE_PREFIX "/"
    CLASS_NAME QtMyModulePlugin
    PLUGIN_TARGET qtmymoduleplugin
    IMPORTS QtInterfaceFramework
)

By using the PREFIX argument in the qt_ifcodegen_extend_target call, additional variables get exposed to using MYMODULE as their prefix. Those variables can be used in the following call to qt_add_qml_module, which handles the QML type registration for all types and also generates a QML plugin.

Before 6.3

Instead of using the new QML Type registration, ifcodegen can be used to generate a QML plugin, which registers all types when loaded:

qt_ifcodegen_import_variables(MYMODULE
    IDL_FILES mymodule.qface
    TEMPLATE qmlplugin
    MODULE_NAME QtMyModule
)

qt_add_qml_module(qtmymoduleplugin
    URI ${MYMODULE_URI}
    VERSION ${MYMODULE_VERSION}
    RESOURCE_PREFIX "/"
    PLUGIN_TARGET qtmymoduleplugin
    NO_PLUGIN_OPTIONAL
    NO_GENERATE_PLUGIN_SOURCE
    NO_GENERATE_QMLTYPES
    NO_GENERATE_QMLDIR
    SOURCES
        ${MYMODULE_SOURCES}
    PUBLIC_LIBRARIES
        Qt::InterfaceFramework
        Qt::MyModule
)

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