From 1fe4b82a45bfe3e578267d84c70d6e55610e2ced Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 20 Jul 2012 10:19:16 -0400 Subject: find_library: Add test covering lib->lib64 cases Add a "CMakeOnly.find_library" test covering various cases involving lib->lib64 (non-)conversion. Comment out cases involving mixed path components "lib" and "lib64", such as lib/A/lib64 and lib64/A/lib, as these are known to be broken currently. --- Tests/CMakeOnly/CMakeLists.txt | 2 + Tests/CMakeOnly/find_library/CMakeLists.txt | 61 ++++++++++++++++++++++ Tests/CMakeOnly/find_library/lib/64/libtest2.a | 0 Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a | 0 .../CMakeOnly/find_library/lib/A/lib64/libtest3.a | 0 Tests/CMakeOnly/find_library/lib/A/libtest1.a | 0 Tests/CMakeOnly/find_library/lib/libtest1.a | 0 Tests/CMakeOnly/find_library/lib/libtest2.a | 0 Tests/CMakeOnly/find_library/lib/libtest3.a | 0 .../CMakeOnly/find_library/lib64/A/lib/libtest2.a | 0 .../find_library/lib64/A/lib64/libtest1.a | 0 Tests/CMakeOnly/find_library/lib64/A/libtest1.a | 0 Tests/CMakeOnly/find_library/lib64/libtest1.a | 0 13 files changed, 63 insertions(+) create mode 100644 Tests/CMakeOnly/find_library/CMakeLists.txt create mode 100644 Tests/CMakeOnly/find_library/lib/64/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a create mode 100644 Tests/CMakeOnly/find_library/lib/A/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/lib/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/lib/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/lib/libtest3.a create mode 100644 Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a create mode 100644 Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/lib64/A/libtest1.a create mode 100644 Tests/CMakeOnly/find_library/lib64/libtest1.a diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt index a1551ca035..6fe91c7810 100644 --- a/Tests/CMakeOnly/CMakeLists.txt +++ b/Tests/CMakeOnly/CMakeLists.txt @@ -23,6 +23,8 @@ add_CMakeOnly_test(AllFindModules) add_CMakeOnly_test(TargetScope) +add_CMakeOnly_test(find_library) + add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND} -DTEST=ProjectInclude -DCMAKE_ARGS=-DCMAKE_PROJECT_ProjectInclude_INCLUDE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectInclude/include.cmake diff --git a/Tests/CMakeOnly/find_library/CMakeLists.txt b/Tests/CMakeOnly/find_library/CMakeLists.txt new file mode 100644 index 0000000000..193889620c --- /dev/null +++ b/Tests/CMakeOnly/find_library/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 2.8) +project(FindLibraryTest NONE) + +set(CMAKE_FIND_DEBUG_MODE 1) + +macro(test_find_library expected) + get_filename_component(dir ${expected} PATH) + get_filename_component(name ${expected} NAME) + string(REGEX REPLACE "lib/?64" "lib" dir "${dir}") + unset(LIB CACHE) + find_library(LIB + NAMES ${name} + PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${dir} + NO_DEFAULT_PATH + ) + if(LIB) + # Convert to relative path for comparison to expected location. + file(RELATIVE_PATH REL_LIB "${CMAKE_CURRENT_SOURCE_DIR}" "${LIB}") + + # Debugging output. + if(CMAKE_FIND_DEBUG_MODE) + message(STATUS "Library ${expected} searched as ${dir}, found as [${REL_LIB}].") + endif() + + # Check and report failure. + if(NOT "${REL_LIB}" STREQUAL "${expected}") + message(SEND_ERROR "Library ${l} should have been [${expected}] but was [${REL_LIB}]") + endif() + else() + message(SEND_ERROR "Library ${expected} searched as ${dir}, NOT FOUND!") + endif() +endmacro() + +set(CMAKE_FIND_LIBRARY_PREFIXES "lib") +set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE) + +set(CMAKE_SIZEOF_VOID_P 4) +foreach(lib + lib/A/lib/libtest1.a + lib/A/libtest1.a + lib/libtest1.a + lib/libtest2.a + lib/libtest3.a + lib/libtest3.a + ) + test_find_library(${lib}) +endforeach() + +set(CMAKE_SIZEOF_VOID_P 8) +foreach(lib64 + lib/64/libtest2.a + #lib/A/lib64/libtest3.a # known breakage + lib/libtest3.a + #lib64/A/lib/libtest2.a # known breakage + lib64/A/lib64/libtest1.a + lib64/A/libtest1.a + lib64/libtest1.a + ) + test_find_library(${lib64}) +endforeach() diff --git a/Tests/CMakeOnly/find_library/lib/64/libtest2.a b/Tests/CMakeOnly/find_library/lib/64/libtest2.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a b/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a b/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/A/libtest1.a b/Tests/CMakeOnly/find_library/lib/A/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/libtest1.a b/Tests/CMakeOnly/find_library/lib/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/libtest2.a b/Tests/CMakeOnly/find_library/lib/libtest2.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib/libtest3.a b/Tests/CMakeOnly/find_library/lib/libtest3.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a b/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a b/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib64/A/libtest1.a b/Tests/CMakeOnly/find_library/lib64/A/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/CMakeOnly/find_library/lib64/libtest1.a b/Tests/CMakeOnly/find_library/lib64/libtest1.a new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.1 From 6ca2f82d0d8dbb1f0f79c5fe1a4e21de78a57c84 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 20 Jul 2012 13:28:49 -0400 Subject: 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. --- Source/cmFindLibraryCommand.cxx | 53 ++++------------------------------------- Source/cmFindLibraryCommand.h | 1 - 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 6cdbbf2dc5..688d8a7655 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -105,7 +105,10 @@ bool cmFindLibraryCommand ->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS")) { // 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(); @@ -149,6 +152,7 @@ void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) // Now look for lib s = *i; s += suffix; + s += "/"; if(cmSystemTools::FileIsDirectory(s.c_str())) { 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 path64; - bool found64 = false; - for(std::vector::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() { diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index b880be2664..f91583bf5d 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -62,7 +62,6 @@ public: protected: void AddArchitecturePaths(const char* suffix); - void AddLib64Paths(); std::string FindLibrary(); virtual void GenerateDocumentation(); private: -- cgit v1.2.1 From 54add62f1b36ffc25f333762901e14b2def21db2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 20 Jul 2012 13:30:30 -0400 Subject: find_library: Simplify lib->lib expansion Simplify cmFindLibraryCommand::AddArchitecturePaths logic to avoid recording a separate 'found' status and populating an entire vector just to throw it away. --- Source/cmFindLibraryCommand.cxx | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 688d8a7655..06216cd752 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -132,44 +132,36 @@ bool cmFindLibraryCommand //---------------------------------------------------------------------------- void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix) { - std::vector newPaths; - bool found = false; + std::vector original; + original.swap(this->SearchPaths); std::string subpath = "lib"; subpath += suffix; subpath += "/"; - for(std::vector::iterator i = this->SearchPaths.begin(); - i != this->SearchPaths.end(); ++i) + 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())) { - found = true; - newPaths.push_back(s); + this->SearchPaths.push_back(s); } - // Now look for lib + // Now look for / s = *i; s += suffix; s += "/"; if(cmSystemTools::FileIsDirectory(s.c_str())) { - found = true; - newPaths.push_back(s); + this->SearchPaths.push_back(s); } - // now add the original unchanged path + // Now add the original unchanged path 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; - } } //---------------------------------------------------------------------------- -- cgit v1.2.1 From 733726edf61aa7889b57aa9490cb719c83d3ea0f Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 20 Jul 2012 14:09:57 -0400 Subject: 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 | 51 ++++++++++++++++++++--------- Source/cmFindLibraryCommand.h | 4 +++ 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 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->AddArchitecturePath(dir, pos+3+1, suffix, false); + } + } + if(fresh) + { + // Check for /. + 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 -- cgit v1.2.1 From af80da349bb259ccccac146cdd734afeedeec116 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Mon, 26 Mar 2012 16:45:04 +0200 Subject: remove lib64 Unix paths if the respective lib path is also given If FIND_LIBRARY_USE_LIB64_PATHS is set both will be searched anyway. --- Modules/FindBLAS.cmake | 4 ++-- Modules/FindGTK2.cmake | 2 -- Modules/FindLAPACK.cmake | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 9eadfd125d..5811a9d15e 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -81,9 +81,9 @@ if (NOT _libdir) if (WIN32) set(_libdir ENV LIB) elseif (APPLE) - set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH) + set(_libdir ENV DYLD_LIBRARY_PATH) else () - set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH) + set(_libdir ENV LD_LIBRARY_PATH) endif () endif () diff --git a/Modules/FindGTK2.cmake b/Modules/FindGTK2.cmake index a03c023e44..5fe52134ac 100644 --- a/Modules/FindGTK2.cmake +++ b/Modules/FindGTK2.cmake @@ -305,9 +305,7 @@ function(_GTK2_FIND_LIBRARY _var _lib _expand_vc _append_version) NAMES ${_lib_list} PATHS /opt/gnome/lib - /opt/gnome/lib64 /usr/openwin/lib - /usr/openwin/lib64 /sw/lib $ENV{GTKMM_BASEPATH}/lib [HKEY_CURRENT_USER\\SOFTWARE\\gtkmm\\2.4;Path]/lib diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake index 0ae98dfa7b..b867f21333 100644 --- a/Modules/FindLAPACK.cmake +++ b/Modules/FindLAPACK.cmake @@ -69,9 +69,9 @@ if (NOT _libdir) if (WIN32) set(_libdir ENV LIB) elseif (APPLE) - set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV DYLD_LIBRARY_PATH) + set(_libdir ENV DYLD_LIBRARY_PATH) else () - set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH) + set(_libdir ENV LD_LIBRARY_PATH) endif () endif () foreach(_library ${_list}) -- cgit v1.2.1