KDEInstallDirs on Mac
Open, Needs TriagePublic

Description

(I hope this is the better place to discuss something that should be done than a WIP diff review...)

There is a discrepancy under the Mac's OS (and unpatched Qt) between the install locations expected in the code and the install locations used by the build system. The former depend on QStandardPaths for the most part while the latter are hardcoded and depend on the install prefix, assuming an XDG-compatible installation layout.

As a result several developers have come up with workarounds. I myself have developed a patch for QStandardPaths allowing to make it return XDG-compatible locations while still supporting native locations (based on a compile-time decision using preprocessor tokens). This is IMHO the preferred solution for package managers that aim to install everything into a dedicated prefix, like MacPorts, Fink and HomeBrew.
Others have designed solutions to build standalone app bundles in order to mimick the simple installer-less way of distributing software that is possible on Mac.

I've been thinking of better ways to get things installed where the running software will be looking for it. Initially I thought that a simple wrapper around QStandardPaths could be written so that cmake can simply look up the actual locations. After going over KDEInstallDirs.cmake I'm no longer certain if that's feasible, and there might be bootstrap issues I'm not aware of.

I notice though that almost all locations in KDEInstallDirs are based on the DATAROOTDIR path. Indeed, a quick test with the patched DrKonqi (from D4929) and

if (WIN32)
    _define_relative(DATAROOTDIR BINDIR "data"
        "read-only architecture-independent data root"
        SHARE_INSTALL_PREFIX)
elseif(APPLE AND NOT APPLE_FORCE_INSTALL_PREFIX)
    _define_absolute(DATAROOTDIR "/Library/Application Support"
        "read-only architecture-independent data root")
else()
    _define_absolute(DATAROOTDIR "share"
        "read-only architecture-independent data root"
        SHARE_INSTALL_PREFIX)
endif()

gave an install that worked just as well as with my patched Qt and APPLE_FORCE_INSTALL_PREFIX=ON or APPLE_FORCE_INSTALL_PREFIX=OFF. (APPLE_FORCE_INSTALL_PREFIX could also be called APPLE_FORCE_UNIX_DIRS or even APPLE_FORCE_UNIX_STANDARDS as a generic switch usable elsewhere too).

There are a few variables though for which I don't know if this is the right thing (and I might be missing others):

  • KDE_INSTALL_APPDIR: this is one where querying QStandardPaths would give an undesirable result (/Applications). But in general this might have to be kept at $SHARE_INSTALL_PREFIX/applications so that any non-KDE5 XDG-compliant software the user might have installed in $PREFIX will be able to interact as expected with KDE software
  • KDE_INSTALL_MANDIR: Apple manpages are installed in standard Unix locations
  • KDE_INSTALL_DBUS* : these are presumable used by KDE AND the D-Bus daemon which is typically installed through MacPorts, Fink or HomeBrew (with $PREFIX one of /opt/local, /sw or /usr/local).

Additional interrogation:

  • Can we set DATAROOTDIR=/Library/Application Support/KDE so that everything remains nicely bundled? I notice that Qt tend to use /Library/Application Support/QtProject for its stuff but can we be certain that the extra path component won't break any lookups?

I'd like to address this so that it becomes possible to do quick builds and installs KDE projects against a stock Qt on Mac in a way that's as similar as possible to how it's done on other Unix versions. It could be simpler than I thought but I'd need some feedback to avoid introducing regressions or cause too much breakage of the standalone-appbundle approaches designed by others (setting APPLE_FORCE_INSTALL_PREFIX=ON should ensure that?).

rjvbb created this task.Nov 23 2018, 10:00 AM
rjvbb edited subscribers, added: kde-mac; removed: rjvbb.Nov 23 2018, 1:33 PM
rjvbb added a comment.Nov 23 2018, 1:38 PM

Can we set DATAROOTDIR=/Library/Application Support/KDE so that everything remains nicely bundled?

Sadly not without patching any code, apparently.

We'll also need something like this I think:

_define_relative(DATADIR DATAROOTDIR ""
    "read-only architecture-independent data"
    DATA_INSTALL_DIR)
if(APPLE AND NOT APPLE_FORCE_INSTALL_PREFIX)
    _define_non_cache(DATADIR_KF5 "/Library/Application Support/kf5")
else()
    _define_non_cache(DATADIR_KF5 "${CMAKE_INSTALL_DATADIR}/kf5")
endif()
if(NOT KDE_INSTALL_DIRS_NO_DEPRECATED)
    set(KF5_DATA_INSTALL_DIR "${CMAKE_INSTALL_DATADIR_KF5}")
endif()
/Library/Application Support/kf5

This will be incompatible with homebrew packages, since they are built inside sandbox and own prefix.

I had created a shell script that sets up needed symlinks, it needs to be run manually.

I think If this patch will be accepted, we will end up with install errors due to sandbox limitation, or my script will require a sudo, because /Library/Application Support/ is not writable by arbitrary users.

You will notice that I plan to maintain an option to disable the Apple-specific behaviour for anyone who depends on the current behaviour (that includes me, but your script would also continue to work). Cf. the APPLE_FORCE_X11 option

A priori /Library/Application Support is admin-writable and I cannot really conceive that anyone using (managing) a MacPorts, Fink or HomeBrew installtion would NOT have an admin account. But then I've been tweaking permissions since 10.2 and have only some outdated experience with Fink besides my intimate knowledge of MacPorts (and those both require root permissions to install packages).

A more complete draft: