Hi,
I’m working on a C library project that provides some examples.
The examples are contained in a self contained subproject, and can be built from both the top library project (as normal executable targets) or installed as a component.
When installed, the subproject itself gets copied, not the binaries. It can detect it’s not a subproject anymore, and switches to find_package()
(config mode) to find the library.
I’d like to make things fancier, and dynamically add the library install prefix to the installed find_package()
's PATHS
, so that no matter where the library project is installed, if the examples component is enabled, they’ll be able to find the library config file.
Now, I know that in this case, the CMAKE_INSTALL_PREFIX
variable, and $<INSTALL_PREFIX
gen exp, are of no use here. Configuration and generation phases are already over when it’s time to install.
Since the install target depends on ALL
, what would be needed is a build time command with access to build time-only data. That’s not possible.
Maybe a install(CODE
/SCRIPT
?
For example, the cmake --install <dir>
cli command let’s the user specify a base install dir. Is that path stored somewhere an install script can read?