I was under the impression that GNUInstallDirs treated certain directories specially:
/
For <dir> other than the SYSCONFDIR, LOCALSTATEDIR and RUNSTATEDIR, the value of CMAKE_INSTALL_<dir> is prefixed with usr/ if it is not user-specified as an absolute path. For example, the INCLUDEDIR value include becomes usr/include. This is required by the GNU Coding Standards, which state:
When building the complete GNU system, the prefix will be empty and /usr will be a symbolic link to /.
/usr
For <dir> equal to SYSCONFDIR, LOCALSTATEDIR or RUNSTATEDIR, the CMAKE_INSTALL_FULL_<dir> is computed by prepending just / to the value of CMAKE_INSTALL_<dir> if it is not user-specified as an absolute path. For example, the SYSCONFDIR value etc becomes /etc. This is required by the GNU Coding Standards.
When trying to take advantage of this, if I use the /usr prefix, the files that are installed to CMAKE_INSTALL_SYSCONFDIR are placed in /usr/etc which I can’t imagine ever being the correct location. This appears to be a direct conflict of the documentation above.
If I use the / prefix, it appears to forget to prepend the /usr when I use cmake --install with --prefix /. It does work if I configure with -DCMAKE_INSTALL_PREFIX=/ but only sometimes. I haven’t figured out why it doesn’t always work.
Anyways, I think I’ve gotten it to work (usually) when using the / prefix but I feel like I’m missing something. I created a very basic testcase. Simply: cmake . -DCMAKE_INSTALL_PREFIX=/usr; DESTDIR=bob cmake --install . should be enough to show what I’m talking about.
Am I misusing this somehow or misunderstanding the documentation?
Seems this is even worse because I have to use the install prefix /usr in order for it to respect the triplet in /usr/lib/ for distributions like Debian. Because of this, there isn’t a way to ever just “do the right thing” for all systems currently it seems like.
On Debian, this may be lib/<multiarch-tuple> when CMAKE_INSTALL_PREFIX is /, /usr, or /usr/local.
This documentation doesn’t seem to be upheld for / or /usr/local
Any update regarding the issue described above? I’m also facing it (cmake version 3.22.11, Ubuntu 22.04.5 LTS). If I am using --prefix /usr, then files get installed in /usr/etc instead of /etc. If I am using --prefix /, then none of the directories get prepended with usr e.g., libraries get installed in /lib instead of /usr/lib. If I am not wrong, both special cases are not upheld (not sure about the third one, haven’t checked it). Also, I am not facing this issue in Yocto, but rather only on Ubuntu.
I’ve opened a merge request regarding the --prefix option: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/11369 to clarify a bit further when this option is intended to be used. The special GNU cases aren’t applied at the install phase when CMAKE_INSTALL_PREFIX is overridden via --prefix.
I was also stuck with understanding this issue and to properly fix it in CMake, it is simply too difficult. Installation prefix in CMake on such distributions where something needs to be installed to /usr prefix, should never be set via --prefix option. Only at the configuration time either by setting the CMAKE_INSTALL_PREFIX variable or by using the --install-prefix option. Yes, annoying, but there is no other way here.