diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx index a35f5cf6e..c7e3581d7 100644 --- a/Source/cmExportInstallFileGenerator.cxx +++ b/Source/cmExportInstallFileGenerator.cxx @@ -69,6 +69,27 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) this->GenerateExpectedTargetsCode(os, expectedTargets); } + // Add code to compute the installation prefix relative to the + // import file location. + const char* installDest = this->IEGen->GetDestination(); + if(!cmSystemTools::FileIsFullPath(installDest)) + { + 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"; + + // Import location properties may reference this variable. + this->ImportPrefix = "${_IMPORT_PREFIX}/"; + } + std::vector missingTargets; // Create all the imported targets. @@ -107,6 +128,13 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os) << "endforeach()\n" << "\n"; + // Cleanup the import prefix variable. + if(!this->ImportPrefix.empty()) + { + os << "# Cleanup temporary variables.\n" + << "set(_IMPORT_PREFIX)\n" + << "\n"; + } this->GenerateImportedFileCheckLoop(os); // Generate an import file for each configuration. @@ -187,27 +215,6 @@ cmExportInstallFileGenerator const char* config, std::string const& suffix, std::vector &missingTargets) { - // Add code to compute the installation prefix relative to the - // import file location. - const char* installDest = this->IEGen->GetDestination(); - if(!cmSystemTools::FileIsFullPath(installDest)) - { - 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"; - - // Import location properties may reference this variable. - this->ImportPrefix = "${_IMPORT_PREFIX}/"; - } - // Add each target in the set to the export. for(std::vector::const_iterator tei = this->IEGen->GetExportSet()->GetTargetExports()->begin(); @@ -253,14 +260,6 @@ cmExportInstallFileGenerator importedLocations); } } - - // Cleanup the import prefix variable. - if(!this->ImportPrefix.empty()) - { - os << "# Cleanup temporary variables.\n" - << "set(_IMPORT_PREFIX)\n" - << "\n"; - } } //----------------------------------------------------------------------------