From 733726edf61aa7889b57aa9490cb719c83d3ea0f Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 20 Jul 2012 14:09:57 -0400 Subject: [PATCH] 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. --- Source/cmFindLibraryCommand.cxx | 53 ++++++++++++++------- Source/cmFindLibraryCommand.h | 4 ++ Tests/CMakeOnly/find_library/CMakeLists.txt | 4 +- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 06216cd75..652e697ed 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -134,32 +134,51 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) { std::vector original; original.swap(this->SearchPaths); - std::string subpath = "lib"; - subpath += suffix; - subpath += "/"; for(std::vector::iterator i = original.begin(); i != original.end(); ++i) { - // Try replacing lib/ with lib/ - 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". + 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 / - 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 /. + 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); } } } diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index f91583bf5..31a5c3f8d 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 193889620..08f9331e1 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