find_library: Refactor lib->lib64 conversion

Previously methods AddArchitecturePaths and AddLib64Paths were almost
identical.  Replace the latter with a call to the former.  Fix the
AddArchitecturePaths implementation to add trailing slashes to all
tested paths.
This commit is contained in:
Brad King 2012-07-20 13:28:49 -04:00
parent 1fe4b82a45
commit 6ca2f82d0d
2 changed files with 5 additions and 49 deletions

View File

@ -105,7 +105,10 @@ bool cmFindLibraryCommand
->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS")) ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
{ {
// add special 64 bit paths if this is a 64 bit compile. // add special 64 bit paths if this is a 64 bit compile.
this->AddLib64Paths(); if(this->Makefile->PlatformIs64Bit())
{
this->AddArchitecturePaths("64");
}
} }
std::string library = this->FindLibrary(); std::string library = this->FindLibrary();
@ -149,6 +152,7 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
// Now look for lib<suffix> // Now look for lib<suffix>
s = *i; s = *i;
s += suffix; s += suffix;
s += "/";
if(cmSystemTools::FileIsDirectory(s.c_str())) if(cmSystemTools::FileIsDirectory(s.c_str()))
{ {
found = true; found = true;
@ -168,53 +172,6 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
} }
} }
void cmFindLibraryCommand::AddLib64Paths()
{
std::string voidsize =
this->Makefile->GetSafeDefinition("CMAKE_SIZEOF_VOID_P");
int size = atoi(voidsize.c_str());
if(size != 8)
{
return;
}
std::vector<std::string> path64;
bool found64 = false;
for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
i != this->SearchPaths.end(); ++i)
{
std::string s = *i;
std::string s2 = *i;
cmSystemTools::ReplaceString(s, "lib/", "lib64/");
// try to replace lib with lib64 and see if it is there,
// then prepend it to the path
// Note that all paths have trailing slashes.
if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str()))
{
path64.push_back(s);
found64 = true;
}
// now just add a 64 to the path name and if it is there,
// add it to the path
s2 += "64/";
if(cmSystemTools::FileIsDirectory(s2.c_str()))
{
found64 = true;
path64.push_back(s2);
}
// now add the original unchanged path
if(cmSystemTools::FileIsDirectory(i->c_str()))
{
path64.push_back(*i);
}
}
// now replace the SearchPaths with the 64 bit converted path
// if any 64 bit paths were discovered
if(found64)
{
this->SearchPaths = path64;
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmFindLibraryCommand::FindLibrary() std::string cmFindLibraryCommand::FindLibrary()
{ {

View File

@ -62,7 +62,6 @@ public:
protected: protected:
void AddArchitecturePaths(const char* suffix); void AddArchitecturePaths(const char* suffix);
void AddLib64Paths();
std::string FindLibrary(); std::string FindLibrary();
virtual void GenerateDocumentation(); virtual void GenerateDocumentation();
private: private: