find_library: Simplify lib->lib<arch> expansion

Simplify cmFindLibraryCommand::AddArchitecturePaths logic to avoid
recording a separate 'found' status and populating an entire
vector<string> just to throw it away.
This commit is contained in:
Brad King 2012-07-20 13:30:30 -04:00
parent 6ca2f82d0d
commit 54add62f1b
1 changed files with 9 additions and 17 deletions

View File

@ -132,44 +132,36 @@ bool cmFindLibraryCommand
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
{ {
std::vector<std::string> newPaths; std::vector<std::string> original;
bool found = false; original.swap(this->SearchPaths);
std::string subpath = "lib"; std::string subpath = "lib";
subpath += suffix; subpath += suffix;
subpath += "/"; subpath += "/";
for(std::vector<std::string>::iterator i = this->SearchPaths.begin(); for(std::vector<std::string>::iterator i = original.begin();
i != this->SearchPaths.end(); ++i) i != original.end(); ++i)
{ {
// Try replacing lib/ with lib<suffix>/ // Try replacing lib/ with lib<suffix>/
std::string s = *i; std::string s = *i;
cmSystemTools::ReplaceString(s, "lib/", subpath.c_str()); cmSystemTools::ReplaceString(s, "lib/", subpath.c_str());
if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str())) if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str()))
{ {
found = true; this->SearchPaths.push_back(s);
newPaths.push_back(s);
} }
// Now look for lib<suffix> // Now look for <original><suffix>/
s = *i; s = *i;
s += suffix; s += suffix;
s += "/"; s += "/";
if(cmSystemTools::FileIsDirectory(s.c_str())) if(cmSystemTools::FileIsDirectory(s.c_str()))
{ {
found = true; this->SearchPaths.push_back(s);
newPaths.push_back(s);
} }
// now add the original unchanged path // Now add the original unchanged path
if(cmSystemTools::FileIsDirectory(i->c_str())) if(cmSystemTools::FileIsDirectory(i->c_str()))
{ {
newPaths.push_back(*i); this->SearchPaths.push_back(*i);
} }
} }
// If any new paths were found replace the original set.
if(found)
{
this->SearchPaths = newPaths;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------