CMake 快速入门

开始采用 find_package to locate the libraries and header files shipped with Qt Quick Ultralite. You can use the target_link_libraries 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)

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 集成 C++ 代码采用 QML 了解细节。

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 Qt Quick Ultralite 的国际化和本地化 了解细节。

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 OS variable. This command links the right platform library and performs additional actions, such as compiling and linking FreeRTOS sources.

set(OS "BareMetal")

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>

CMAKE_TOOLCHAIN_FILE variable is used to switch to the armgcc 工具链 ,和 QUL_PLATFORM variable determines which particular board to build for.