Different cmake behaviour for SNAPCRAFT_PART_INSTALL

I am trying to build a part with cmake+Ninja, but SNAPCRAFT_PART_INSTALL seems to resolve to a wrong path when using the cmake plugin.

When using the cmake plugin:

  plugin: cmake
  cmake-generator: Ninja

the part installs to:


(see the nested /root/parts/plugin-ros/install/). This does not seem correct or what a user intended with -DCMAKE_INSTALL_PREFIX=${SNAPCRAFT_PART_INSTALL}.

If I install manually via:

  plugin: nil
  override-build: |
    cmake --build .
    cmake --install .

then the install path becomes:


This is what I expect the cmake plugin would do. Why does the cmake plugin create this nested install path and how do I tell the cmake plugin to behave as if I passed -DCMAKE_INSTALL_PREFIX=${SNAPCRAFT_PART_INSTALL} to cmake?

i guess your application already respects the $DESTDIR env variable (normally this would point to / but in snap builds it points to $SNAPCRAFT_PART_INSTALL) … the prefix would then normally be something like usr or usr/local, so you end up with:


… i.e. / combined with usr/local …

what you are doing above is to effectively set your prefix to $DESTDIR again so you end up with


i’d just leave the install prefix alone and let it use the defaults, or set it to usr, that should make you end up with


The CMake project is pretty standard (I think). At least it is behaving as expected when setting the CMake variables manually.

As far as I understand, DESTDIR is usually a variable used by make, not by cmake. CMake uses CMAKE_INSTALL_PREFIX as the prefix. What you describe makes sense and would explain what I observed. Setting both to the same value makes no sense.

If the cmake plugin already sets DESTDIR, then CMAKE_INSTALL_PREFIX “prefix” becomes a “suffix”. I think this is wrong. The cmake plugin should set CMAKE_INSTALL_PREFIX and not DESTDIR. DESTDIR would be used if a user calls the install step manually, after the build scripts have been generated by cmake.

If I do not define CMAKE_INSTALL_PREFIX at all I get:


If I set it to / (CMAKE_INSTALL_PREFIX=/) I get:


For the stage part, it would make the most sense if the parts are just installed in the root folder of the snap (i.e. ${SNAPCRAFT_PART_INSTALL}).

How do I replicate the cmake -DCMAKE_INSTALL_PREFIX=${SNAPCRAFT_PART_INSTALL} behaviour with the cmake plugin?