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()
}
}
// Search for the config file if it is not already found.
if(cmSystemTools::IsOff(def))
{
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;
// Try to load the config file if the directory is known
bool cachedDirectoryOk = false;
if(!cmSystemTools::IsOff(def))
{
// Get the directory from the variable value.
......@@ -733,16 +724,37 @@ bool cmFindPackageCommand::HandlePackageMode()
dir = "/" + dir;
dir = this->Makefile->GetCurrentDirectory() + dir;
}
// The file location was cached. Look for the correct file.
std::string file;
if (this->FindConfigFile(dir, file))
{
this->FileFound = file;
cachedDirectoryOk = true;
}
def = this->Makefile->GetDefinition(this->Variable.c_str());
}
// Search for the config file if it is not already found.
if(cmSystemTools::IsOff(def) || !cachedDirectoryOk)
{
this->FindConfig();
def = this->Makefile->GetDefinition(this->Variable.c_str());
}
// Find the configuration file.
if(this->FindConfigFileToLoad(dir, file))
// If the directory for the config file was found, try to read the file.
bool result = true;
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(file.c_str()))
if(this->ReadListFile(this->FileFound.c_str()))
{
// The package has been found.
found = true;
......@@ -753,21 +765,6 @@ bool cmFindPackageCommand::HandlePackageMode()
result = false;
}
}
else
{
// The variable setting is wrong.
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;
}
}
else if(!this->Quiet || this->Required)
{
// The variable is not set.
......@@ -816,7 +813,7 @@ bool cmFindPackageCommand::HandlePackageMode()
fileVar += "_CONFIG";
if(found)
{
this->Makefile->AddDefinition(fileVar.c_str(), file.c_str());
this->Makefile->AddDefinition(fileVar.c_str(), this->FileFound.c_str());
}
else
{
......@@ -1244,24 +1241,6 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
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)
{
......
......@@ -97,7 +97,6 @@ private:
bool SearchDirectory(std::string const& dir);
bool CheckDirectory(std::string const& dir);
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 CheckVersionFile(std::string const& version_file);
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