Allow rootless 'make install' with non-standard CMAKE_INSTALL_PREFIX
ClosedPublic

Authored by martinkostolny on Jan 19 2018, 1:02 AM.

Details

Summary

This is just a suggestion. The change would allow building and installing krusader with standard dev KDE building tool ./kdesrc_build without root privileges.

Without this patch 'make install' is always installing qt plugins into protected /usr/lib/qt/plugins directory regardless of set CMAKE_INSTALL_PREFIX. That means installing fails. With this patch, plugin directory is set e.g. to ${CMAKE_INSTALL_PREFIX}/lib/qt/plugins.

I realize that the removed setting is there for a reason but I cannot reproduce any problems. Also none of KF5 packages (including KIO with a lot of Qt plugins) have this setting enabled. Any info regarding this proposed setting removal is appreciated :-).

Test Plan

Tested building & installing & working with krarc support:

  • rootless ./kdesrc_build (on Arch Linux)

...plus the same with standard -DCMAKE_INSTALL_PREFIX=/usr and 'sudo make install' on:

  • Arch Linux
  • Ubuntu 17.10

Diff Detail

Repository
R167 Krusader
Lint
Lint Skipped
Unit
Unit Tests Skipped
martinkostolny requested review of this revision.Jan 19 2018, 1:02 AM
martinkostolny created this revision.

As I understand it, the problem is that plugins installed to PREFIX/lib/qt/plugins won't always be be found depending on PREFIX.
It will work for "/usr" and probably "/usr/local" (can you confirm the latter, Martin? I didn't test it).
But if I install e.g. to a directory in the Krusader source directory (a quick local installation for testing) the plugins won't work. And this will may be left unnoticed by the user.

Adding a warning in this case would be good - with a hint that -DQT_PLUGIN_INSTALL_DIR should be used. But my knowledge about CMake is limited.
Besides that I'm fine with removing these lines.

@asensi Can you comment, please? Because you added this

Because you added this

Thanks for mentioning it, the change was caused because QT_PLUGIN_INSTALL_DIR became deprecated, etc. There was more information in:

https://phabricator.kde.org/T2115
https://phabricator.kde.org/D1323

Thanks for the lot of good info!

"/usr" and probably "/usr/local" can you confirm the latter, Martin?

I've tested /usr/local and it works as well on Arch. Although if one use a different CMAKE_INSTALL_PREFIX, the plugins fail to load, like You said, Alex.

It probably has also something to do with the location where KDE libraries are installed. Because if I run the whole plasma session with ~/kde/usr prefix (default for ./kdesrc-build), I can use krusader within this prefix along with its plugins. Meaning without the KDE_INSTALL_USE_QT_SYS_PATHS flag.

I've seen the various links and info in T2115. Interesting is this e.g. change:
https://git.reviewboard.kde.org/r/127169/

  • Qt plugin directory is by default united with cmake one, which is probably fixing the mentioned Ubuntu problems
  • Also here they say KDE_INSTALL_USE_QT_SYS_PATHS ... This variable should NOT be set from within CMakeLists.txt files, instead is intended to be set manually when configuring a project which uses KDEInstallDirs (e.g. by packagers).

Therefore I still believe we should remove it. But I agree we should add a warning as a hint for users. I'll update the diff. But I'm of course still open for other suggestions including letting it be :).

Diff updated to show a waring if CMAKE_INSTALL_PREFIX is not standard with a hint how to force installing plugins to standard location.

asensi added a comment.Feb 9 2018, 9:12 AM

Hi! I tried the patch, using Kubuntu 17.10, and everything seems to work correctly.

One interesting thing to note is that prior to applying this patch: after a cmake [...]; make && sudo make install Krusader was installed in /usr/local/bin/, but after applying this patch: Krusader is installed in /usr/bin/

-Thanks, Toni, for trying it out! :-) I believe that cmake is installing into /user/local by default no matter KDE_INSTALL_USE_QT_SYS_PATHS is set or not. At least on Arch Linux it works out like that. Only after setting -DCMAKE_INSTALL_PREFIX=... the install prefix get changed. And that is persisted even if next cmake call is performed without this switch. Best practice for me is cleaning up build folder before calling cmake to have a predictable results. Again, it works like that in Arch Linux with cmake version 3.10.2, I'm not sure if other distributions behave the same.

Anyway this does not probably matter so much at this point. Thanks for the testing. I'll wait for a while and if there aren't any further objections I'll push the change.

nmel accepted this revision.Feb 16 2018, 8:40 AM
nmel added a subscriber: nmel.

Hi Martin,

Thanks for the patch. I verified on current Gentoo, make install under unprivileged user is working as expected now.

It's a good step forward, however this doesn't help with configs which Krusader is looking for during the runtime. For example, it should be looking into $INSTALL_ROOT/share/krusader/layout.xml, but it reads /usr/share/krusader/layout.xml. I can tell by error messages as my /usr version is 2.6.0. We had a brief discussion with Alex here, however no solution was proposed.

This revision is now accepted and ready to land.Feb 16 2018, 8:40 AM
asensi accepted this revision.EditedFeb 16 2018, 10:50 AM

Thanks, Toni, for trying it out! :-)

Thanks, Martin, for preparing those changes :-)

[...] after setting -DCMAKE_INSTALL_PREFIX=... the install prefix get changed.

If it may be useful, I execute

cmake ../krusader -DCMAKE_INSTALL_PREFIX=/usr/ -DCMAKE_C_FLAGS:STRING="-O2 -fPIC" -DCMAKE_CXX_FLAGS:STRING="-O2 -fPIC"

as in the "CMake may be executed this way: [...]" section in

https://cgit.kde.org/krusader.git/tree/INSTALL

And that is persisted even if next cmake call is performed without this switch. Best practice for me is cleaning up build folder before calling cmake to have a predictable results.

Yes, I also cleaned that build folder before trying it.

Anyway this does not probably matter so much at this point. Thanks for the testing. I'll wait for a while and if there aren't any further objections I'll push the change.

I also agree :-)

P.S.: The prior comment, made by nmel, would also have to be taken into account.

This revision was automatically updated to reflect the committed changes.

Thank you both for informative answers!

@asensi Toni, thanks for clearing up the commands you used. I've used almost the same, just not with the C/CXX flags. So there have to be differences in distributions.

@nmel Nikita, good point with the layout.xml. There we will probably have to change the way it is installed and loaded in a way that we either force loading the installed one, or we primarily try to load the one in .local/share and as a "fallback" we load the installed one. But I can be wrong about this approach. I also cannot simulate when the .local/share/krusader/layout.xml is being created.