C

Getting Started with CMake

A CMakeLists.txt file should always begin with the commands, cmake_minimum_required and project. Currently, Qt Quick Ultralite expects the minimum version to be v3.15, but it could be set higher if the project depends on the latest CMake functionalities. The project command defines a name and a list of programming languages used by the project. Although Qt Quick Ultralite expects C and CXX (C++) in the list of languages, ASM (assembly) is also needed for some supported platforms and GNU Compilers. It is a best practice to include all three languages in the list, as it does not harm to have a longer list of languages.

After general CMake configuration use find_package to locate the libraries and header files shipped with Qt Quick Ultralite. You can use the qul_add_target command to build your Qt Quick Ultralite-based application with these libraries and header files. This command automatically adds the appropriate include directories, compile definitions, and libraries.

cmake_minimum_required (VERSION 3.15)

project(example_project LANGUAGE C CXX ASM)

find_package(Qul)
qul_add_target(example)

Then add your source files. Add the QML source files using the qul_target_qml_sources command, and the C++ files that define the exported classes using the qul_target_generate_interfaces command. During the build the QML sources are translated to C++ and then compiled. Descriptions of the exported types in interface headers are made available to the QML code. See Integrating C++ code with QML for details.

target_sources(example PRIVATE example.cpp)
qul_target_qml_sources(example ExampleView.qml)
qul_target_generate_interfaces(example example.h)

If you want the application to be translated, set up translations using qul_target_embed_translations. This creates a update_translations target for generating and updating the listed .ts files based on the translated strings in the QML sources, and embed those translations in the binary. See Internationalization and Localization with Qt Quick Ultralite for details.

qul_target_embed_translations(example translation.nb_NO.ts translation.lv_LV.ts)

Finally, use app_target_setup_os to do additional setup for the OS depending on the value of the QUL_OS variable. This command links the right platform library and performs additional actions, such as compiling and linking FreeRTOS sources.

set(QUL_OS "BareMetal")
app_target_setup_os(example)

Build the project by running cmake on the directory with the CMakeLists.txt file and command-line options to choose the platform to build for. For example, to build for the STM32F769I-Discovery board:

cmake <source_directory>
    -DCMAKE_TOOLCHAIN_FILE=<qul_directory>/lib/cmake/Qul/toolchain/armgcc.cmake
    -DQUL_PLATFORM=STM32F769I-DISCOVERY-baremetal

The CMAKE_TOOLCHAIN_FILE variable is used to switch to the armgcc toolchain, and the QUL_PLATFORM variable determines which particular board to build for.

Note: in a Qt Quick Ultralite project the CMAKE_BUILD_TYPE CMake argument is by default set to MinSizeRel. MinSizeRel is the build type used for the pre-built platform libraries shipped with Qt Quick Ultralite. If you want to change the build type (e.g. to Release) you can do so by invoking cmake with -DCMAKE_BUILD_TYPE=Release. Please refer to this page for more information.

Available under certain Qt licenses.
Find out more.