Merge topic 'CheckImportedFileExistenceInConfigDotCMakeFiles'
5c03438 install(EXPORT): Improve target import failure message format a2be068 install(EXPORT): Enforce existence of imported target files
This commit is contained in:
commit
7ed2ed9a2e
@ -368,3 +368,66 @@ 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\n"
|
||||
" \\\"${file}\\\"\n"
|
||||
"but this file does not exist. Possible reasons include:\n"
|
||||
"* The file was deleted, renamed, or moved to another location.\n"
|
||||
"* An install or uninstall procedure did not complete successfully.\n"
|
||||
"* The installation package was faulty and contained\n"
|
||||
" \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
|
||||
"but not all the files it references.\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";
|
||||
}
|
||||
|
@ -56,6 +56,11 @@ protected:
|
||||
void GenerateImportPropertyCode(std::ostream& os, const char* config,
|
||||
cmTarget* target,
|
||||
ImportPropertyMap const& properties);
|
||||
void GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
|
||||
ImportPropertyMap const& properties,
|
||||
const std::set<std::string>& importedLocations);
|
||||
void GenerateImportedFileCheckLoop(std::ostream& os);
|
||||
|
||||
|
||||
// Collect properties with detailed information about targets beyond
|
||||
// their location on disk.
|
||||
|
@ -167,16 +167,18 @@ cmExportInstallFileGenerator
|
||||
// Collect import properties for this target.
|
||||
cmTargetExport* te = *tei;
|
||||
ImportPropertyMap properties;
|
||||
std::set<std::string> importedLocations;
|
||||
this->SetImportLocationProperty(config, suffix, te->ArchiveGenerator,
|
||||
properties, importedLocations);
|
||||
this->SetImportLocationProperty(config, suffix, te->LibraryGenerator,
|
||||
properties, importedLocations);
|
||||
this->SetImportLocationProperty(config, suffix,
|
||||
te->ArchiveGenerator, properties);
|
||||
this->SetImportLocationProperty(config, suffix,
|
||||
te->LibraryGenerator, properties);
|
||||
this->SetImportLocationProperty(config, suffix,
|
||||
te->RuntimeGenerator, properties);
|
||||
this->SetImportLocationProperty(config, suffix,
|
||||
te->FrameworkGenerator, properties);
|
||||
this->SetImportLocationProperty(config, suffix,
|
||||
te->BundleGenerator, properties);
|
||||
te->RuntimeGenerator, properties,
|
||||
importedLocations);
|
||||
this->SetImportLocationProperty(config, suffix, te->FrameworkGenerator,
|
||||
properties, importedLocations);
|
||||
this->SetImportLocationProperty(config, suffix, te->BundleGenerator,
|
||||
properties, importedLocations);
|
||||
|
||||
// If any file location was set for the target add it to the
|
||||
// import file.
|
||||
@ -194,9 +196,13 @@ cmExportInstallFileGenerator
|
||||
|
||||
// Generate code in the export file.
|
||||
this->GenerateImportPropertyCode(os, config, te->Target, properties);
|
||||
this->GenerateImportedFileChecksCode(os, te->Target, properties,
|
||||
importedLocations);
|
||||
}
|
||||
}
|
||||
|
||||
this->GenerateImportedFileCheckLoop(os);
|
||||
|
||||
// Cleanup the import prefix variable.
|
||||
if(!this->ImportPrefix.empty())
|
||||
{
|
||||
@ -211,7 +217,9 @@ void
|
||||
cmExportInstallFileGenerator
|
||||
::SetImportLocationProperty(const char* config, std::string const& suffix,
|
||||
cmInstallTargetGenerator* itgen,
|
||||
ImportPropertyMap& properties)
|
||||
ImportPropertyMap& properties,
|
||||
std::set<std::string>& importedLocations
|
||||
)
|
||||
{
|
||||
// Skip rules that do not match this configuration.
|
||||
if(!(itgen && itgen->InstallsForConfig(config)))
|
||||
@ -249,6 +257,7 @@ cmExportInstallFileGenerator
|
||||
|
||||
// Store the property.
|
||||
properties[prop] = value;
|
||||
importedLocations.insert(prop);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -291,6 +300,7 @@ cmExportInstallFileGenerator
|
||||
|
||||
// Store the property.
|
||||
properties[prop] = value;
|
||||
importedLocations.insert(prop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,9 @@ protected:
|
||||
void SetImportLocationProperty(const char* config,
|
||||
std::string const& suffix,
|
||||
cmInstallTargetGenerator* itgen,
|
||||
ImportPropertyMap& properties);
|
||||
ImportPropertyMap& properties,
|
||||
std::set<std::string>& importedLocations
|
||||
);
|
||||
|
||||
void ComplainAboutImportPrefix(cmInstallTargetGenerator* itgen);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user