mirror of
https://github.com/reactos/CMake.git
synced 2024-11-27 21:41:03 +00:00
Merge topic 'mixed-lib-to-lib64'
af80da3
remove lib64 Unix paths if the respective lib path is also given733726e
find_library: Fix mixed lib->lib64 (non-)conversion cases (#13419)54add62
find_library: Simplify lib->lib<arch> expansion6ca2f82
find_library: Refactor lib->lib64 conversion1fe4b82
find_library: Add test covering lib->lib64 cases
This commit is contained in:
commit
85f843a7b4
@ -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,89 +132,54 @@ 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);
|
||||
}
|
||||
|
||||
// Now look for lib<suffix>
|
||||
s = *i;
|
||||
s += suffix;
|
||||
if(cmSystemTools::FileIsDirectory(s.c_str()))
|
||||
{
|
||||
found = true;
|
||||
newPaths.push_back(s);
|
||||
}
|
||||
// now add the original unchanged path
|
||||
if(cmSystemTools::FileIsDirectory(i->c_str()))
|
||||
{
|
||||
newPaths.push_back(*i);
|
||||
this->AddArchitecturePath(*i, 0, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
// If any new paths were found replace the original set.
|
||||
if(found)
|
||||
//----------------------------------------------------------------------------
|
||||
void cmFindLibraryCommand::AddArchitecturePath(
|
||||
std::string const& dir, std::string::size_type start_pos,
|
||||
const char* suffix, bool fresh)
|
||||
{
|
||||
this->SearchPaths = newPaths;
|
||||
}
|
||||
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()))
|
||||
{
|
||||
next_dir += dir.substr(pos+3);
|
||||
std::string::size_type next_pos = pos+3+strlen(suffix)+1;
|
||||
this->AddArchitecturePath(next_dir, next_pos, suffix);
|
||||
}
|
||||
|
||||
void cmFindLibraryCommand::AddLib64Paths()
|
||||
// Follow "lib".
|
||||
if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
|
||||
{
|
||||
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()))
|
||||
{
|
||||
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);
|
||||
this->AddArchitecturePath(dir, pos+3+1, suffix, false);
|
||||
}
|
||||
}
|
||||
// now replace the SearchPaths with the 64 bit converted path
|
||||
// if any 64 bit paths were discovered
|
||||
if(found64)
|
||||
if(fresh)
|
||||
{
|
||||
this->SearchPaths = path64;
|
||||
// Check for <dir><suffix>/.
|
||||
std::string cur_dir = dir + suffix + "/";
|
||||
if(cmSystemTools::FileIsDirectory(cur_dir.c_str()))
|
||||
{
|
||||
this->SearchPaths.push_back(cur_dir);
|
||||
}
|
||||
|
||||
// Now add the original unchanged path
|
||||
if(cmSystemTools::FileIsDirectory(dir.c_str()))
|
||||
{
|
||||
this->SearchPaths.push_back(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
61
Tests/CMakeOnly/find_library/CMakeLists.txt
Normal file
61
Tests/CMakeOnly/find_library/CMakeLists.txt
Normal file
@ -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()
|
0
Tests/CMakeOnly/find_library/lib/64/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib/64/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/lib/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/lib64/libtest3.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/A/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest3.a
Normal file
0
Tests/CMakeOnly/find_library/lib/libtest3.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/A/lib/libtest2.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/A/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/A/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/libtest1.a
Normal file
0
Tests/CMakeOnly/find_library/lib64/libtest1.a
Normal file
Loading…
Reference in New Issue
Block a user