Commit 85f843a7 authored by David Cole's avatar David Cole Committed by Kitware Robot

Merge topic 'mixed-lib-to-lib64'

af80da34 remove lib64 Unix paths if the respective lib path is also given
733726ed find_library: Fix mixed lib->lib64 (non-)conversion cases (#13419)
54add62f find_library: Simplify lib->lib<arch> expansion
6ca2f82d find_library: Refactor lib->lib64 conversion
1fe4b82a find_library: Add test covering lib->lib64 cases
parents e93d9c5c af80da34
......@@ -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 ()
......
......@@ -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
......
......@@ -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})
......
......@@ -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;
}
}
//----------------------------------------------------------------------------
......
......@@ -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:
......
......@@ -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
......
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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment