2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-01-18 19:20:24 +03:00
|
|
|
#include "cmFindLibraryCommand.h"
|
2008-09-22 18:59:52 +04:00
|
|
|
#include <cmsys/Directory.hxx>
|
2001-01-05 19:41:20 +03:00
|
|
|
|
2006-03-02 21:30:22 +03:00
|
|
|
cmFindLibraryCommand::cmFindLibraryCommand()
|
2012-08-13 21:42:58 +04:00
|
|
|
{
|
2010-11-12 18:47:28 +03:00
|
|
|
this->EnvironmentPath = "LIB";
|
2012-09-24 19:05:10 +04:00
|
|
|
this->NamesPerDirAllowed = true;
|
2010-11-12 18:47:28 +03:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName, "",
|
2006-07-18 23:21:26 +04:00
|
|
|
this->VariableDocumentation.c_str(),
|
2015-04-07 23:45:54 +03:00
|
|
|
cmState::FILEPATH);
|
2006-07-18 23:21:26 +04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-04-11 15:15:55 +03:00
|
|
|
if(this->Makefile->GetState()
|
|
|
|
->GetGlobalPropertyAsBool("FIND_LIBRARY_USE_LIB64_PATHS"))
|
2007-06-27 20:07:34 +04:00
|
|
|
{
|
|
|
|
// add special 64 bit paths if this is a 64 bit compile.
|
2012-07-20 21:28:49 +04:00
|
|
|
if(this->Makefile->PlatformIs64Bit())
|
|
|
|
{
|
|
|
|
this->AddArchitecturePaths("64");
|
|
|
|
}
|
2007-06-27 20:07:34 +04:00
|
|
|
}
|
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
std::string library = this->FindLibrary();
|
|
|
|
if(library != "")
|
2006-03-02 21:30:22 +03:00
|
|
|
{
|
2008-06-09 19:58:29 +04:00
|
|
|
// Save the value in the cache
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName,
|
2008-06-09 19:58:29 +04:00
|
|
|
library.c_str(),
|
|
|
|
this->VariableDocumentation.c_str(),
|
2015-04-07 23:45:54 +03:00
|
|
|
cmState::FILEPATH);
|
2008-06-09 19:58:29 +04:00
|
|
|
return true;
|
2006-03-02 21:30:22 +03:00
|
|
|
}
|
|
|
|
std::string notfound = this->VariableName + "-NOTFOUND";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName,
|
2006-03-15 19:02:08 +03:00
|
|
|
notfound.c_str(),
|
|
|
|
this->VariableDocumentation.c_str(),
|
2015-04-07 23:45:54 +03:00
|
|
|
cmState::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
|
|
|
{
|
2012-07-20 21:30:30 +04:00
|
|
|
std::vector<std::string> original;
|
|
|
|
original.swap(this->SearchPaths);
|
2014-10-09 21:52:54 +04:00
|
|
|
for(std::vector<std::string>::const_iterator i = original.begin();
|
2012-07-20 21:30:30 +04:00
|
|
|
i != original.end(); ++i)
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2012-07-20 22:09:57 +04:00
|
|
|
this->AddArchitecturePath(*i, 0, suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
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;
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(next_dir))
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2012-07-20 22:09:57 +04:00
|
|
|
next_dir += dir.substr(pos+3);
|
|
|
|
std::string::size_type next_pos = pos+3+strlen(suffix)+1;
|
|
|
|
this->AddArchitecturePath(next_dir, next_pos, suffix);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
2008-01-23 17:53:33 +03:00
|
|
|
|
2012-07-20 22:09:57 +04:00
|
|
|
// Follow "lib".
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(cur_dir))
|
2012-07-20 22:09:57 +04:00
|
|
|
{
|
|
|
|
this->AddArchitecturePath(dir, pos+3+1, suffix, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(fresh)
|
|
|
|
{
|
|
|
|
// Check for <dir><suffix>/.
|
|
|
|
std::string cur_dir = dir + suffix + "/";
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(cur_dir))
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2012-07-20 22:09:57 +04:00
|
|
|
this->SearchPaths.push_back(cur_dir);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
2012-07-20 22:09:57 +04:00
|
|
|
|
2012-07-20 21:30:30 +04:00
|
|
|
// Now add the original unchanged path
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(dir))
|
2008-01-22 02:30:36 +03:00
|
|
|
{
|
2012-07-20 22:09:57 +04:00
|
|
|
this->SearchPaths.push_back(dir);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-11 20:13:14 +04:00
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindLibrary()
|
2006-03-02 21:30:22 +03:00
|
|
|
{
|
2008-06-09 19:58:29 +04:00
|
|
|
std::string library;
|
|
|
|
if(this->SearchFrameworkFirst || this->SearchFrameworkOnly)
|
2001-05-11 20:13:14 +04:00
|
|
|
{
|
2008-06-09 19:58:29 +04:00
|
|
|
library = this->FindFrameworkLibrary();
|
2006-03-02 21:30:22 +03:00
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
if(library.empty() && !this->SearchFrameworkOnly)
|
2006-03-02 21:30:22 +03:00
|
|
|
{
|
2008-06-09 19:58:29 +04:00
|
|
|
library = this->FindNormalLibrary();
|
2006-03-02 21:30:22 +03:00
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
if(library.empty() && this->SearchFrameworkLast)
|
|
|
|
{
|
|
|
|
library = this->FindFrameworkLibrary();
|
|
|
|
}
|
|
|
|
return library;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2008-09-22 18:59:52 +04:00
|
|
|
struct cmFindLibraryHelper
|
|
|
|
{
|
|
|
|
cmFindLibraryHelper(cmMakefile* mf);
|
|
|
|
|
|
|
|
// Context information.
|
|
|
|
cmMakefile* Makefile;
|
|
|
|
cmGlobalGenerator* GG;
|
|
|
|
|
|
|
|
// List of valid prefixes and suffixes.
|
|
|
|
std::vector<std::string> Prefixes;
|
|
|
|
std::vector<std::string> Suffixes;
|
|
|
|
std::string PrefixRegexStr;
|
|
|
|
std::string SuffixRegexStr;
|
|
|
|
|
|
|
|
// Keep track of the best library file found so far.
|
|
|
|
typedef std::vector<std::string>::size_type size_type;
|
|
|
|
std::string BestPath;
|
|
|
|
|
2008-09-22 19:08:17 +04:00
|
|
|
// Support for OpenBSD shared library naming: lib<name>.so.<major>.<minor>
|
|
|
|
bool OpenBSD;
|
|
|
|
|
2012-09-21 00:32:26 +04:00
|
|
|
// Current names under consideration.
|
|
|
|
struct Name
|
|
|
|
{
|
|
|
|
bool TryRaw;
|
|
|
|
std::string Raw;
|
|
|
|
cmsys::RegularExpression Regex;
|
|
|
|
Name(): TryRaw(false) {}
|
|
|
|
};
|
|
|
|
std::vector<Name> Names;
|
2008-09-22 18:59:52 +04:00
|
|
|
|
|
|
|
// Current full path under consideration.
|
|
|
|
std::string TestPath;
|
|
|
|
|
|
|
|
void RegexFromLiteral(std::string& out, std::string const& in);
|
|
|
|
void RegexFromList(std::string& out, std::vector<std::string> const& in);
|
|
|
|
size_type GetPrefixIndex(std::string const& prefix)
|
|
|
|
{
|
2015-01-30 01:19:40 +03:00
|
|
|
return std::find(this->Prefixes.begin(), this->Prefixes.end(),
|
2008-09-22 18:59:52 +04:00
|
|
|
prefix) - this->Prefixes.begin();
|
|
|
|
}
|
|
|
|
size_type GetSuffixIndex(std::string const& suffix)
|
|
|
|
{
|
2015-01-30 01:19:40 +03:00
|
|
|
return std::find(this->Suffixes.begin(), this->Suffixes.end(),
|
2008-09-22 18:59:52 +04:00
|
|
|
suffix) - this->Suffixes.begin();
|
|
|
|
}
|
|
|
|
bool HasValidSuffix(std::string const& name);
|
2012-09-21 00:32:26 +04:00
|
|
|
void AddName(std::string const& name);
|
2008-09-22 18:59:52 +04:00
|
|
|
bool CheckDirectory(std::string const& path);
|
2012-09-21 00:32:26 +04:00
|
|
|
bool CheckDirectoryForName(std::string const& path, Name& name);
|
2008-09-22 18:59:52 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf):
|
|
|
|
Makefile(mf)
|
2008-06-09 19:58:29 +04:00
|
|
|
{
|
2015-05-03 12:10:30 +03:00
|
|
|
this->GG = this->Makefile->GetGlobalGenerator();
|
2008-09-22 18:59:52 +04:00
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
// Collect the list of library name prefixes/suffixes to try.
|
2006-03-02 21:30:22 +03:00
|
|
|
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");
|
2008-09-22 18:59:52 +04:00
|
|
|
cmSystemTools::ExpandListArgument(prefixes_list, this->Prefixes, true);
|
|
|
|
cmSystemTools::ExpandListArgument(suffixes_list, this->Suffixes, true);
|
|
|
|
this->RegexFromList(this->PrefixRegexStr, this->Prefixes);
|
|
|
|
this->RegexFromList(this->SuffixRegexStr, this->Suffixes);
|
2008-02-10 19:37:06 +03:00
|
|
|
|
2008-09-22 19:08:17 +04:00
|
|
|
// Check whether to use OpenBSD-style library version comparisons.
|
|
|
|
this->OpenBSD =
|
2015-04-11 15:15:55 +03:00
|
|
|
this->Makefile->GetState()
|
|
|
|
->GetGlobalPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING");
|
2008-09-22 18:59:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindLibraryHelper::RegexFromLiteral(std::string& out,
|
|
|
|
std::string const& in)
|
|
|
|
{
|
|
|
|
for(std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci)
|
2006-03-02 21:30:22 +03:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
char ch = *ci;
|
|
|
|
if(ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' ||
|
|
|
|
ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' ||
|
|
|
|
ch == '^' || ch == '$')
|
2001-11-27 02:24:47 +03:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
out += "\\";
|
2001-11-27 02:24:47 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__)
|
|
|
|
out += tolower(ch);
|
|
|
|
#else
|
|
|
|
out += ch;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
|
2008-09-22 18:59:52 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmFindLibraryHelper::RegexFromList(std::string& out,
|
|
|
|
std::vector<std::string> const& in)
|
|
|
|
{
|
|
|
|
// Surround the list in parens so the '|' does not apply to anything
|
|
|
|
// else and the result can be checked after matching.
|
|
|
|
out += "(";
|
|
|
|
const char* sep = "";
|
|
|
|
for(std::vector<std::string>::const_iterator si = in.begin();
|
|
|
|
si != in.end(); ++si)
|
|
|
|
{
|
|
|
|
// Separate from previous item.
|
|
|
|
out += sep;
|
|
|
|
sep = "|";
|
|
|
|
|
|
|
|
// Append this item.
|
|
|
|
this->RegexFromLiteral(out, *si);
|
|
|
|
}
|
|
|
|
out += ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindLibraryHelper::HasValidSuffix(std::string const& name)
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator si = this->Suffixes.begin();
|
|
|
|
si != this->Suffixes.end(); ++si)
|
|
|
|
{
|
2012-02-15 22:55:57 +04:00
|
|
|
std::string suffix = *si;
|
|
|
|
if(name.length() <= suffix.length())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Check if the given name ends in a valid library suffix.
|
|
|
|
if(name.substr(name.size()-suffix.length()) == suffix)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Check if a valid library suffix is somewhere in the name,
|
|
|
|
// this may happen e.g. for versioned shared libraries: libfoo.so.2
|
|
|
|
suffix += ".";
|
|
|
|
if(name.find(suffix) != name.npos)
|
2008-09-22 18:59:52 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-09-21 00:32:26 +04:00
|
|
|
void cmFindLibraryHelper::AddName(std::string const& name)
|
2008-09-22 18:59:52 +04:00
|
|
|
{
|
2012-09-21 00:32:26 +04:00
|
|
|
Name entry;
|
|
|
|
|
2008-09-22 18:59:52 +04:00
|
|
|
// Consider checking the raw name too.
|
2012-09-21 00:32:26 +04:00
|
|
|
entry.TryRaw = this->HasValidSuffix(name);
|
|
|
|
entry.Raw = name;
|
2008-09-22 18:59:52 +04:00
|
|
|
|
|
|
|
// Build a regular expression to match library names.
|
|
|
|
std::string regex = "^";
|
|
|
|
regex += this->PrefixRegexStr;
|
|
|
|
this->RegexFromLiteral(regex, name);
|
|
|
|
regex += this->SuffixRegexStr;
|
2008-09-22 19:08:17 +04:00
|
|
|
if(this->OpenBSD)
|
|
|
|
{
|
|
|
|
regex += "(\\.[0-9]+\\.[0-9]+)?";
|
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
regex += "$";
|
2012-09-21 00:32:26 +04:00
|
|
|
entry.Regex.compile(regex.c_str());
|
|
|
|
this->Names.push_back(entry);
|
2008-09-22 18:59:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindLibraryHelper::CheckDirectory(std::string const& path)
|
2012-09-21 00:32:26 +04:00
|
|
|
{
|
|
|
|
for(std::vector<Name>::iterator i = this->Names.begin();
|
|
|
|
i != this->Names.end(); ++i)
|
|
|
|
{
|
|
|
|
if(this->CheckDirectoryForName(path, *i))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmFindLibraryHelper::CheckDirectoryForName(std::string const& path,
|
|
|
|
Name& name)
|
2008-09-22 18:59:52 +04:00
|
|
|
{
|
|
|
|
// If the original library name provided by the user matches one of
|
|
|
|
// the suffixes, try it first. This allows users to search
|
|
|
|
// specifically for a static library on some platforms (on MS tools
|
|
|
|
// one cannot tell just from the library name whether it is a static
|
|
|
|
// library or an import library).
|
2012-09-21 00:32:26 +04:00
|
|
|
if(name.TryRaw)
|
2008-09-22 18:59:52 +04:00
|
|
|
{
|
|
|
|
this->TestPath = path;
|
2012-09-21 00:32:26 +04:00
|
|
|
this->TestPath += name.Raw;
|
2008-09-22 18:59:52 +04:00
|
|
|
if(cmSystemTools::FileExists(this->TestPath.c_str(), true))
|
|
|
|
{
|
|
|
|
this->BestPath =
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::CollapseFullPath(this->TestPath);
|
2008-09-22 18:59:52 +04:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->BestPath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-21 00:32:26 +04:00
|
|
|
// No library file has yet been found.
|
|
|
|
size_type bestPrefix = this->Prefixes.size();
|
|
|
|
size_type bestSuffix = this->Suffixes.size();
|
|
|
|
unsigned int bestMajor = 0;
|
|
|
|
unsigned int bestMinor = 0;
|
|
|
|
|
2008-09-22 18:59:52 +04:00
|
|
|
// Search for a file matching the library name regex.
|
|
|
|
std::string dir = path;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(dir);
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> const& files = this->GG->GetDirectoryContent(dir);
|
|
|
|
for(std::set<std::string>::const_iterator fi = files.begin();
|
2008-09-22 18:59:52 +04:00
|
|
|
fi != files.end(); ++fi)
|
|
|
|
{
|
|
|
|
std::string const& origName = *fi;
|
|
|
|
#if defined(_WIN32) || defined(__APPLE__)
|
|
|
|
std::string testName = cmSystemTools::LowerCase(origName);
|
|
|
|
#else
|
|
|
|
std::string const& testName = origName;
|
|
|
|
#endif
|
2012-09-21 00:32:26 +04:00
|
|
|
if(name.Regex.find(testName))
|
2001-05-11 20:13:14 +04:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
this->TestPath = path;
|
|
|
|
this->TestPath += origName;
|
2014-10-15 16:54:05 +04:00
|
|
|
if(!cmSystemTools::FileIsDirectory(this->TestPath))
|
2008-02-06 23:26:22 +03:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
// This is a matching file. Check if it is better than the
|
|
|
|
// best name found so far. Earlier prefixes are preferred,
|
2008-09-22 19:08:17 +04:00
|
|
|
// followed by earlier suffixes. For OpenBSD, shared library
|
|
|
|
// version extensions are compared.
|
2012-09-21 00:32:26 +04:00
|
|
|
size_type prefix = this->GetPrefixIndex(name.Regex.match(1));
|
|
|
|
size_type suffix = this->GetSuffixIndex(name.Regex.match(2));
|
2008-09-22 19:08:17 +04:00
|
|
|
unsigned int major = 0;
|
|
|
|
unsigned int minor = 0;
|
|
|
|
if(this->OpenBSD)
|
|
|
|
{
|
2012-09-21 00:32:26 +04:00
|
|
|
sscanf(name.Regex.match(3).c_str(), ".%u.%u", &major, &minor);
|
2008-09-22 19:08:17 +04:00
|
|
|
}
|
2012-09-21 00:32:26 +04:00
|
|
|
if(this->BestPath.empty() || prefix < bestPrefix ||
|
|
|
|
(prefix == bestPrefix && suffix < bestSuffix) ||
|
|
|
|
(prefix == bestPrefix && suffix == bestSuffix &&
|
|
|
|
(major > bestMajor ||
|
|
|
|
(major == bestMajor && minor > bestMinor))))
|
2008-02-10 19:37:06 +03:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
this->BestPath = this->TestPath;
|
2012-09-21 00:32:26 +04:00
|
|
|
bestPrefix = prefix;
|
|
|
|
bestSuffix = suffix;
|
|
|
|
bestMajor = major;
|
|
|
|
bestMinor = minor;
|
2008-02-10 19:37:06 +03:00
|
|
|
}
|
2008-02-06 23:26:22 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
}
|
|
|
|
}
|
2008-02-06 23:26:22 +03:00
|
|
|
|
2008-09-22 18:59:52 +04:00
|
|
|
// Use the best candidate found in this directory, if any.
|
|
|
|
return !this->BestPath.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindNormalLibrary()
|
2012-09-24 19:05:10 +04:00
|
|
|
{
|
|
|
|
if(this->NamesPerDir)
|
|
|
|
{
|
|
|
|
return this->FindNormalLibraryNamesPerDir();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->FindNormalLibraryDirsPerName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir()
|
|
|
|
{
|
|
|
|
// Search for all names in each directory.
|
|
|
|
cmFindLibraryHelper helper(this->Makefile);
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end() ; ++ni)
|
|
|
|
{
|
|
|
|
helper.AddName(*ni);
|
|
|
|
}
|
|
|
|
// Search every directory.
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
p = this->SearchPaths.begin(); p != this->SearchPaths.end(); ++p)
|
|
|
|
{
|
|
|
|
if(helper.CheckDirectory(*p))
|
|
|
|
{
|
|
|
|
return helper.BestPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Couldn't find the library.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindNormalLibraryDirsPerName()
|
2008-09-22 18:59:52 +04:00
|
|
|
{
|
|
|
|
// Search the entire path for each name.
|
|
|
|
cmFindLibraryHelper helper(this->Makefile);
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end() ; ++ni)
|
|
|
|
{
|
|
|
|
// Switch to searching for this name.
|
|
|
|
std::string const& name = *ni;
|
2012-09-21 00:32:26 +04:00
|
|
|
helper.AddName(name);
|
2008-09-22 18:59:52 +04:00
|
|
|
|
|
|
|
// Search every directory.
|
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
p = this->SearchPaths.begin();
|
|
|
|
p != this->SearchPaths.end(); ++p)
|
|
|
|
{
|
|
|
|
if(helper.CheckDirectory(*p))
|
2001-11-27 02:24:47 +03:00
|
|
|
{
|
2008-09-22 18:59:52 +04:00
|
|
|
return helper.BestPath;
|
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
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindFrameworkLibrary()
|
2012-09-24 19:05:10 +04:00
|
|
|
{
|
|
|
|
if(this->NamesPerDir)
|
|
|
|
{
|
|
|
|
return this->FindFrameworkLibraryNamesPerDir();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->FindFrameworkLibraryDirsPerName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir()
|
|
|
|
{
|
|
|
|
std::string fwPath;
|
|
|
|
// Search for all names in each search path.
|
|
|
|
for(std::vector<std::string>::const_iterator di = this->SearchPaths.begin();
|
|
|
|
di != this->SearchPaths.end(); ++di)
|
|
|
|
{
|
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end() ; ++ni)
|
|
|
|
{
|
|
|
|
fwPath = *di;
|
|
|
|
fwPath += *ni;
|
|
|
|
fwPath += ".framework";
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(fwPath))
|
2012-09-24 19:05:10 +04:00
|
|
|
{
|
2014-10-15 16:54:05 +04:00
|
|
|
return cmSystemTools::CollapseFullPath(fwPath);
|
2012-09-24 19:05:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No framework found.
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::string cmFindLibraryCommand::FindFrameworkLibraryDirsPerName()
|
2008-06-09 19:58:29 +04:00
|
|
|
{
|
2012-09-24 18:17:45 +04:00
|
|
|
std::string fwPath;
|
|
|
|
// Search for each name in all search paths.
|
2008-06-09 19:58:29 +04:00
|
|
|
for(std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end() ; ++ni)
|
|
|
|
{
|
2012-09-24 18:17:45 +04:00
|
|
|
for(std::vector<std::string>::const_iterator
|
|
|
|
di = this->SearchPaths.begin();
|
|
|
|
di != this->SearchPaths.end(); ++di)
|
2008-06-09 19:58:29 +04:00
|
|
|
{
|
2012-09-24 18:17:45 +04:00
|
|
|
fwPath = *di;
|
|
|
|
fwPath += *ni;
|
|
|
|
fwPath += ".framework";
|
2014-10-15 16:54:05 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(fwPath))
|
2012-09-24 18:17:45 +04:00
|
|
|
{
|
2014-10-15 16:54:05 +04:00
|
|
|
return cmSystemTools::CollapseFullPath(fwPath);
|
2012-09-24 18:17:45 +04:00
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No framework found.
|
|
|
|
return "";
|
|
|
|
}
|