Cmake part unable to find libraries from previous part installed to SNAPCRAFT_STAGE instead looks under /

I’m having difficulty getting a part to build with the cmake plugin that is dependent on a previous part also built with the cmake plugin. The parts are adwaita-qt and qgnomeplatform. QGnomePlatform depends on adwaita-qt libs being present. Adwaita-qt successfully installs to SNAPCRAFT_STAGE but when QGnomePlatform attempts to build I get the following error:

Building qgnomeplatform 
+ snapcraftctl build
+ cmake /root/parts/qgnomeplatform/src/ -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glib-2.0'
--   Found glib-2.0, version 2.64.6
-- Found GSettingSchemas: TRUE  
CMake Error at /root/stage/usr/lib/x86_64-linux-gnu/cmake/AdwaitaQt/AdwaitaQtTargets.cmake:80 (message):
  The imported target "adwaitaqtpriv" references the file

     "/usr/lib/x86_64-linux-gnu/libadwaitaqtpriv.so.1.4.1"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/root/stage/usr/lib/x86_64-linux-gnu/cmake/AdwaitaQt/AdwaitaQtTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /root/stage/usr/lib/x86_64-linux-gnu/cmake/AdwaitaQt/AdwaitaQtConfig.cmake:44 (include)
  CMakeLists.txt:50 (find_package)


-- Configuring incomplete, errors occurred!
See also "/root/parts/qgnomeplatform/build/CMakeFiles/CMakeOutput.log".
See also "/root/parts/qgnomeplatform/build/CMakeFiles/CMakeError.log".
Failed to build 'qgnomeplatform'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

The libadwaitaqtpriv.so.1.4.1 library does get installed to SNAPCRAFT_STAGE

snapcraft-nightmayr-kf5-qt-5-15-2-core20 # find . -name libadwaitaqtpriv.so.1.4.1
./parts/adwaita-qt/install/usr/lib/x86_64-linux-gnu/libadwaitaqtpriv.so.1.4.1
./parts/adwaita-qt/build/src/lib/libadwaitaqtpriv.so.1.4.1
./stage/usr/lib/x86_64-linux-gnu/libadwaitaqtpriv.so.1.4.1

But it looks like cmake expects it to be located under /usr.

The parts in my snapcraft.yaml look like this:

    adwaita-qt:
        plugin: cmake
        cmake-generator: Ninja
        cmake-parameters:
        - -DCMAKE_BUILD_TYPE=Release
        - -DCMAKE_INSTALL_PREFIX=/usr
        build-environment:
        - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
        - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
        override-pull: |
            cp -a $SNAPCRAFT_PART_SRC/../../sources/src/adwaita-qt/. $SNAPCRAFT_PART_SRC
        stage:
        - -usr/share/doc
        after:
        - libkdegames

    qgnomeplatform:
        plugin: cmake
        cmake-generator: Ninja
        cmake-parameters: 
        - -DCMAKE_BUILD_TYPE=Release
        - -DCMAKE_INSTALL_PREFIX=/usr
        build-environment:
        - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
        - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
        override-pull: |
            cp -a $SNAPCRAFT_PART_SRC/../../sources/src/QGnomePlatform/. $SNAPCRAFT_PART_SRC
        stage:
        - -usr/share/doc
        after:
        - adwaita-qt

If anyone knows how to get cmake to find the libs under SNAPCRAFT_STAGE and is able to advise that would be greatly appreciated.

Ah, yes, hm. _IMPORT_PREFIX will point to /usr if you set CMAKE_INSTALL_PREFIX like that, I think. Have you tried setting -DCMAKE_INSTALL_PREFIX="" for the dependency?

I’ve split the 2 parts out to a separate snap to experiment on this, unfortunately setting -DCMAKE_INSTALL_PREFIX="" doesn’t resolve the problem:

'qgnomeplatform' has dependencies that need to be staged: adwaita-qt
Skipping pull adwaita-qt (already ran)
Building adwaita-qt 
+ snapcraftctl build
+ cmake /root/parts/adwaita-qt/src/ -G Ninja -DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current/usr/bin/pkg-config (found version "0.29.1") 
-- Found XCB: /snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current/usr/lib/x86_64-linux-gnu/libxcb.so (Required is at least version "1.10") 
-- Configuring done
-- Generating done
-- Build files have been written to: /root/parts/adwaita-qt/build
+ cmake --build . -- -j2
[49/49] Linking CXX shared module src/style/adwaita.so
+ DESTDIR=/root/parts/adwaita-qt/install
+ cmake --build . --target install
[0/1] Install the project...
-- Install configuration: "Release"
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqtpriv.so.1.4.1
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqtpriv.so.1
-- Set runtime path of "/root/parts/adwaita-qt/install/lib/libadwaitaqtpriv.so.1.4.1" to ""
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqtpriv.so
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqt.so.1.4.1
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqt.so.1
-- Set runtime path of "/root/parts/adwaita-qt/install/lib/libadwaitaqt.so.1.4.1" to ""
-- Installing: /root/parts/adwaita-qt/install/lib/libadwaitaqt.so
-- Installing: /root/parts/adwaita-qt/install/include/AdwaitaQt/adwaita.h
-- Installing: /root/parts/adwaita-qt/install/include/AdwaitaQt/adwaitacolors.h
-- Installing: /root/parts/adwaita-qt/install/include/AdwaitaQt/adwaitarenderer.h
-- Installing: /root/parts/adwaita-qt/install/include/AdwaitaQt/adwaitaqt_export.h
-- Installing: /root/parts/adwaita-qt/install/lib/pkgconfig/adwaita-qt.pc
-- Installing: /root/parts/adwaita-qt/install/lib/cmake/AdwaitaQt/AdwaitaQtConfig.cmake
-- Installing: /root/parts/adwaita-qt/install/lib/cmake/AdwaitaQt/AdwaitaQtConfigVersion.cmake
-- Installing: /root/parts/adwaita-qt/install/lib/cmake/AdwaitaQt/AdwaitaQtTargets.cmake
-- Installing: /root/parts/adwaita-qt/install/lib/cmake/AdwaitaQt/AdwaitaQtTargets-release.cmake
-- Installing: /root/parts/adwaita-qt/install/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/6/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/adwaita.so
-- Set runtime path of "/root/parts/adwaita-qt/install/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/6/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/adwaita.so" to ""
Staging adwaita-qt 
+ snapcraftctl stage
Pulling qgnomeplatform 
+ snapcraftctl pull
Cloning into '/root/parts/qgnomeplatform/src'...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 37 (delta 6), reused 15 (delta 2), pack-reused 0
Unpacking objects: 100% (37/37), 45.13 KiB | 1.74 MiB/s, done.
Note: switching to '71da0a5d29ecf0503532148105f6ee509e635c73'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

Skipping build adwaita-qt (already ran)
Building qgnomeplatform 
+ snapcraftctl build
+ cmake /root/parts/qgnomeplatform/src/ -G Ninja -DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - 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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found PkgConfig: /snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current/usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glib-2.0'
--   Found glib-2.0, version 2.64.6
-- Found GSettingSchemas: TRUE  
CMake Error at /root/stage/lib/cmake/AdwaitaQt/AdwaitaQtTargets.cmake:80 (message):
  The imported target "adwaitaqtpriv" references the file

     "/lib/libadwaitaqtpriv.so.1.4.1"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/root/stage/lib/cmake/AdwaitaQt/AdwaitaQtTargets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /root/stage/lib/cmake/AdwaitaQt/AdwaitaQtConfig.cmake:44 (include)
  CMakeLists.txt:50 (find_package)


-- Configuring incomplete, errors occurred!
See also "/root/parts/qgnomeplatform/build/CMakeFiles/CMakeOutput.log".
See also "/root/parts/qgnomeplatform/build/CMakeFiles/CMakeError.log".
Failed to build 'qgnomeplatform'.

Recommended resolution:
Check the build logs and ensure the part's configuration and sources are correct.

With the blank prefix it ends up installing to $SNAPCRAFT_STAGE/lib but as before, QGnomePlatform expects it to exist under /lib

snapcraft.yaml for these 2 parts:

name: qgnomeplatform
base: core20
version: '0.8.2'
summary: QGnomePlatform
description: |
  QGnomePlatform
grade: stable
confinement: strict

parts:
  adwaita-qt:
      source: https://github.com/FedoraQt/adwaita-qt.git
      source-depth: 1
      source-tag: 1.4.1
      plugin: cmake
      cmake-generator: Ninja
      cmake-parameters:
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX=""
      build-snaps:
      - kde-frameworks-5-qt-5-15-3-core20-sdk
      - cmake
      build-packages:
      - libx11-xcb-dev
      - libx11-dev
      - libxcb1-dev
      build-environment:
      - &id001
        SNAPCRAFT_CMAKE_ARGS: -DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current
      - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
      - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
      stage:
      - -usr/share/doc

  qgnomeplatform:
      source: https://github.com/FedoraQt/QGnomePlatform.git
      source-depth: 1
      source-tag: 0.8.2
      plugin: cmake
      cmake-generator: Ninja
      cmake-parameters: 
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX=/usr
      build-snaps:
      - kde-frameworks-5-qt-5-15-3-core20-sdk
      - cmake
      build-packages:
      - libgtk-3-dev
      - gsettings-desktop-schemas-dev
      build-environment:
      - *id001
      - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
      - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
      stage:
      - -usr/share/doc
      after:
      - adwaita-qt

Well, you could always turn to the good old brute-force way of doing things:

[...]
override-build: |
  snapcraftctl build 
  rsync -a --ignore-existing $SNAPCRAFT_PART_INSTALL/ /

That seems a problem with the way QGnomePlataform configures its project. You might try digging into CMake files trying to find where exactly it references this lib, and sed your way out of this.

That can be a PITA though, CMake seems very confusing to me (I really dislike it, but it seems to get the job done, since everybody uses it).

@ivo.cavalcante I suspect you’re right with the configuration issue lying with adwaita-qt/qgnomeplatform as in my content snap I’ve managed to use cmake parts, which are dependent on previous cmake parts. Was hoping there might be a more elegant way as opposed to using sed or rsync to move the libs to the system location.

@ppd Thanks for the suggestion, I had to make a slight tweak as one of the install paths was

-- Installing: /root/parts/adwaita-qt/install/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/6/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/adwaita.so

which aside from looking incorrect also resulted in an error trying to write to a read-only location. Similarly when this part is included in my content snap it installs to

-- Installing: /root/parts/adwaita-qt/install/root/stage/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/adwaita.so

Not too sure why this happens, but basically had to correct that path:

override-build: |
  snapcraftctl build
  rsync -a --ignore-existing $SNAPCRAFT_PART_INSTALL/root/stage/ $SNAPCRAFT_PART_INSTALL
  rm -rf $SNAPCRAFT_PART_INSTALL/root
  rsync -a --ignore-existing $SNAPCRAFT_PART_INSTALL/ /

The resulting snap successfully allows QGnomePlatform to be used by my Qt snaps. Thanks for the assistance.

On a side note related to QGnomePlatform it looks like it doesn’t use desktop portals so might not be all that of an upgrade at the moment (perhaps a code change needed in Qt itself so it’s aware QT_QPA_PLATFORMTHEME='gnome'?).

Can you try this for the AdwaitaQ part (with prefix /usr):

override-build: |
  snapcraftctl build
  sed -i -E \
    's|set\(_IMPORT_PREFIX "(.*)"\)|set\(_IMPORT_PREFIX "/root/stage\1"\)|' \
    $SNAPCRAFT_PART_INSTALL/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/cmake/AdwaitaQt/AdwaitaQtTargets.cmake

Basically force the “correct” prefix for the imported target.

Edit: I’m impatient and tried it myself with your code above. It does compile and produces a snap. I’d consider this cleaner than the rsync trickery.

1 Like

It looks like it does use portal dialogs, doesn’t it?

Btw., what do you want to do with this? Ship QGnomePlatform inside a snap that uses kde-neon? Because we could probably include this in the platform snap itself if @jriddell doesn’t mind.

1 Like

I did end up giving this a go yesterday, and I can confirm that I did get a snap to be produced but I would still have to do some reorganising manually for adwaita.so in the Adwaita-qt part and libqgnomeplatformtheme.so in the QGnomePlatform part as they still get installed under $SNAPCRAFT_PART_INSTALL/root/stage.

Hmm judging by the code it definitely looks like it should be using portals for the file chooser but this isn’t my experience. The file chooser doesn’t allow me access to removable drives indicating it’s not using portals. Being on GNOME I usually see the current application change to “Portal” which does not happen in my case.

The reason I want to include this within my content snap is so that Qt applications integrate better with the GNOME desktop. I also have plasma-integration included in the snap providing KDEPlasmaPlatformTheme.so as a platformtheme for good integration with KDE (the kde content snap also includes this). When using Qt apps from Flathub, of the selection I’ve used, they ususally use QGnomePlatform. Ideally I would use the content snap provided by the kde-neon extension, but it’s due to lacking certain libs for GNOME like QGnomePlatform and librsvg2 (problem related to this explained here) that have prevented me from adopting it as they don’t look at home on GNOME/GTK desktop environments.

I get:

$ find squashfs-root/ -name "*.so"
squashfs-root/usr/lib/x86_64-linux-gnu/qt5/plugins/styles/adwaita.so
squashfs-root/usr/lib/x86_64-linux-gnu/qt5/plugins/platformthemes/libqgnomeplatformtheme.so
squashfs-root/usr/lib/x86_64-linux-gnu/qt5/plugins/wayland-decoration-client/libqgnomeplatformdecoration.so
squashfs-root/usr/lib/x86_64-linux-gnu/libadwaitaqtpriv.so
squashfs-root/usr/lib/x86_64-linux-gnu/libadwaitaqt.so
squashfs-root/usr/lib/x86_64-linux-gnu/libqgnomeplatform.so

with your adapted

name: qgnomeplatform
base: core20
version: '0.8.2'
summary: QGnomePlatform
description: |
  QGnomePlatform
grade: stable
confinement: strict

parts:
  adwaita-qt:
      source: https://github.com/FedoraQt/adwaita-qt.git
      source-depth: 1
      source-tag: 1.4.1
      plugin: cmake
      cmake-generator: Ninja
      cmake-parameters: &cmake-params
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PREFIX=/usr
      - -DCMAKE_FIND_ROOT_PATH=/snap/kde-frameworks-5-qt-5-15-3-core20-sdk/current
      - -DQT_PLUGINS_DIR=/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5/plugins
      build-snaps:
      - kde-frameworks-5-qt-5-15-3-core20-sdk
      - cmake
      build-packages:
      - libx11-xcb-dev
      - libx11-dev
      - libxcb1-dev
      build-environment:
      - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
      - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
      stage:
      - -usr/share/doc
      override-build: |
        snapcraftctl build
        sed -i -E \
          's|set\(_IMPORT_PREFIX "(.*)"\)|set\(_IMPORT_PREFIX "/root/stage\1"\)|' \
          $SNAPCRAFT_PART_INSTALL/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/cmake/AdwaitaQt/AdwaitaQtTargets.cmake

  qgnomeplatform:
      source: https://github.com/FedoraQt/QGnomePlatform.git
      source-depth: 1
      source-tag: 0.8.2
      plugin: cmake
      cmake-generator: Ninja
      cmake-parameters: *cmake-params
      build-snaps:
      - kde-frameworks-5-qt-5-15-3-core20-sdk
      - cmake
      build-packages:
      - libgtk-3-dev
      - gsettings-desktop-schemas-dev
      build-environment:
      - LD_LIBRARY_PATH: $SNAPCRAFT_STAGE/usr/lib/$SNAPCRAFT_ARCH_TRIPLET:$LD_LIBRARY_PATH
      - PATH: $SNAPCRAFT_STAGE/usr/bin:$PATH
      stage:
      - -usr/share/doc
      after:
      - adwaita-qt

If you set QT_PLUGIN_PATH right for your app (= first this qgnomeplatform snap path, then the KDE framework path), it should find QGnomePlatform and do the right thing. As a matter of fact, I know the kde-neon extension sets this plugin path correctly to first look in the snap itself. So you shouldn’t have to do anything in this case.

You can easily tell by enabling looking glass with alt + f2 (run a command) and running “lg”. There’s a “Windows” tab that should display something like this for an app that uses the portal:

Screenshot from 2021-11-23 11-13-20

1 Like

Ah didn’t realise in your adapted yaml you set DQT_PLUGINS_DIR=/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/qt5/plugins which ended up placing adwaita.so and libqgnomeplatformtheme.so under the correct location, didn’t see this parameter documented in the qgnomeplatform repo.

Portals ended up working correctly when I didn’t set QT_QPA_PLATFORMTHEME manually.

Thanks for the tip, really useful debugging tool