Assume I have written a library <mylib>
that I can build an install via cmake. And I also have a <mylib>Config.cmake
file that can locate all necessary files (library, headers, ...) and exports a target for the library.
If I want to use the library with find_package(...)
, cmake needs to know the location of the config file. I know that I could pass this every time I build a project using the library or I could (for cmake 3.13 and newer) point the <mylib>_ROOT
environment variable to it.
But there is a solution for this that seems much simpler to me: I can register a package in the cmake package registry with the export(PACKAGE <PackageName>)
command. But if I understand its documentation correctly this only allows to register the build directory. My build directories typically contain neither the config file, nor other stuff like include files that might be needed. Sure, I could copy them there, but why would I do this if I already have everything nicely set up in the install directory.
Therefore my questions:
- What is the reason that only registering of the build directory is supported by
export(PACKAGE ...)
? - Is there any way to register my install directory in the cmake package registry?