exports: define a CMAKE_FIND_PACKAGE_NAME var set by find_package()

This way the name of the searched package can be accessed in find-modules,
config-files and more importantly in generated target export files.
This is now used when a target export file detects that a required
target does not exist.

Alex
This commit is contained in:
Alex Neundorf 2012-09-23 18:40:40 +02:00 committed by Brad King
parent 0cfd055acd
commit 6f50a04cc1
2 changed files with 10 additions and 1 deletions

View File

@ -389,8 +389,15 @@ void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
for(unsigned int i=0; i<missingTargets.size(); ++i)
{
os << "IF(NOT TARGET \"" << missingTargets[i] << "\" )\n"
<< " MESSAGE(FATAL_ERROR \"Required imported target \\\""
<< " IF(CMAKE_FIND_PACKAGE_NAME)\n"
<< " SET( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
<< " SET( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
<< "\"Required imported target \\\"" << missingTargets[i]
<< "\\\" not found ! \")\n"
<< " ELSE()\n"
<< " MESSAGE(FATAL_ERROR \"Required imported target \\\""
<< missingTargets[i] << "\\\" not found ! \")\n"
<< " ENDIF()\n"
<< "ENDIF()\n";
}
os << "\n";

View File

@ -840,6 +840,8 @@ bool cmFindPackageCommand
//----------------------------------------------------------------------------
void cmFindPackageCommand::SetModuleVariables(const std::string& components)
{
this->AddFindDefinition("CMAKE_FIND_PACKAGE_NAME", this->Name.c_str());
// Store the list of components.
std::string components_var = this->Name + "_FIND_COMPONENTS";
this->AddFindDefinition(components_var.c_str(), components.c_str());