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 installation. 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_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

QMake

The integration also supports generating code that you can subsequently compile into a Qt module. Since this module needs to work more closely with Qt's module building system, it shouldn't be loaded using the CONFIG variable, but using the load() function instead. The ifcodegen_qt_module feature replaces the load(qt_module) call.

The following shows how you can integrate the QtIfVehicleFunctions module:

TARGET = QtIfVehicleFunctions
QT = core core-private interfaceframework
CONFIG += c++11 ifcodegen

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

...

IFCODEGEN_MODULE_NAME = QtIfVehicleFunctions
IFCODEGEN_SOURCES += ifvehiclefunctions.qface

load(ifcodegen_qt_module)

CMake

The following shows how you can use CMake to build the QtIfVehicleFunctions module:

qt_ifcodegen_generate(
    IDL_FILES ifvehiclefunctions.qface
    TEMPLATE frontend
    MODULE_NAME QtIfVehicleFunctions
)

qt_internal_add_module(IfVehicleFunctions
    LIBRARIES
        Qt::CorePrivate
        Qt::InterfaceFrameworkPrivate
    PUBLIC_LIBRARIES
        Qt::Core
        Qt::InterfaceFramework
    PRIVATE_MODULE_INTERFACE
        Qt::CorePrivate
        Qt::InterfaceFrameworkPrivate
)

qt_ifcodegen_extend_target(IfVehicleFunctions
    NO_GENERATE
    IDL_FILES ifvehiclefunctions.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
    "QtIfVehicleFunctions" => "$basedir/src/ifvehiclefunctions;$out_basedir/src/ifvehiclefunctions"
);
...

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