summaryrefslogtreecommitdiffstats
path: root/Source/cmExportInstallFileGenerator.cxx
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2016-07-12 17:26:55 (GMT)
committerBrad King <brad.king@kitware.com>2016-09-08 14:37:31 (GMT)
commitf81b9475f3724eef5d9e81b9190e30f5df09c808 (patch)
treeb2e9bc3973c3ac91826becb5513f7d1cd6a2adf4 /Source/cmExportInstallFileGenerator.cxx
parentf506489d1ed222761f9ce752144a458290020e55 (diff)
downloadCMake-f81b9475f3724eef5d9e81b9190e30f5df09c808.zip
CMake-f81b9475f3724eef5d9e81b9190e30f5df09c808.tar.gz
CMake-f81b9475f3724eef5d9e81b9190e30f5df09c808.tar.bz2
Export: Factor out file generation steps into helpers
Do not actually generate any content in the driving code paths. Use helpers for that.
Diffstat (limited to 'Source/cmExportInstallFileGenerator.cxx')
-rw-r--r--Source/cmExportInstallFileGenerator.cxx153
1 files changed, 84 insertions, 69 deletions
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index bcadaa0..f47038f 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -75,58 +75,8 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
this->GenerateExpectedTargetsCode(os, expectedTargets);
}
- // Set an _IMPORT_PREFIX variable for import location properties
- // to reference if they are relative to the install prefix.
- std::string installPrefix =
- this->IEGen->GetLocalGenerator()->GetMakefile()->GetSafeDefinition(
- "CMAKE_INSTALL_PREFIX");
- std::string const& expDest = this->IEGen->GetDestination();
- if (cmSystemTools::FileIsFullPath(expDest)) {
- // The export file is being installed to an absolute path so the
- // package is not relocatable. Use the configured install prefix.
- /* clang-format off */
- os <<
- "# The installation prefix configured by this project.\n"
- "set(_IMPORT_PREFIX \"" << installPrefix << "\")\n"
- "\n";
- /* clang-format on */
- } else {
- // Add code to compute the installation prefix relative to the
- // import file location.
- std::string absDest = installPrefix + "/" + expDest;
- 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 (cmHasLiteralPrefix(absDestS.c_str(), "/lib/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/lib64/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib/") ||
- cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib64/")) {
- // Handle "/usr move" symlinks created by some Linux distros.
- /* clang-format off */
- 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";
- /* clang-format on */
- }
- std::string dest = expDest;
- while (!dest.empty()) {
- os << "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" "
- "PATH)\n";
- dest = cmSystemTools::GetFilenamePath(dest);
- }
- os << "if(_IMPORT_PREFIX STREQUAL \"/\")\n"
- << " set(_IMPORT_PREFIX \"\")\n"
- << "endif()\n"
- << "\n";
- }
+ // Compute the relative import prefix for the file
+ this->GenerateImportPrefix(os);
std::vector<std::string> missingTargets;
@@ -204,24 +154,9 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
this->GenerateRequiredCMakeVersion(os, "2.8.12");
}
- // Now load per-configuration properties for them.
- /* clang-format off */
- os << "# Load information for each installed configuration.\n"
- << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
- << "file(GLOB CONFIG_FILES \"${_DIR}/"
- << this->GetConfigImportFileGlob() << "\")\n"
- << "foreach(f ${CONFIG_FILES})\n"
- << " include(${f})\n"
- << "endforeach()\n"
- << "\n";
- /* clang-format on */
+ this->LoadConfigFiles(os);
- // Cleanup the import prefix variable.
- /* clang-format off */
- os << "# Cleanup temporary variables.\n"
- << "set(_IMPORT_PREFIX)\n"
- << "\n";
- /* clang-format on */
+ this->CleanupTemporaryVariables(os);
this->GenerateImportedFileCheckLoop(os);
bool result = true;
@@ -242,6 +177,86 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
return result;
}
+void cmExportInstallFileGenerator::GenerateImportPrefix(std::ostream& os)
+{
+ // Set an _IMPORT_PREFIX variable for import location properties
+ // to reference if they are relative to the install prefix.
+ std::string installPrefix =
+ this->IEGen->GetLocalGenerator()->GetMakefile()->GetSafeDefinition(
+ "CMAKE_INSTALL_PREFIX");
+ std::string const& expDest = this->IEGen->GetDestination();
+ if (cmSystemTools::FileIsFullPath(expDest)) {
+ // The export file is being installed to an absolute path so the
+ // package is not relocatable. Use the configured install prefix.
+ /* clang-format off */
+ os <<
+ "# The installation prefix configured by this project.\n"
+ "set(_IMPORT_PREFIX \"" << installPrefix << "\")\n"
+ "\n";
+ /* clang-format on */
+ } else {
+ // Add code to compute the installation prefix relative to the
+ // import file location.
+ std::string absDest = installPrefix + "/" + expDest;
+ 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 (cmHasLiteralPrefix(absDestS.c_str(), "/lib/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/lib64/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib/") ||
+ cmHasLiteralPrefix(absDestS.c_str(), "/usr/lib64/")) {
+ // Handle "/usr move" symlinks created by some Linux distros.
+ /* clang-format off */
+ 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";
+ /* clang-format on */
+ }
+ std::string dest = expDest;
+ while (!dest.empty()) {
+ os << "get_filename_component(_IMPORT_PREFIX \"${_IMPORT_PREFIX}\" "
+ "PATH)\n";
+ dest = cmSystemTools::GetFilenamePath(dest);
+ }
+ os << "if(_IMPORT_PREFIX STREQUAL \"/\")\n"
+ << " set(_IMPORT_PREFIX \"\")\n"
+ << "endif()\n"
+ << "\n";
+ }
+}
+
+void cmExportInstallFileGenerator::CleanupTemporaryVariables(std::ostream& os)
+{
+ /* clang-format off */
+ os << "# Cleanup temporary variables.\n"
+ << "set(_IMPORT_PREFIX)\n"
+ << "\n";
+ /* clang-format on */
+}
+
+void cmExportInstallFileGenerator::LoadConfigFiles(std::ostream& os)
+{
+ // Now load per-configuration properties for them.
+ /* clang-format off */
+ os << "# Load information for each installed configuration.\n"
+ << "get_filename_component(_DIR \"${CMAKE_CURRENT_LIST_FILE}\" PATH)\n"
+ << "file(GLOB CONFIG_FILES \"${_DIR}/"
+ << this->GetConfigImportFileGlob() << "\")\n"
+ << "foreach(f ${CONFIG_FILES})\n"
+ << " include(${f})\n"
+ << "endforeach()\n"
+ << "\n";
+ /* clang-format on */
+}
+
void cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string& input)
{
std::string::size_type pos = 0;