CMakePackageConfigHelpers' configure_package_config_file() interferes with parent package
When a project uses the configure_package_config_file()
macro from the CMakePackageConfigHelpers
module to configure its package config file, there is a variable called PACKAGE_PREFIX_DIR
in the @PACKAGE_INIT@
block. This is a garden-variety local variable.
The problem arises, when the project includes a child dependency via find_package()
/find_dependency()
in the same package config file and the child dependency's package config file has also been created with configure_package_config_file()
, but is installed in a different install prefix!
find_package()
modifies variables in the parent scope. The child dependency also has a variable PACKAGE_PREFIX_DIR
from the @PACKAGE_INIT@
block, but with a different value. It overwrites the PACKAGE_PREFIX_DIR
in the parent project. If the parent project now uses PACKAGE_PREFIX_DIR
after this find_package()
call (via @PACKAGE_<variable name>@
), the variable has a wrong value and paths break. This is unexpected behavior for the author of the parent package (at least, it was for me), who should not be required to know about the internals of the included dependency.
Can't the PACKAGE_PREFIX_DIR
variable be prefixed with the package name or something? That would be an easy fix opaque to the user.