Handle usr-move without forcing absolute paths (#14041)

In commit 0c727b90 (install(EXPORT): Force absolute paths for usr-move,
2013-03-08) and commit d4774140 (configure_package_config_file: force
absolute paths for usr-move, 2013-01-24) we supported Linux
distributions implementing the "/usr move" by assuming that installation
to (/usr)?/lib(64)? represents a non-relocatable system package.

When cross-compiling one may prepare a package for installation into a
system location on a target machine but install the package files on the
*host* machine inside another path for use with CMAKE_FIND_ROOT_PATH.
In this case the package development files must still be relocatable.

Handle "/usr move" with a new approach that works with relocatable
files.  Teach configure_package_config_file and install(EXPORT) to
generate special logic in a package configuration file or targets file
for installation under (/usr)?/lib(64)?.  Teach the file to recognize
when it is loaded through a symlink that refers to the same realpath as
its original install destination.  In such a case, use the original
install prefix.  Otherwise, compute the prefix relative to the current
file location to make it relocatable.
This commit is contained in:
Brad King
2013-04-03 10:54:08 -04:00
parent 99f7cc127a
commit 6c613b433c
2 changed files with 45 additions and 44 deletions
+26 -23
View File
@@ -76,33 +76,36 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
{
std::string installPrefix =
this->IEGen->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
std::string absDest = installPrefix + "/" + installDest + "/";
if(strncmp(absDest.c_str(), "/lib/", 5) == 0 ||
strncmp(absDest.c_str(), "/lib64/", 7) == 0 ||
strncmp(absDest.c_str(), "/usr/lib/", 9) == 0 ||
strncmp(absDest.c_str(), "/usr/lib64/", 11) == 0)
std::string absDest = installPrefix + "/" + installDest;
std::string absDestS = absDest + "/";
os << "# Compute the installation prefix relative to this file.\n"
<< "get_filename_component(_IMPORT_PREFIX"
<< " \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
if(strncmp(absDestS.c_str(), "/lib/", 5) == 0 ||
strncmp(absDestS.c_str(), "/lib64/", 7) == 0 ||
strncmp(absDestS.c_str(), "/usr/lib/", 9) == 0 ||
strncmp(absDestS.c_str(), "/usr/lib64/", 11) == 0)
{
// Assume this is a build for system package installation rather than a
// relocatable distribution. Use an absolute prefix because some Linux
// distros symlink /lib to /usr/lib which confuses the relative path
// computation below if we generate for /lib under one prefix and but the
// file is loaded from another.
os << "set(_IMPORT_PREFIX \"" << installPrefix << "\")\n";
// Handle "/usr move" symlinks created by some Linux distros.
os <<
"# Use original install prefix when loaded through a\n"
"# cross-prefix symbolic link such as /lib -> /usr/lib.\n"
"get_filename_component(_realCurr \"${_IMPORT_PREFIX}\" REALPATH)\n"
"get_filename_component(_realOrig \"" << absDest << "\" REALPATH)\n"
"if(_realCurr STREQUAL _realOrig)\n"
" set(_IMPORT_PREFIX \"" << absDest << "\")\n"
"endif()\n"
"unset(_realOrig)\n"
"unset(_realCurr)\n";
}
else
std::string dest = installDest;
while(!dest.empty())
{
std::string dest = installDest;
os << "# Compute the installation prefix relative to this file.\n"
<< "get_filename_component(_IMPORT_PREFIX "
<< "\"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n";
while(!dest.empty())
{
os <<
"get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n";
dest = cmSystemTools::GetFilenamePath(dest);
}
os << "\n";
os <<
"get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" PATH)\n";
dest = cmSystemTools::GetFilenamePath(dest);
}
os << "\n";
// Import location properties may reference this variable.
this->ImportPrefix = "${_IMPORT_PREFIX}/";