exports: first try at error handling if a target is missing
Now, if an imported target depends on a library which must come from some other export set, cmake generates a check which errors out if that target does not exist. I guess instead of completely erroring out it would be better to only make the find_package() fail. Alex
This commit is contained in:
parent
87f4c01910
commit
8b5f448ba6
|
@ -72,8 +72,9 @@ cmExportBuildFileGenerator
|
||||||
if(!properties.empty())
|
if(!properties.empty())
|
||||||
{
|
{
|
||||||
// Get the rest of the target details.
|
// Get the rest of the target details.
|
||||||
|
std::vector<std::string> missingTargets;
|
||||||
this->SetImportDetailProperties(config, suffix,
|
this->SetImportDetailProperties(config, suffix,
|
||||||
target, properties);
|
target, properties, missingTargets);
|
||||||
|
|
||||||
// TOOD: PUBLIC_HEADER_LOCATION
|
// TOOD: PUBLIC_HEADER_LOCATION
|
||||||
// This should wait until the build feature propagation stuff
|
// This should wait until the build feature propagation stuff
|
||||||
|
@ -82,6 +83,7 @@ cmExportBuildFileGenerator
|
||||||
// properties);
|
// properties);
|
||||||
|
|
||||||
// Generate code in the export file.
|
// Generate code in the export file.
|
||||||
|
this->GenerateMissingTargetsCheckCode(os, missingTargets);
|
||||||
this->GenerateImportPropertyCode(os, config, target, properties);
|
this->GenerateImportPropertyCode(os, config, target, properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,9 @@ void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
|
||||||
void
|
void
|
||||||
cmExportFileGenerator
|
cmExportFileGenerator
|
||||||
::SetImportDetailProperties(const char* config, std::string const& suffix,
|
::SetImportDetailProperties(const char* config, std::string const& suffix,
|
||||||
cmTarget* target, ImportPropertyMap& properties)
|
cmTarget* target, ImportPropertyMap& properties,
|
||||||
|
std::vector<std::string>& missingTargets
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Get the makefile in which to lookup target information.
|
// Get the makefile in which to lookup target information.
|
||||||
cmMakefile* mf = target->GetMakefile();
|
cmMakefile* mf = target->GetMakefile();
|
||||||
|
@ -164,13 +166,13 @@ cmExportFileGenerator
|
||||||
{
|
{
|
||||||
this->SetImportLinkProperty(suffix, target,
|
this->SetImportLinkProperty(suffix, target,
|
||||||
"IMPORTED_LINK_INTERFACE_LANGUAGES",
|
"IMPORTED_LINK_INTERFACE_LANGUAGES",
|
||||||
iface->Languages, properties);
|
iface->Languages, properties, missingTargets);
|
||||||
this->SetImportLinkProperty(suffix, target,
|
this->SetImportLinkProperty(suffix, target,
|
||||||
"IMPORTED_LINK_INTERFACE_LIBRARIES",
|
"IMPORTED_LINK_INTERFACE_LIBRARIES",
|
||||||
iface->Libraries, properties);
|
iface->Libraries, properties, missingTargets);
|
||||||
this->SetImportLinkProperty(suffix, target,
|
this->SetImportLinkProperty(suffix, target,
|
||||||
"IMPORTED_LINK_DEPENDENT_LIBRARIES",
|
"IMPORTED_LINK_DEPENDENT_LIBRARIES",
|
||||||
iface->SharedDeps, properties);
|
iface->SharedDeps, properties, missingTargets);
|
||||||
if(iface->Multiplicity > 0)
|
if(iface->Multiplicity > 0)
|
||||||
{
|
{
|
||||||
std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
|
std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
|
||||||
|
@ -189,7 +191,9 @@ cmExportFileGenerator
|
||||||
cmTarget* target,
|
cmTarget* target,
|
||||||
const char* propName,
|
const char* propName,
|
||||||
std::vector<std::string> const& libs,
|
std::vector<std::string> const& libs,
|
||||||
ImportPropertyMap& properties)
|
ImportPropertyMap& properties,
|
||||||
|
std::vector<std::string>& missingTargets
|
||||||
|
)
|
||||||
{
|
{
|
||||||
// Skip the property if there are no libraries.
|
// Skip the property if there are no libraries.
|
||||||
if(libs.empty())
|
if(libs.empty())
|
||||||
|
@ -234,8 +238,10 @@ cmExportFileGenerator
|
||||||
|
|
||||||
if (targetOccurrences == 1)
|
if (targetOccurrences == 1)
|
||||||
{
|
{
|
||||||
link_libs += namespaces[0];
|
std::string missingTarget = namespaces[0];
|
||||||
link_libs += *li;
|
missingTarget += *li;
|
||||||
|
link_libs += missingTarget;
|
||||||
|
missingTargets.push_back(missingTarget);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -438,6 +444,23 @@ cmExportFileGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
|
||||||
|
const std::vector<std::string>& missingTargets)
|
||||||
|
{
|
||||||
|
os << "# Make sure the targets which have been exported in some other \n"
|
||||||
|
"# export set exist.\n";
|
||||||
|
for(unsigned int i=0; i<missingTargets.size(); ++i)
|
||||||
|
{
|
||||||
|
os << "IF(NOT TARGET \"" << missingTargets[i] << "\" )\n"
|
||||||
|
<< " MESSAGE(FATAL_ERROR \"Required imported target \\\""
|
||||||
|
<< missingTargets[i] << "\\\" not found ! \")\n"
|
||||||
|
<< "ENDIF()\n";
|
||||||
|
}
|
||||||
|
os << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
|
cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
|
||||||
|
|
|
@ -60,17 +60,21 @@ protected:
|
||||||
ImportPropertyMap const& properties,
|
ImportPropertyMap const& properties,
|
||||||
const std::set<std::string>& importedLocations);
|
const std::set<std::string>& importedLocations);
|
||||||
void GenerateImportedFileCheckLoop(std::ostream& os);
|
void GenerateImportedFileCheckLoop(std::ostream& os);
|
||||||
|
void GenerateMissingTargetsCheckCode(std::ostream& os,
|
||||||
|
const std::vector<std::string>& missingTargets);
|
||||||
|
|
||||||
|
|
||||||
// Collect properties with detailed information about targets beyond
|
// Collect properties with detailed information about targets beyond
|
||||||
// their location on disk.
|
// their location on disk.
|
||||||
void SetImportDetailProperties(const char* config,
|
void SetImportDetailProperties(const char* config,
|
||||||
std::string const& suffix, cmTarget* target,
|
std::string const& suffix, cmTarget* target,
|
||||||
ImportPropertyMap& properties);
|
ImportPropertyMap& properties,
|
||||||
|
std::vector<std::string>& missingTargets);
|
||||||
void SetImportLinkProperty(std::string const& suffix,
|
void SetImportLinkProperty(std::string const& suffix,
|
||||||
cmTarget* target, const char* propName,
|
cmTarget* target, const char* propName,
|
||||||
std::vector<std::string> const& libs,
|
std::vector<std::string> const& libs,
|
||||||
ImportPropertyMap& properties);
|
ImportPropertyMap& properties,
|
||||||
|
std::vector<std::string>& missingTargets);
|
||||||
|
|
||||||
/** Each subclass knows how to generate its kind of export file. */
|
/** Each subclass knows how to generate its kind of export file. */
|
||||||
virtual bool GenerateMainFile(std::ostream& os) = 0;
|
virtual bool GenerateMainFile(std::ostream& os) = 0;
|
||||||
|
|
|
@ -188,8 +188,9 @@ cmExportInstallFileGenerator
|
||||||
if(!properties.empty())
|
if(!properties.empty())
|
||||||
{
|
{
|
||||||
// Get the rest of the target details.
|
// Get the rest of the target details.
|
||||||
|
std::vector<std::string> missingTargets;
|
||||||
this->SetImportDetailProperties(config, suffix,
|
this->SetImportDetailProperties(config, suffix,
|
||||||
te->Target, properties);
|
te->Target, properties, missingTargets);
|
||||||
|
|
||||||
// TOOD: PUBLIC_HEADER_LOCATION
|
// TOOD: PUBLIC_HEADER_LOCATION
|
||||||
// This should wait until the build feature propagation stuff
|
// This should wait until the build feature propagation stuff
|
||||||
|
@ -198,6 +199,7 @@ cmExportInstallFileGenerator
|
||||||
// properties);
|
// properties);
|
||||||
|
|
||||||
// Generate code in the export file.
|
// Generate code in the export file.
|
||||||
|
this->GenerateMissingTargetsCheckCode(os, missingTargets);
|
||||||
this->GenerateImportPropertyCode(os, config, te->Target, properties);
|
this->GenerateImportPropertyCode(os, config, te->Target, properties);
|
||||||
this->GenerateImportedFileChecksCode(os, te->Target, properties,
|
this->GenerateImportedFileChecksCode(os, te->Target, properties,
|
||||||
importedLocations);
|
importedLocations);
|
||||||
|
|
Loading…
Reference in New Issue