I’m attempting to build a simple Qt 6 app as a snap. Ideally it should run on Ubuntu Core in U. Frame but just successfully building and running it on my Ubuntu Desktop (22.04.1) would be a huge step forward.
My snapcraft.yaml
:
name: hello-qt
version: 0.0.1
summary: Qt6 example app
description: Qt example app
confinement: strict
grade: stable
base: core22
architectures:
- amd64
apps:
qt-hello:
common-id: org.foobar.qt-hello
command: qt-hello
daemon: simple
restart-condition: always
plugs:
- opengl # do I need opengl?
- wayland
- network
environment:
QT_QPA_PLATFORM: wayland
QT_PLUGIN_PATH: ${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/qt6/plugins/
QT_QPA_PLATFORM_PLUGIN_PATH: ${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/qt6/plugins/platforms/
parts:
qt-hello:
source-type: git
source: https://github.com/redacted.git
plugin: cmake
cmake-generator: Ninja
;; cmake-parameters:
;; - -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6/
build-packages:
- libgl1-mesa-dev
- libvulkan-dev
- libxkbcommon-dev
- qt6-base-dev
- qt6-tools-dev
- qt6-l10n-tools
stage-packages:
- qt6-base-dev
# not sure yet which ones I'll need
stage-snaps:
- ubuntu-frame
I can build and run the app on both Ubuntu and Windows using just cmake
+ ninja
.
When using snapcraft
it fails with
Unpacking stage-snaps to /root/parts/qt-hello/install
:: + cmake /root/parts/qt-hello/src -G Ninja
:: -- Could NOT find Qt6LinguistTools (missing: Qt6LinguistTools_DIR)
:: CMake Error at CMakeLists.txt:15 (find_package):
:: Found package configuration file:
::
:: /root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/Qt6/Qt6Config.cmake
::
:: but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
:: FOUND. Reason given by package:
::
:: Failed to find Qt component "LinguistTools".
::
:: Expected Config file at
:: "/root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake"
:: does NOT exist
When I enter the ldx container using snapcraft --debug
I can confirm Qt6LinguistTools
doesn’t exist in /root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/
but it does exist in /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake
.
What I don’t understand: the directory
/root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/
seems to be mirroring
/usr/lib/x86_64-linux-gnu/cmake/
but not quite, the latter contains 6 more Qt* directories - these are missing:
- Qt6Designer
- Qt6DesignerComponentsPrivate
- Qt6Help
- Qt6Linguist
- Qt6Tools
- Qt6ToolsTools
- Qt6UiPlugin
- Qt6UiTools
Next, I’ve tried to set
cmake-parameters:
- -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6/
but got the same error message.
I can build it manually in the LXD container without any issues:
mkdir /root/parts/qt-hello/custom_build
cd /root/parts/qt-hello/custom_build
cmake -S /root/parts/qt-hello/src -B /root/parts/qt-hello/custom_build -G Ninja && ninja
– The CXX compiler identification is GNU 11.2.0 – Detecting CXX compiler ABI info – Detecting CXX compiler ABI info - done – Check for working CXX compiler: /usr/bin/c++ - skipped – Detecting CXX compile features – Detecting CXX compile features - done – Looking for C++ include pthread.h – Looking for C++ include pthread.h - found – 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
– Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
– Found WrapOpenGL: TRUE
– Found XKB: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (Required is at least version “0.5.0”) – Found WrapVulkanHeaders: /usr/include
– Configuring done – Generating done – Build files have been written to: /root/parts/qt-hello/custom_build[0/2] Re-checking globbed directories… [8/8] Linking CXX executable qt-hello