diff options
author | Brad King <brad.king@kitware.com> | 2012-07-20 14:09:57 -0400 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-07-20 14:19:11 -0400 |
commit | 733726edf61aa7889b57aa9490cb719c83d3ea0f (patch) | |
tree | 7e757a1828ac7e9a936b1161aea7dcb70ba91680 | |
parent | 54add62f1b36ffc25f333762901e14b2def21db2 (diff) | |
download | cmake-733726edf61aa7889b57aa9490cb719c83d3ea0f.tar.gz |
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.
-rw-r--r-- | Source/cmFindLibraryCommand.cxx | 51 | ||||
-rw-r--r-- | Source/cmFindLibraryCommand.h | 4 | ||||
-rw-r--r-- | Tests/CMakeOnly/find_library/CMakeLists.txt | 4 |
3 files changed, 41 insertions, 18 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 06216cd752..652e697edd 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -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->AddArchitecturePath(dir, pos+3+1, suffix, false); + } + } + if(fresh) + { + // Check for <dir><suffix>/. + std::string cur_dir = dir + suffix + "/"; + if(cmSystemTools::FileIsDirectory(cur_dir.c_str())) { - this->SearchPaths.push_back(s); + this->SearchPaths.push_back(cur_dir); } + // Now add the original unchanged path - if(cmSystemTools::FileIsDirectory(i->c_str())) + if(cmSystemTools::FileIsDirectory(dir.c_str())) { - this->SearchPaths.push_back(*i); + this->SearchPaths.push_back(dir); } } } diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index f91583bf5d..31a5c3f8df 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -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: diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt index 193889620c..08f9331e11 100644 --- a/Tests/CMakeOnly/find_library/CMakeLists.txt +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -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 |