Creating reusable packages
We’ve extensively used find_package()
in previous chapters and observed its convenience and simplicity. To make our project accessible through this command, we need to complete a few steps so CMake can treat our project as a coherent package:
- Make our targets relocatable.
- Install the target export file to a standard location.
- Create a config file for the package.
- Generate a version file for the package.
Let’s start from the beginning: why do targets need to be relocatable and how can we do this?
Understanding the issues with relocatable targets
Installation solves many problems but also introduces some complexity. The CMAKE_INSTALL_PREFIX
is platform specific and can be set by the user at the installation stage with the --install-prefix
command-line argument. The challenge is that target export files are generated before installation, during the build stage, when the final destination of the installed...