Extend GNUInstallDirs to preserve ability to create relocatable packages with EXPORT
Hello,
Creating relocatable packages (doc) is encouraged by CMake, but this only works for install(EXPORT ...)
when install(... DESTINATION ...)
destinations are relative paths. The GNUInstallDirs
package is designed for users to use the CMAKE_INSTALL_FULL_*DIR
variables as destinations. These are absolute paths and thus, it is not convenient to both use GNUInstallDirs
and create relocatable packages with install(EXPORT ...)
I would like to suggest an extension to GNUInstallDirs
that provides additional variables CMAKE_INSTALL_RELOC_*DIR
(or a similar name) which are relative paths if the CMAKE_INSTALL_FULL_*DIR
is equal to ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_*DIR}
and if not are just equal to the FULL variants. In this way, the user can always use the RELOC variants for their DESTINATIONS and they will get relocatable behavior if possible. This would also add a new macro GNUInstallDirs_get_relocatable_dir()
similar to GNUInstallDirs_get_install_dir()
.
I've implemented this in my own project in this kim-api commit, with the primary additions I suggest for GNUInstallDirs given here.
I would be happy to submit this as a MR (with any suggested changes and documentation) if there is interest from the developers.