summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2012-08-13 13:26:57 -0400
committerCMake Topic Stage <kwrobot@kitware.com>2012-08-13 13:26:57 -0400
commit85f843a7b4aaf1b25e1e1e60ecdae3a3e2d7a9cb (patch)
treef25dae6a02680f4659322e65a54e5b421d900aea
parente93d9c5c2b8095cf94ebb92763604db0108e0818 (diff)
parentaf80da349bb259ccccac146cdd734afeedeec116 (diff)
downloadcmake-85f843a7b4aaf1b25e1e1e60ecdae3a3e2d7a9cb.tar.gz
Merge topic 'mixed-lib-to-lib64'
af80da3 remove lib64 Unix paths if the respective lib path is also given 733726e find_library: Fix mixed lib->lib64 (non-)conversion cases (#13419) 54add62 find_library: Simplify lib->lib<arch> expansion 6ca2f82 find_library: Refactor lib->lib64 conversion 1fe4b82 find_library: Add test covering lib->lib64 cases
-rw-r--r--Modules/FindBLAS.cmake4
-rw-r--r--Modules/FindGTK2.cmake2
-rw-r--r--Modules/FindLAPACK.cmake4
-rw-r--r--Source/cmFindLibraryCommand.cxx114
-rw-r--r--Source/cmFindLibraryCommand.h5
-rw-r--r--Tests/CMakeOnly/CMakeLists.txt2
-rw-r--r--Tests/CMakeOnly/find_library/CMakeLists.txt61
-rw-r--r--Tests/CMakeOnly/find_library/lib/64/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/A/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib/libtest3.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/A/libtest1.a0
-rw-r--r--Tests/CMakeOnly/find_library/lib64/libtest1.a0
18 files changed, 112 insertions, 80 deletions
diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake
index 1cf31c4a67..84bc7bb349 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})
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 6cdbbf2dc5..652e697edd 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();
@@ -129,90 +132,55 @@ bool cmFindLibraryCommand
//----------------------------------------------------------------------------
void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
{
- std::vector<std::string> newPaths;
- bool found = false;
- std::string subpath = "lib";
- subpath += suffix;
- subpath += "/";
- for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
- i != this->SearchPaths.end(); ++i)
+ std::vector<std::string> original;
+ original.swap(this->SearchPaths);
+ 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()))
- {
- found = true;
- newPaths.push_back(s);
- }
+ this->AddArchitecturePath(*i, 0, suffix);
+ }
+}
- // Now look for lib<suffix>
- s = *i;
- s += suffix;
- if(cmSystemTools::FileIsDirectory(s.c_str()))
+//----------------------------------------------------------------------------
+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()))
{
- found = true;
- newPaths.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 add the original unchanged path
- if(cmSystemTools::FileIsDirectory(i->c_str()))
+
+ // Follow "lib".
+ if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
{
- newPaths.push_back(*i);
+ this->AddArchitecturePath(dir, pos+3+1, suffix, false);
}
}
-
- // If any new paths were found replace the original set.
- if(found)
+ if(fresh)
{
- this->SearchPaths = newPaths;
- }
-}
-
-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()))
+ // Check for <dir><suffix>/.
+ std::string cur_dir = dir + suffix + "/";
+ if(cmSystemTools::FileIsDirectory(cur_dir.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()))
+ this->SearchPaths.push_back(cur_dir);
+ }
+
+ // Now add the original unchanged path
+ if(cmSystemTools::FileIsDirectory(dir.c_str()))
{
- path64.push_back(*i);
+ this->SearchPaths.push_back(dir);
}
}
- // now replace the SearchPaths with the 64 bit converted path
- // if any 64 bit paths were discovered
- if(found64)
- {
- this->SearchPaths = path64;
- }
}
//----------------------------------------------------------------------------
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
index b880be2664..31a5c3f8df 100644
--- a/Source/cmFindLibraryCommand.h
+++ b/Source/cmFindLibraryCommand.h
@@ -62,7 +62,10 @@ public:
protected:
void AddArchitecturePaths(const char* suffix);
- void AddLib64Paths();
+ 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/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..08f9331e11
--- /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
+ lib/libtest3.a
+ lib64/A/lib/libtest2.a
+ 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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/64/libtest2.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/A/libtest1.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest1.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest2.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib/libtest3.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/lib64/libtest1.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/A/libtest1.a
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
--- /dev/null
+++ b/Tests/CMakeOnly/find_library/lib64/libtest1.a