Last edited 3 weeks ago

How to build Qt applications using CMake

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP23x lines, STM32MP25x lines

Warning DB.png Important
The X-LINUX-QT expansion package is validated against the ecosystem release v6.0.0 More info.png and ecosystem release v6.1.0 More info.png .
The X-LINUX-QT expansion package compatible with ecosystem release v6.1.0 More info.png provides only the Distribution package, which can be used to generate the Starter and Developer packages


This article explains how to use the X-LINUX-QT Developer Package to build Qt applications for the STM32 microprocessor series. It has been written for STM32MP2 series but it can be adapted easily to STM32MP1 series.


1. Prerequisites[edit | edit source]

Check first, detailed prerequisites in X-LINUX-QT_Expansion_Package#Prerequisites and X-LINUX-QT Developer Package#Prerequisites.

Then X-LINUX-QT Developer Package is up and running on your board. For that, follow information provided in X-LINUX-QT Developer Package article.

2. Update the SDK environment for CMake[edit | edit source]

Info white.png Information
The OE_CMAKE_TOOLCHAIN_FILE variable needs to be set to allow building CMake projects with the installed SDK

Follow the steps bellow in case it is necessary to add the missing OE_CMAKE_TOOLCHAIN_FILE variable to the SDK configuration.

  • Open the terminal and load the environment setup:
 source /opt/st/stm32mp2/5.0.3-openstlinux-6.6-yocto-scarthgap-mpu-v24.11.06/environment-setup-cortexa35-ostl-linux
  • Export the OE_CMAKE_TOOLCHAIN_FILE variable:
 export OE_CMAKE_TOOLCHAIN_FILE="$OECORE_NATIVE_SYSROOT/usr/lib/cmake/Qt6/qt.toolchain.cmake"

3. Download the demo example source code[edit | edit source]

 mkdir -p /opt/st/demos/Qt
 cd /opt/st/demos/Qt
 git clone https://github.com/KDABLabs/KDBoatDemo.git -b qt6

4. Build the demo example[edit | edit source]

 cd KDBoatDemo
 cmake -S . -B config_default

Example of output traces with previous OSTL/X-LINUX-QT versions (not contractual):

-- Toolchain file defaulted to '/opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/x86_64-ostl_sdk-linux/usr/lib/cmake/Qt6/qt.toolchain.cmake'
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/x86_64-ostl_sdk-linux/usr/bin/aarch64-ostl-linux/aarch64-ostl-linux-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/x86_64-ostl_sdk-linux/usr/bin/aarch64-ostl-linux/aarch64-ostl-linux-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE  
-- Performing Test HAVE_EGL
-- Performing Test HAVE_EGL - Success
-- Found EGL: /opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/cortexa35-ostl-linux/usr/include (found version "1.5") 
-- Performing Test HAVE_GLESv2
-- Performing Test HAVE_GLESv2 - Success
-- Found GLESv2: /opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/cortexa35-ostl-linux/usr/include  
-- Found XKB: /opt/st/stm32mp2/4.2.4-openstlinux-6.1-yocto-mickledore-mpu-v24.06.26_x-linux-qt_v2.0.0/sysroots/cortexa35-ostl-linux/usr/lib/libxkbcommon.so (found suitable version "1.5.0", minimum required is "0.5.0") 
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/st/demos/Qt/KDBoatDemo/config_default
 cmake --build config_default --target all
[  7%] Running qmlimportscanner for KDABBoatDemo
[  7%] Built target KDABBoatDemo_qmlimportscan
[ 15%] Automatic MOC for target KDABBoatDemo
[ 15%] Built target KDABBoatDemo_autogen
[ 23%] Automatic RCC for imagesMaps2.qrc
[ 30%] Automatic RCC for data.qrc
[ 38%] Automatic RCC for images.qrc
[ 46%] Automatic RCC for imagesMaps.qrc
[ 53%] Building CXX object CMakeFiles/KDABBoatDemo.dir/KDABBoatDemo_autogen/mocs_compilation.cpp.o
[ 61%] Building CXX object CMakeFiles/KDABBoatDemo.dir/main.cpp.o
[ 69%] Building CXX object CMakeFiles/KDABBoatDemo.dir/KDABBoatDemo_autogen/EWIEGA46WW/qrc_imagesMaps.cpp.o
[ 76%] Building CXX object CMakeFiles/KDABBoatDemo.dir/KDABBoatDemo_autogen/EWIEGA46WW/qrc_imagesMaps2.cpp.o
[ 84%] Building CXX object CMakeFiles/KDABBoatDemo.dir/KDABBoatDemo_autogen/EWIEGA46WW/qrc_images.cpp.o
[ 92%] Building CXX object CMakeFiles/KDABBoatDemo.dir/KDABBoatDemo_autogen/EWIEGA46WW/qrc_data.cpp.o
[100%] Linking CXX executable KDABBoatDemo
[100%] Built target KDABBoatDemo

5. Deploy the demo example to the running board[edit | edit source]

  • Copy the example's binary into the connected board:
 cd /opt/st/demos/Qt
 scp config_default/KDABBoatDemo root@<board_ip>:/home/root/.

6. Run the demo example on the board[edit | edit source]

  • Connect to the running board:
 ssh root@<board_ip>
  • Run the demo's example (windowed mode):
 ./KDABBoatDemo
  • Check the running demo example on the board's display:
Running KDAB Boat Demo on target (Windowed Mode)
  • Run the demo's example (full screen mode):
 ./KDABBoatDemo --fullscreen
  • Check the running demo example on the board's display:
Running KDAB Boat Demo on target (Full screen Mode)