summaryrefslogtreecommitdiffstats
path: root/Source/cmFindPackageCommand.cxx
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2009-01-08 22:57:52 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2009-01-08 22:57:52 (GMT)
commitef3e48c3d566a8d0d547a2a65bf18281a0aef664 (patch)
tree8ed49d007f0ffaab2d508ced35b9b997d6a21b0d /Source/cmFindPackageCommand.cxx
parent206c09c4f66fff69ea35f3434834c98a9e4a8fa9 (diff)
downloadCMake-ef3e48c3d566a8d0d547a2a65bf18281a0aef664.zip
CMake-ef3e48c3d566a8d0d547a2a65bf18281a0aef664.tar.gz
CMake-ef3e48c3d566a8d0d547a2a65bf18281a0aef664.tar.bz2
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
Diffstat (limited to 'Source/cmFindPackageCommand.cxx')
-rw-r--r--Source/cmFindPackageCommand.cxx93
1 files changed, 36 insertions, 57 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 9577b42..7432c84 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -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,38 +724,44 @@ bool cmFindPackageCommand::HandlePackageMode()
dir = "/" + dir;
dir = this->Makefile->GetCurrentDirectory() + dir;
}
-
- // Find the configuration file.
- if(this->FindConfigFileToLoad(dir, file))
+ // The file location was cached. Look for the correct file.
+ std::string file;
+ if (this->FindConfigFile(dir, file))
{
- // Set the version variables before loading the config file.
- // It may override them.
- this->StoreVersionFound();
+ this->FileFound = file;
+ cachedDirectoryOk = true;
+ }
+ def = this->Makefile->GetDefinition(this->Variable.c_str());
+ }
- // Parse the configuration file.
- if(this->ReadListFile(file.c_str()))
- {
- // The package has been found.
- found = true;
- }
- else
- {
- // The configuration file is invalid.
- result = false;
- }
+ // 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());
+ }
+
+ // 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(this->FileFound.c_str()))
+ {
+ // The package has been found.
+ found = true;
}
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());
+ // The configuration file is invalid.
result = false;
}
}
@@ -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
{
@@ -1245,24 +1242,6 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
}
//----------------------------------------------------------------------------
-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)
{
// Get the filename without the .cmake extension.