2001-01-11 22:55:47 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2001-01-11 22:55:47 +03:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2002-01-21 23:30:43 +03:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
|
|
|
=========================================================================*/
|
2001-01-18 19:20:24 +03:00
|
|
|
#include "cmFindLibraryCommand.h"
|
2001-02-19 23:13:48 +03:00
|
|
|
#include "cmCacheManager.h"
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
cmFindLibraryCommand::cmFindLibraryCommand()
|
|
|
|
{
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
2007-10-10 19:47:43 +04:00
|
|
|
"FIND_XXX", "find_library");
|
2006-03-02 21:30:22 +03:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"CMAKE_XXX_PATH", "CMAKE_LIBRARY_PATH");
|
2008-01-17 17:02:31 +03:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"CMAKE_XXX_MAC_PATH",
|
|
|
|
"CMAKE_FRAMEWORK_PATH");
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"CMAKE_SYSTEM_XXX_MAC_PATH",
|
|
|
|
"CMAKE_SYSTEM_FRAMEWORK_PATH");
|
2006-03-02 21:30:22 +03:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"XXX_SYSTEM", "LIB");
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
2006-05-10 23:46:45 +04:00
|
|
|
"CMAKE_SYSTEM_XXX_PATH",
|
|
|
|
"CMAKE_SYSTEM_LIBRARY_PATH");
|
2006-03-02 21:30:22 +03:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"SEARCH_XXX_DESC", "library");
|
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"SEARCH_XXX", "library");
|
2007-10-26 17:55:40 +04:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"XXX_SUBDIR", "lib");
|
2007-06-08 19:57:16 +04:00
|
|
|
cmSystemTools::ReplaceString(this->GenericDocumentation,
|
|
|
|
"CMAKE_FIND_ROOT_PATH_MODE_XXX",
|
|
|
|
"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY");
|
|
|
|
|
2007-12-15 04:46:15 +03:00
|
|
|
this->EnvironmentPath = "LIB";
|
2006-03-02 21:30:22 +03:00
|
|
|
this->GenericDocumentation +=
|
|
|
|
"\n"
|
2006-03-02 21:43:39 +03:00
|
|
|
"If the library found is a framework, then VAR will be set to "
|
2006-03-02 21:30:22 +03:00
|
|
|
"the full path to the framework <fullPath>/A.framework. "
|
|
|
|
"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. ";
|
|
|
|
}
|
|
|
|
|
2001-01-18 19:20:24 +03:00
|
|
|
// cmFindLibraryCommand
|
2008-01-23 18:28:26 +03:00
|
|
|
bool cmFindLibraryCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
this->VariableDocumentation = "Path to a library.";
|
|
|
|
this->CMakePathName = "LIBRARY";
|
|
|
|
if(!this->ParseArguments(argsIn))
|
2001-01-05 19:41:20 +03:00
|
|
|
{
|
|
|
|
return false;
|
2006-03-02 21:30:22 +03:00
|
|
|
}
|
|
|
|
if(this->AlreadyInCache)
|
2001-11-27 02:24:47 +03:00
|
|
|
{
|
2006-07-18 23:21:26 +04:00
|
|
|
// If the user specifies the entry on the command line without a
|
|
|
|
// type we should add the type and docstring but keep the original
|
|
|
|
// value.
|
|
|
|
if(this->AlreadyInCacheWithoutMetaInfo)
|
|
|
|
{
|
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(), "",
|
|
|
|
this->VariableDocumentation.c_str(),
|
|
|
|
cmCacheManager::FILEPATH);
|
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
return true;
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2007-06-27 20:07:34 +04:00
|
|
|
|
2008-01-23 17:53:33 +03:00
|
|
|
if(const char* abi_name =
|
2008-01-22 02:30:36 +03:00
|
|
|
this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI"))
|
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
std::string abi = abi_name;
|
|
|
|
if(abi.find("ELF N32") != abi.npos)
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
// Convert lib to lib32.
|
|
|
|
this->AddArchitecturePaths("32");
|
|
|
|
}
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
|
|
|
|
2007-06-27 20:07:34 +04:00
|
|
|
if(this->Makefile->GetCMakeInstance()
|
|
|
|
->GetPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
|
|
|
|
{
|
|
|
|
// add special 64 bit paths if this is a 64 bit compile.
|
|
|
|
this->AddLib64Paths();
|
|
|
|
}
|
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
std::string library;
|
|
|
|
for(std::vector<std::string>::iterator i = this->Names.begin();
|
|
|
|
i != this->Names.end() ; ++i)
|
|
|
|
{
|
|
|
|
library = this->FindLibrary(i->c_str());
|
|
|
|
if(library != "")
|
2008-01-24 00:21:49 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
|
|
|
|
library.c_str(),
|
|
|
|
this->VariableDocumentation.c_str(),
|
|
|
|
cmCacheManager::FILEPATH);
|
2006-03-02 21:30:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string notfound = this->VariableName + "-NOTFOUND";
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName.c_str(),
|
|
|
|
notfound.c_str(),
|
|
|
|
this->VariableDocumentation.c_str(),
|
|
|
|
cmCacheManager::FILEPATH);
|
2006-03-02 21:30:22 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-22 02:30:36 +03:00
|
|
|
//----------------------------------------------------------------------------
|
2008-01-23 17:53:33 +03:00
|
|
|
void cmFindLibraryCommand::AddArchitecturePaths(const char* suffix)
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
std::vector<std::string> newPaths;
|
|
|
|
bool found = false;
|
|
|
|
std::string subpath = "lib";
|
|
|
|
subpath += suffix;
|
|
|
|
subpath += "/";
|
2008-01-22 02:30:36 +03:00
|
|
|
for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
|
|
|
|
i != this->SearchPaths.end(); ++i)
|
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
// Try replacing lib/ with lib<suffix>/
|
2008-01-22 02:30:36 +03:00
|
|
|
std::string s = *i;
|
2008-01-23 17:53:33 +03:00
|
|
|
cmSystemTools::ReplaceString(s, "lib/", subpath.c_str());
|
2008-01-22 02:30:36 +03:00
|
|
|
if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str()))
|
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
found = true;
|
|
|
|
newPaths.push_back(s);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
2008-01-23 17:53:33 +03:00
|
|
|
|
|
|
|
// Now look for lib<suffix>
|
|
|
|
s = *i;
|
|
|
|
s += suffix;
|
|
|
|
if(cmSystemTools::FileIsDirectory(s.c_str()))
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
found = true;
|
|
|
|
newPaths.push_back(s);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
|
|
|
// now add the original unchanged path
|
|
|
|
if(cmSystemTools::FileIsDirectory(i->c_str()))
|
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
newPaths.push_back(*i);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
|
|
|
}
|
2008-01-23 17:53:33 +03:00
|
|
|
|
|
|
|
// If any new paths were found replace the original set.
|
|
|
|
if(found)
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2008-01-23 17:53:33 +03:00
|
|
|
this->SearchPaths = newPaths;
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
|
|
|
}
|
2001-05-11 20:13:14 +04:00
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
void cmFindLibraryCommand::AddLib64Paths()
|
|
|
|
{
|
2006-05-10 23:46:45 +04:00
|
|
|
if(!this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
|
|
|
|
GetLanguageEnabled("C"))
|
2006-03-02 21:30:22 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-02-12 01:00:45 +03:00
|
|
|
std::string voidsize =
|
|
|
|
this->Makefile->GetSafeDefinition("CMAKE_SIZEOF_VOID_P");
|
2006-03-02 21:30:22 +03:00
|
|
|
int size = atoi(voidsize.c_str());
|
|
|
|
if(size != 8)
|
2001-02-16 19:34:23 +03:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2007-08-21 00:59:06 +04:00
|
|
|
std::vector<std::string> path64;
|
2006-03-02 21:30:22 +03:00
|
|
|
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
|
|
|
|
if((s != *i) && cmSystemTools::FileIsDirectory(s.c_str()))
|
2001-04-26 17:38:31 +04:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
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()))
|
2001-04-26 17:38:31 +04:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
found64 = true;
|
|
|
|
path64.push_back(s2);
|
|
|
|
}
|
|
|
|
// now add the original unchanged path
|
|
|
|
if(cmSystemTools::FileIsDirectory(i->c_str()))
|
|
|
|
{
|
|
|
|
path64.push_back(*i);
|
2001-04-26 17:38:31 +04:00
|
|
|
}
|
2001-05-09 22:53:32 +04:00
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
// now replace the SearchPaths with the 64 bit converted path
|
|
|
|
// if any 64 bit paths were discovered
|
|
|
|
if(found64)
|
2001-05-09 22:53:32 +04:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
this->SearchPaths = path64;
|
2001-05-09 22:53:32 +04:00
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmFindLibraryCommand::FindLibrary(const char* name)
|
|
|
|
{
|
|
|
|
bool supportFrameworks = false;
|
|
|
|
bool onlyFrameworks = false;
|
2006-03-15 19:02:08 +03:00
|
|
|
std::string ff = this->Makefile->GetSafeDefinition("CMAKE_FIND_FRAMEWORK");
|
2006-03-02 21:30:22 +03:00
|
|
|
if(ff == "FIRST" || ff == "LAST")
|
2001-05-11 20:13:14 +04:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
supportFrameworks = true;
|
|
|
|
}
|
|
|
|
if(ff == "ONLY")
|
|
|
|
{
|
|
|
|
onlyFrameworks = true;
|
|
|
|
supportFrameworks = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* prefixes_list =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
|
2006-03-02 21:30:22 +03:00
|
|
|
const char* suffixes_list =
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
|
2006-03-02 21:30:22 +03:00
|
|
|
std::vector<std::string> prefixes;
|
|
|
|
std::vector<std::string> suffixes;
|
|
|
|
cmSystemTools::ExpandListArgument(prefixes_list, prefixes, true);
|
|
|
|
cmSystemTools::ExpandListArgument(suffixes_list, suffixes, true);
|
2008-02-10 19:37:06 +03:00
|
|
|
|
|
|
|
// If the original library name provided by the user matches one of
|
|
|
|
// the suffixes, try it first.
|
|
|
|
bool tryOrig = false;
|
|
|
|
{
|
|
|
|
std::string nm = name;
|
|
|
|
for(std::vector<std::string>::const_iterator si = suffixes.begin();
|
|
|
|
!tryOrig && si != suffixes.end(); ++si)
|
|
|
|
{
|
|
|
|
std::string const& suffix = *si;
|
|
|
|
if(nm.length() > suffix.length() &&
|
|
|
|
nm.substr(nm.size()-suffix.length()) == suffix)
|
|
|
|
{
|
|
|
|
tryOrig = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 01:41:14 +03:00
|
|
|
// Add a trailing slash to all paths to aid the search process.
|
|
|
|
for(std::vector<std::string>::iterator i = this->SearchPaths.begin();
|
|
|
|
i != this->SearchPaths.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string& p = *i;
|
2008-01-21 03:29:12 +03:00
|
|
|
if(p.empty() || p[p.size()-1] != '/')
|
2008-01-21 01:41:14 +03:00
|
|
|
{
|
|
|
|
p += "/";
|
|
|
|
}
|
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
std::string tryPath;
|
|
|
|
for(std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
|
|
|
|
p != this->SearchPaths.end(); ++p)
|
|
|
|
{
|
|
|
|
if(supportFrameworks)
|
2001-11-27 02:24:47 +03:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
tryPath = *p;
|
|
|
|
tryPath += name;
|
|
|
|
tryPath += ".framework";
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str())
|
|
|
|
&& cmSystemTools::FileIsDirectory(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(tryPath);
|
|
|
|
return tryPath;
|
|
|
|
}
|
2001-11-27 02:24:47 +03:00
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
if(!onlyFrameworks)
|
2001-05-11 20:13:14 +04:00
|
|
|
{
|
2008-02-06 23:26:22 +03:00
|
|
|
// Try the original library name as specified by the user.
|
2008-02-10 19:37:06 +03:00
|
|
|
if(tryOrig)
|
2008-02-06 23:26:22 +03:00
|
|
|
{
|
2008-02-10 19:37:06 +03:00
|
|
|
tryPath = *p;
|
|
|
|
tryPath += name;
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str(), true))
|
|
|
|
{
|
|
|
|
tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(tryPath);
|
|
|
|
return tryPath;
|
|
|
|
}
|
2008-02-06 23:26:22 +03:00
|
|
|
}
|
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
// Try various library naming conventions.
|
|
|
|
for(std::vector<std::string>::iterator prefix = prefixes.begin();
|
|
|
|
prefix != prefixes.end(); ++prefix)
|
2001-11-27 02:24:47 +03:00
|
|
|
{
|
2006-03-02 21:30:22 +03:00
|
|
|
for(std::vector<std::string>::iterator suffix = suffixes.begin();
|
|
|
|
suffix != suffixes.end(); ++suffix)
|
|
|
|
{
|
|
|
|
tryPath = *p;
|
|
|
|
tryPath += *prefix;
|
|
|
|
tryPath += name;
|
|
|
|
tryPath += *suffix;
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str())
|
|
|
|
&& !cmSystemTools::FileIsDirectory(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
tryPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(tryPath);
|
|
|
|
return tryPath;
|
|
|
|
}
|
|
|
|
}
|
2001-11-27 02:24:47 +03:00
|
|
|
}
|
2001-05-11 20:13:14 +04:00
|
|
|
}
|
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
// Couldn't find the library.
|
|
|
|
return "";
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|