Commit ef3e48c3 authored by Alexander Neundorf's avatar Alexander Neundorf

ENH: when trying to find a FooConfig.cmake file, if in the directory pointed

to by the Foo_DIR variable there is no FooConfig.cmake file, then instead of
abort and complain that the user should set or clear the Foo_DIR variables,
just search for the file and discard the old Foo_DIR contents

The tests succeed, ok by Brad.

Alex
parent 206c09c4
...@@ -710,17 +710,8 @@ bool cmFindPackageCommand::HandlePackageMode() ...@@ -710,17 +710,8 @@ bool cmFindPackageCommand::HandlePackageMode()
} }
} }
// Search for the config file if it is not already found. // Try to load the config file if the directory is known
if(cmSystemTools::IsOff(def)) bool cachedDirectoryOk = false;
{
this->FindConfig();
def = this->Makefile->GetDefinition(this->Variable.c_str());
}
// If the config file was found, load it.
std::string file;
bool result = true;
bool found = false;
if(!cmSystemTools::IsOff(def)) if(!cmSystemTools::IsOff(def))
{ {
// Get the directory from the variable value. // Get the directory from the variable value.
...@@ -733,38 +724,44 @@ bool cmFindPackageCommand::HandlePackageMode() ...@@ -733,38 +724,44 @@ bool cmFindPackageCommand::HandlePackageMode()
dir = "/" + dir; dir = "/" + dir;
dir = this->Makefile->GetCurrentDirectory() + dir; dir = this->Makefile->GetCurrentDirectory() + dir;
} }
// The file location was cached. Look for the correct file.
// Find the configuration file. std::string file;
if(this->FindConfigFileToLoad(dir, file)) if (this->FindConfigFile(dir, file))
{ {
// Set the version variables before loading the config file. this->FileFound = file;
// It may override them. cachedDirectoryOk = true;
this->StoreVersionFound(); }
def = this->Makefile->GetDefinition(this->Variable.c_str());
}
// Parse the configuration file. // Search for the config file if it is not already found.
if(this->ReadListFile(file.c_str())) if(cmSystemTools::IsOff(def) || !cachedDirectoryOk)
{ {
// The package has been found. this->FindConfig();
found = true; def = this->Makefile->GetDefinition(this->Variable.c_str());
} }
else
{ // If the directory for the config file was found, try to read the file.
// The configuration file is invalid. bool result = true;
result = false; bool found = false;
} // in the following test FileFound should never be empty if def is valid
// but I don't want to put an assert() in there now, in case this still
// makes it into 2.6.3
if(!cmSystemTools::IsOff(def) && (!this->FileFound.empty()))
{
// Set the version variables before loading the config file.
// It may override them.
this->StoreVersionFound();
// Parse the configuration file.
if(this->ReadListFile(this->FileFound.c_str()))
{
// The package has been found.
found = true;
} }
else else
{ {
// The variable setting is wrong. // The configuration file is invalid.
cmOStringStream e;
e << "cannot find package " << this->Name << " because "
<< this->Variable << " is set to \"" << def << "\" "
<< "which is not a directory containing a package configuration "
<< "file (or it is not for the requested version). "
<< "Please set the cache entry " << this->Variable << " "
<< "to the correct directory, or delete it to ask CMake "
<< "to search.";
this->SetError(e.str().c_str());
result = false; result = false;
} }
} }
...@@ -816,7 +813,7 @@ bool cmFindPackageCommand::HandlePackageMode() ...@@ -816,7 +813,7 @@ bool cmFindPackageCommand::HandlePackageMode()
fileVar += "_CONFIG"; fileVar += "_CONFIG";
if(found) if(found)
{ {
this->Makefile->AddDefinition(fileVar.c_str(), file.c_str()); this->Makefile->AddDefinition(fileVar.c_str(), this->FileFound.c_str());
} }
else else
{ {
...@@ -1244,24 +1241,6 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir, ...@@ -1244,24 +1241,6 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
return false; return false;
} }
//----------------------------------------------------------------------------
bool cmFindPackageCommand::FindConfigFileToLoad(std::string const& dir,
std::string& file)
{
if(this->FileFound.empty())
{
// The file location was cached. Look for the correct file.
return this->FindConfigFile(dir, file);
}
else
{
// The file location was just found during this call.
// Use the file found without searching again.
file = this->FileFound;
return true;
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmFindPackageCommand::CheckVersion(std::string const& config_file) bool cmFindPackageCommand::CheckVersion(std::string const& config_file)
{ {
......
...@@ -97,7 +97,6 @@ private: ...@@ -97,7 +97,6 @@ private:
bool SearchDirectory(std::string const& dir); bool SearchDirectory(std::string const& dir);
bool CheckDirectory(std::string const& dir); bool CheckDirectory(std::string const& dir);
bool FindConfigFile(std::string const& dir, std::string& file); bool FindConfigFile(std::string const& dir, std::string& file);
bool FindConfigFileToLoad(std::string const& dir, std::string& file);
bool CheckVersion(std::string const& config_file); bool CheckVersion(std::string const& config_file);
bool CheckVersionFile(std::string const& version_file); bool CheckVersionFile(std::string const& version_file);
bool SearchPrefix(std::string const& prefix); bool SearchPrefix(std::string const& prefix);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment