summaryrefslogtreecommitdiffstats
path: root/Source/cmExportFileGenerator.cxx
diff options
context:
space:
mode:
authorAlex Neundorf <neundorf@kde.org>2011-11-12 17:12:07 (GMT)
committerBrad King <brad.king@kitware.com>2011-11-22 20:55:00 (GMT)
commita2be068c75890a9b6723c0bbb2d32a108cb84eed (patch)
tree782be0b5570258cae5fdf292081eacf9120082a7 /Source/cmExportFileGenerator.cxx
parentb90b6969f68950d57e6ba23fa92780c78c804218 (diff)
downloadCMake-a2be068c75890a9b6723c0bbb2d32a108cb84eed.zip
CMake-a2be068c75890a9b6723c0bbb2d32a108cb84eed.tar.gz
CMake-a2be068c75890a9b6723c0bbb2d32a108cb84eed.tar.bz2
install(EXPORT): Enforce existence of imported target files
Typical <package>Config.cmake files for find_package() rely only on the files generated by install(EXPORT). They might be wrong, for whatever reasons, like people manually deleted files, projects were packaged wrong by distributions, whatever. To protect against this, add checks that the file locations we are importing actually exist on disk. Alex
Diffstat (limited to 'Source/cmExportFileGenerator.cxx')
-rw-r--r--Source/cmExportFileGenerator.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 9e5c91e..7777373 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -368,3 +368,69 @@ cmExportFileGenerator
os << " )\n"
<< "\n";
}
+
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
+{
+ // Add code which verifies at cmake time that the file which is being
+ // imported actually exists on disk. This should in theory always be theory
+ // case, but still when packages are split into normal and development
+ // packages this might get broken (e.g. the Config.cmake could be part of
+ // the non-development package, something similar happened to me without
+ // on SUSE with a mysql pkg-config file, which claimed everything is fine,
+ // but the development package was not installed.).
+ os << "# Loop over all imported files and verify that they actually exist\n"
+ "FOREACH(target ${_IMPORT_CHECK_TARGETS} )\n"
+ " FOREACH(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
+ " IF(NOT EXISTS \"${file}\" )\n"
+ " MESSAGE(FATAL_ERROR \"The imported target \\\"${target}\\\" "
+ "references the file \\\"${file}\\\", but this file does not exist. "
+ "There are multiple possible reasons:\n"
+ " * The file \\\"${file}\\\" has been manually "
+ "deleted, renamed or moved to another location.\n"
+ " * A previous install or uninstall procedure did not complete "
+ " successfully.\n"
+ " * The installation package was faulty, and contained\n"
+ "\\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
+ "but not\n"
+ "\\\"${file}\\\"\n"
+ "which must always be installed together.\\n\"\n"
+ " )\n"
+ " ENDIF()\n"
+ " ENDFOREACH()\n"
+ " UNSET(_IMPORT_CHECK_FILES_FOR_${target})\n"
+ "ENDFOREACH()\n"
+ "UNSET(_IMPORT_CHECK_TARGETS)\n"
+ "\n";
+}
+
+
+//----------------------------------------------------------------------------
+void
+cmExportFileGenerator
+::GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
+ ImportPropertyMap const& properties,
+ const std::set<std::string>& importedLocations)
+{
+ // Construct the imported target name.
+ std::string targetName = this->Namespace;
+ targetName += target->GetName();
+
+ os << "LIST(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n"
+ "LIST(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " ";
+
+ for(std::set<std::string>::const_iterator li = importedLocations.begin();
+ li != importedLocations.end();
+ ++li)
+ {
+ ImportPropertyMap::const_iterator pi = properties.find(*li);
+ if (pi != properties.end())
+ {
+ os << "\"" << pi->second << "\" ";
+ }
+ }
+
+ os << ")\n\n";
+}