[cmake-commits] king committed cmFindLibraryCommand.cxx 1.51 1.52
cmFindLibraryCommand.h 1.25 1.26
cmake-commits at cmake.org
cmake-commits at cmake.org
Wed Jan 23 16:21:51 EST 2008
Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv19069/Source
Modified Files:
cmFindLibraryCommand.cxx cmFindLibraryCommand.h
Log Message:
ENH: Teach find_library to avoid returning library paths in system directories that may be converted to architecture-specific directories by the compiler when it invokes the linker.
Index: cmFindLibraryCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindLibraryCommand.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- cmFindLibraryCommand.h 23 Jan 2008 15:27:59 -0000 1.25
+++ cmFindLibraryCommand.h 23 Jan 2008 21:21:49 -0000 1.26
@@ -69,6 +69,7 @@
void AddArchitecturePaths(const char* suffix);
void AddLib64Paths();
std::string FindLibrary(const char* name);
+ std::string FixForImplicitLocations(std::string const& lib);
};
Index: cmFindLibraryCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFindLibraryCommand.cxx,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- cmFindLibraryCommand.cxx 23 Jan 2008 15:27:59 -0000 1.51
+++ cmFindLibraryCommand.cxx 23 Jan 2008 21:21:49 -0000 1.52
@@ -52,6 +52,17 @@
"When a full path to a framework is used as a library, "
"CMake will use a -framework A, and a -F<fullPath> to "
"link the framework to the target. ";
+ this->GenericDocumentation +=
+ "\n"
+ "Some platforms define implicit library directories such as "
+ "/lib and /usr/lib that are automatically searched by the linker. "
+ "If this command finds a library in one of these directories "
+ "it will report only the name of the library file and not the path. "
+ "When the name is used to link the library CMake will generate a "
+ "link line that asks the linker to search for it. This allows "
+ "the system linker to automatically adjust the implicit directory "
+ "set based on the current architecture."
+ ;
}
// cmFindLibraryCommand
@@ -107,7 +118,8 @@
{
library = this->FindLibrary(i->c_str());
if(library != "")
- {
+ {
+ library = this->FixForImplicitLocations(library);
this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
library.c_str(),
this->VariableDocumentation.c_str(),
@@ -293,3 +305,43 @@
// Couldn't find the library.
return "";
}
+
+//----------------------------------------------------------------------------
+std::string
+cmFindLibraryCommand::FixForImplicitLocations(std::string const& lib)
+{
+ // Get implicit link directories for the platform.
+ const char* implicitLinks =
+ (this->Makefile->GetDefinition
+ ("CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES"));
+ if(!implicitLinks)
+ {
+ // There are no implicit link directories. No fix is needed.
+ return lib;
+ }
+ std::vector<std::string> implicitLinkVec;
+ cmSystemTools::ExpandListArgument(implicitLinks, implicitLinkVec);
+
+ // Get the path containing the library.
+ std::string libDir = cmSystemTools::GetFilenamePath(lib);
+
+ // Many system linkers support multiple architectures by
+ // automatically selecting the implicit linker search path for the
+ // current architecture. If the library appears in an implicit link
+ // directory then just report the file name without the directory
+ // portion. This will allow the system linker to locate the proper
+ // library for the architecture at link time.
+ for(std::vector<std::string>::const_iterator i = implicitLinkVec.begin();
+ i != implicitLinkVec.end(); ++i)
+ {
+ if(*i == libDir)
+ {
+ // The library appears in an implicit link directory. Report
+ // only the file name.
+ return cmSystemTools::GetFilenameName(lib);
+ }
+ }
+
+ // No implicit link directory matched. No fix is needed.
+ return lib;
+}
More information about the Cmake-commits
mailing list