Skip to content

Default install

Sebastian requested to merge Sebastian/cmake:DefaultInstall into master

Motivation

As a user of some libraries that use cmake to build, I would like if they used consistent ways of installation, preferably with package configuration files, so that I don't need to provide a Find<package>.cmake for find_package module mode.

I would like all the libraries to install their package configuration files into consistent paths, too. Others have already noticed this problem, see Issue 17238.

And I don't want to put find_package commands into the CMakeLists of my executable for the dependencies of the librares I'm using. If these dependencies change, this should be in the responsibility of these libraries, not of the executable, in my opinion. This problem is already mentioned in The Ultimate Guide to Modern CMake.

I am aware that there is a solution to that problem, but it's hidden deep in the cmake documentation: Instead of generating the package configuratin file, generate a file with a slightly different name from install(EXPORT ...) and then include that from the real package configuration file, which also calls find_package for dependencies.

As an author of libraries, I don't want to care about the details how libraries are installed on each system. This should be in the responsibility of cmake, or package / distribution maintainers who shoud be able to configure how the cmake of their system installs libraries.

The proposed DefaultInstall module

The module is a proposal on how these issues could be solved, from the point of view of a cmake user. I'm not sure if the implementation as a module, which changes the behavious of existing commands, is a good thing. Maybe in the long term, or immediately, this should be moved into cmake itself? But until then, there's at least a starting point for discussion. And if the interface is agreed, it could serve as a temporary solution, too, so that users can start using it.

Examples how to use the module are in the Tests.

  • A: Just there as a dependency for the libraries B-E.
  • B: Doesn't use DefaulInstall module
  • C: DefaulInstall module, but not default_install function and not EXPORT in find_package Because of that, need to manually create the CConfig.cmake. Also manually create CConfigVersion.cmake.
  • D: DefaulInstall module, but not default_install function
  • E: full use of default_install
  • X: Depends on B-E

Merge request reports