Absolute paths forbidden in some CMake options

Update your packages before 2.1 release
Added by David Demelier over 1 year ago

Starting with revision r101 (and future 2.1 version), irccd now completely disallow absolute paths for the following options:

  • WITH_BINDIR,
  • WITH_CACHEDIR,
  • WITH_CONFDIR,
  • WITH_DATADIR,
  • WITH_PLUGINDIR.

Background

It is highly recommended to make relocatable software. But what does that mean really? It means that wherever the application is installed, you can safely move it to an another location without recompiling it and the application can still run. The only requirement is to keep the same hierarchy.

In the case of irccd, it uses the following defaults on Unix:

  • WITH_BINDIR: bin/
  • WITH_CACHEDIR: var/irccd/
  • WITH_CONFDIR: etc/
  • WITH_DATADIR: share/irccd/
  • WITH_PLUGINDIR: share/irccd/plugins/

Thus, when irccd is installed in bin/ directory, it knows how to go to the configuration directory by going upward a directory and then in etc/ directory. This is done by retrieving the executable path. This means you can safely install irccd into any directory and then move it somewhere else.

Example:

cmake . -DCMAKE_INSTALL_PREFIX=/tmp/irccd-test
make install

Now, /tmp/irccd-test/ is filled with bin/, etc/ and such. I can safely move /tmp/irccd-test/ somewhere else, irccd will still knows where to locate its directories.

Why disallowing absolute paths

Irccd's CMake process builds the project into a fake root directory, in ${CMAKE_BINARY_DIR}/fakeroot. This makes easier to test irccd without installing it as the fake root directory already simulates the installed project. It makes also much easier for packagers to determine the installed files as they are exactly the same upon installed.

But to use this fakeroot directory, users must not use absolute paths as CMake options are appended to it, thus, setting WITH_BINDIR to C:/Irccd/bin will define the path to ${CMAKE_BINARY_DIR}/fakeroot/C:/Irccd/bin which is indeed invalid.

To fix this, a warning was shown telling that absolute paths are not recommended and fakeroot was disabled in this case, ending with a lot of conditionals in CMake, polluting the readability.

As it's not usually needed to change these directories and to facilitate irccd's development, it's not possible to make them absolute anymore.

But I want to mix / and /usr/local!

While I think you should keep everything belong to the CMAKE_INSTALL_PREFIX variable, it's still possible to tweak the installation to use different parent directories.

cmake . -DCMAKE_INSTALL_PREFIX=/ -DWITH_BINDIR=usr/local/bin -DWITH_CONFDIR=etc -DWITH_DATADIR=usr/local/share -DWITH_CACHEDIR=var/irccd -DWITH_PLUGINDIR=usr/local/share/irccd/plugins

With that invocation, you'll get irccd installed like this:

  • WITH_BINDIR: /usr/local/bin/irccd(ctl)
  • WITH_DATADIR: /usr/local/share/irccd
  • WITH_CONFDIR: /etc/irccd(ctl).conf
  • WITH_CACHEDIR: /var/irccd
  • WITH_PLUGINDIR: /usr/local/share/irccd/plugins

Incoming improvements

Anyway, these CMake options only alter defaults and a new feature to include more paths in the configuration file will be added soon, see #470.


Comments