find_library: Fix mixed lib->lib64 (non-)conversion cases (#13419)

When a search path contains multiple "lib/" instances we previously
converted all or none.  This fails for cases where only some of the
multiple instances must be converted.  Teach AddArchitecturePaths to
generate all combinations that exist.  Uncomment these cases in the
CMakeOnly.find_library test now that they work.
This commit is contained in:
Brad King 2012-07-20 14:09:57 -04:00
parent 54add62f1b
commit 733726edf6
3 changed files with 42 additions and 19 deletions

View File

@ -134,32 +134,51 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
{
std::vector<std::string> original;
original.swap(this->SearchPaths);
std::string subpath = "lib";
subpath += suffix;
subpath += "/";
for(std::vector<std::string>::iterator i = original.begin();
i != original.end(); ++i)
{
// Try replacing lib/ with lib<suffix>/
std::string s = *i;
cmSystemTools::ReplaceString(s, "lib/", subpath.c_str());
if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str()))
this->AddArchitecturePath(*i, 0, suffix);
}
}
//----------------------------------------------------------------------------
void cmFindLibraryCommand::AddArchitecturePath(
std::string const& dir, std::string::size_type start_pos,
const char* suffix, bool fresh)
{
std::string::size_type pos = dir.find("lib/", start_pos);
if(pos != std::string::npos)
{
std::string cur_dir = dir.substr(0,pos+3);
// Follow "lib<suffix>".
std::string next_dir = cur_dir + suffix;
if(cmSystemTools::FileIsDirectory(next_dir.c_str()))
{
this->SearchPaths.push_back(s);
next_dir += dir.substr(pos+3);
std::string::size_type next_pos = pos+3+strlen(suffix)+1;
this->AddArchitecturePath(next_dir, next_pos, suffix);
}
// Now look for <original><suffix>/
s = *i;
s += suffix;
s += "/";
if(cmSystemTools::FileIsDirectory(s.c_str()))
// Follow "lib".
if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
{
this->SearchPaths.push_back(s);
this->AddArchitecturePath(dir, pos+3+1, suffix, false);
}
// Now add the original unchanged path
if(cmSystemTools::FileIsDirectory(i->c_str()))
}
if(fresh)
{
// Check for <dir><suffix>/.
std::string cur_dir = dir + suffix + "/";
if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
{
this->SearchPaths.push_back(*i);
this->SearchPaths.push_back(cur_dir);
}
// Now add the original unchanged path
if(cmSystemTools::FileIsDirectory(dir.c_str()))
{
this->SearchPaths.push_back(dir);
}
}
}

View File

@ -62,6 +62,10 @@ public:
protected:
void AddArchitecturePaths(const char* suffix);
void AddArchitecturePath(std::string const& dir,
std::string::size_type start_pos,
const char* suffix,
bool fresh = true);
std::string FindLibrary();
virtual void GenerateDocumentation();
private:

View File

@ -50,9 +50,9 @@ endforeach()
set(CMAKE_SIZEOF_VOID_P 8)
foreach(lib64
lib/64/libtest2.a
#lib/A/lib64/libtest3.a # known breakage
lib/A/lib64/libtest3.a
lib/libtest3.a
#lib64/A/lib/libtest2.a # known breakage
lib64/A/lib/libtest2.a
lib64/A/lib64/libtest1.a
lib64/A/libtest1.a
lib64/libtest1.a