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"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
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
|
2016-05-16 17:34:04 +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";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ParseArguments(argsIn)) {
|
2001-01-05 19:41:20 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->AlreadyInCache) {
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
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);
|
2001-01-05 19:41:20 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return true;
|
|
|
|
}
|
2007-06-27 20:07:34 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* abi_name =
|
|
|
|
this->Makefile->GetDefinition("CMAKE_INTERNAL_PLATFORM_ABI")) {
|
2008-01-23 17:53:33 +03:00
|
|
|
std::string abi = abi_name;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (abi.find("ELF N32") != abi.npos) {
|
2008-01-23 17:53:33 +03:00
|
|
|
// Convert lib to lib32.
|
|
|
|
this->AddArchitecturePaths("32");
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-22 02:30:36 +03:00
|
|
|
|
2016-05-16 17:34:04 +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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->PlatformIs64Bit()) {
|
2012-07-20 21:28:49 +04:00
|
|
|
this->AddArchitecturePaths("64");
|
2007-06-27 20:07:34 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-27 20:07:34 +04:00
|
|
|
|
2008-06-09 19:58:29 +04:00
|
|
|
std::string library = this->FindLibrary();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (library != "") {
|
2008-06-09 19:58:29 +04:00
|
|
|
// Save the value in the cache
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName, library.c_str(),
|
2008-06-09 19:58:29 +04:00
|
|
|
this->VariableDocumentation.c_str(),
|
2015-04-07 23:45:54 +03:00
|
|
|
cmState::FILEPATH);
|
2008-06-09 19:58:29 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-02 21:30:22 +03:00
|
|
|
std::string notfound = this->VariableName + "-NOTFOUND";
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddCacheDefinition(this->VariableName, notfound.c_str(),
|
2006-03-15 19:02:08 +03:00
|
|
|
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-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);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator i = original.begin();
|
|
|
|
i != original.end(); ++i) {
|
2012-07-20 22:09:57 +04:00
|
|
|
this->AddArchitecturePath(*i, 0, suffix);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-20 22:09:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmFindLibraryCommand::AddArchitecturePath(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& dir, std::string::size_type start_pos, const char* suffix,
|
|
|
|
bool fresh)
|
2012-07-20 22:09:57 +04:00
|
|
|
{
|
|
|
|
std::string::size_type pos = dir.find("lib/", start_pos);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (pos != std::string::npos) {
|
|
|
|
std::string cur_dir = dir.substr(0, pos + 3);
|
2012-07-20 22:09:57 +04:00
|
|
|
|
|
|
|
// Follow "lib<suffix>".
|
|
|
|
std::string next_dir = cur_dir + suffix;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(next_dir)) {
|
|
|
|
next_dir += dir.substr(pos + 3);
|
|
|
|
std::string::size_type next_pos = pos + 3 + strlen(suffix) + 1;
|
2012-07-20 22:09:57 +04:00
|
|
|
this->AddArchitecturePath(next_dir, next_pos, suffix);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-01-23 17:53:33 +03:00
|
|
|
|
2012-07-20 22:09:57 +04:00
|
|
|
// Follow "lib".
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(cur_dir)) {
|
|
|
|
this->AddArchitecturePath(dir, pos + 3 + 1, suffix, false);
|
2012-07-20 22:09:57 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (fresh) {
|
2012-07-20 22:09:57 +04:00
|
|
|
// Check for <dir><suffix>/.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cur_dir = dir + suffix + "/";
|
|
|
|
if (cmSystemTools::FileIsDirectory(cur_dir)) {
|
2012-07-20 22:09:57 +04:00
|
|
|
this->SearchPaths.push_back(cur_dir);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-07-20 22:09:57 +04:00
|
|
|
|
2012-07-20 21:30:30 +04:00
|
|
|
// Now add the original unchanged path
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(dir)) {
|
2012-07-20 22:09:57 +04:00
|
|
|
this->SearchPaths.push_back(dir);
|
2008-01-22 02:30:36 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->SearchFrameworkFirst || this->SearchFrameworkOnly) {
|
2008-06-09 19:58:29 +04:00
|
|
|
library = this->FindFrameworkLibrary();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (library.empty() && !this->SearchFrameworkOnly) {
|
2008-06-09 19:58:29 +04:00
|
|
|
library = this->FindNormalLibrary();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (library.empty() && this->SearchFrameworkLast) {
|
2008-06-09 19:58:29 +04:00
|
|
|
library = this->FindFrameworkLibrary();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
Name()
|
|
|
|
: TryRaw(false)
|
|
|
|
{
|
|
|
|
}
|
2012-09-21 00:32:26 +04:00
|
|
|
};
|
|
|
|
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)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
return std::find(this->Prefixes.begin(), this->Prefixes.end(), prefix) -
|
|
|
|
this->Prefixes.begin();
|
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
size_type GetSuffixIndex(std::string const& suffix)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
return std::find(this->Suffixes.begin(), this->Suffixes.end(), suffix) -
|
|
|
|
this->Suffixes.begin();
|
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
bool HasValidSuffix(std::string const& name);
|
2012-09-21 00:32:26 +04:00
|
|
|
void AddName(std::string const& name);
|
2015-09-01 20:39:55 +03:00
|
|
|
void SetName(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
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03: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.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->OpenBSD = 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)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::const_iterator ci = in.begin(); ci != in.end(); ++ci) {
|
2008-09-22 18:59:52 +04:00
|
|
|
char ch = *ci;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '\\' ||
|
|
|
|
ch == '.' || ch == '*' || ch == '+' || ch == '?' || ch == '-' ||
|
|
|
|
ch == '^' || ch == '$') {
|
2008-09-22 18:59:52 +04:00
|
|
|
out += "\\";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__)
|
|
|
|
out += tolower(ch);
|
|
|
|
#else
|
|
|
|
out += ch;
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
}
|
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 = "";
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator si = in.begin();
|
|
|
|
si != in.end(); ++si) {
|
2008-09-22 18:59:52 +04:00
|
|
|
// Separate from previous item.
|
|
|
|
out += sep;
|
|
|
|
sep = "|";
|
|
|
|
|
|
|
|
// Append this item.
|
|
|
|
this->RegexFromLiteral(out, *si);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
out += ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmFindLibraryHelper::HasValidSuffix(std::string const& name)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.length() <= suffix.length()) {
|
2012-02-15 22:55:57 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-02-15 22:55:57 +04:00
|
|
|
// Check if the given name ends in a valid library suffix.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.substr(name.size() - suffix.length()) == suffix) {
|
2012-02-15 22:55:57 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-02-15 22:55:57 +04:00
|
|
|
// Check if a valid library suffix is somewhere in the name,
|
|
|
|
// this may happen e.g. for versioned shared libraries: libfoo.so.2
|
|
|
|
suffix += ".";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.find(suffix) != name.npos) {
|
2008-09-22 18:59:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OpenBSD) {
|
2008-09-22 19:08:17 +04:00
|
|
|
regex += "(\\.[0-9]+\\.[0-9]+)?";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-09-01 20:39:55 +03:00
|
|
|
void cmFindLibraryHelper::SetName(std::string const& name)
|
|
|
|
{
|
|
|
|
this->Names.clear();
|
|
|
|
this->AddName(name);
|
|
|
|
}
|
|
|
|
|
2008-09-22 18:59:52 +04:00
|
|
|
bool cmFindLibraryHelper::CheckDirectory(std::string const& path)
|
2012-09-21 00:32:26 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<Name>::iterator i = this->Names.begin();
|
|
|
|
i != this->Names.end(); ++i) {
|
|
|
|
if (this->CheckDirectoryForName(path, *i)) {
|
2012-09-21 00:32:26 +04:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-21 00:32:26 +04:00
|
|
|
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).
|
2016-05-16 17:34:04 +03: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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(this->TestPath.c_str(), true)) {
|
|
|
|
this->BestPath = cmSystemTools::CollapseFullPath(this->TestPath);
|
2008-09-22 18:59:52 +04:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(this->BestPath);
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
|
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);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::set<std::string>::const_iterator fi = files.begin();
|
|
|
|
fi != files.end(); ++fi) {
|
2008-09-22 18:59:52 +04:00
|
|
|
std::string const& origName = *fi;
|
|
|
|
#if defined(_WIN32) || defined(__APPLE__)
|
|
|
|
std::string testName = cmSystemTools::LowerCase(origName);
|
|
|
|
#else
|
|
|
|
std::string const& testName = origName;
|
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name.Regex.find(testName)) {
|
2008-09-22 18:59:52 +04:00
|
|
|
this->TestPath = path;
|
|
|
|
this->TestPath += origName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsDirectory(this->TestPath)) {
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OpenBSD) {
|
2012-09-21 00:32:26 +04:00
|
|
|
sscanf(name.Regex.match(3).c_str(), ".%u.%u", &major, &minor);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (this->BestPath.empty() || prefix < bestPrefix ||
|
|
|
|
(prefix == bestPrefix && suffix < bestSuffix) ||
|
|
|
|
(prefix == bestPrefix && suffix == bestSuffix &&
|
|
|
|
(major > bestMajor ||
|
|
|
|
(major == bestMajor && minor > bestMinor)))) {
|
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-06 23:26:22 +03:00
|
|
|
}
|
2008-09-22 18:59:52 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03: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
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->NamesPerDir) {
|
2012-09-24 19:05:10 +04:00
|
|
|
return this->FindNormalLibraryNamesPerDir();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-09-24 19:05:10 +04:00
|
|
|
return this->FindNormalLibraryDirsPerName();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-24 19:05:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmFindLibraryCommand::FindNormalLibraryNamesPerDir()
|
|
|
|
{
|
|
|
|
// Search for all names in each directory.
|
|
|
|
cmFindLibraryHelper helper(this->Makefile);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni) {
|
2012-09-24 19:05:10 +04:00
|
|
|
helper.AddName(*ni);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-24 19:05:10 +04:00
|
|
|
// Search every directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p = this->SearchPaths.begin();
|
|
|
|
p != this->SearchPaths.end(); ++p) {
|
|
|
|
if (helper.CheckDirectory(*p)) {
|
2012-09-24 19:05:10 +04:00
|
|
|
return helper.BestPath;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-24 19:05:10 +04:00
|
|
|
// 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);
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni) {
|
2008-09-22 18:59:52 +04:00
|
|
|
// Switch to searching for this name.
|
2015-09-01 20:39:55 +03:00
|
|
|
helper.SetName(*ni);
|
2008-09-22 18:59:52 +04:00
|
|
|
|
|
|
|
// Search every directory.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p =
|
|
|
|
this->SearchPaths.begin();
|
|
|
|
p != this->SearchPaths.end(); ++p) {
|
|
|
|
if (helper.CheckDirectory(*p)) {
|
2008-09-22 18:59:52 +04:00
|
|
|
return helper.BestPath;
|
2001-05-11 20:13:14 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03: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
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->NamesPerDir) {
|
2012-09-24 19:05:10 +04:00
|
|
|
return this->FindFrameworkLibraryNamesPerDir();
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2012-09-24 19:05:10 +04:00
|
|
|
return this->FindFrameworkLibraryDirsPerName();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-24 19:05:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmFindLibraryCommand::FindFrameworkLibraryNamesPerDir()
|
|
|
|
{
|
|
|
|
std::string fwPath;
|
|
|
|
// Search for all names in each search path.
|
2016-05-16 17:34:04 +03:00
|
|
|
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) {
|
2012-09-24 19:05:10 +04:00
|
|
|
fwPath = *di;
|
|
|
|
fwPath += *ni;
|
|
|
|
fwPath += ".framework";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(fwPath)) {
|
2014-10-15 16:54:05 +04:00
|
|
|
return cmSystemTools::CollapseFullPath(fwPath);
|
2012-09-24 19:05:10 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator ni = this->Names.begin();
|
|
|
|
ni != this->Names.end(); ++ni) {
|
|
|
|
for (std::vector<std::string>::const_iterator di =
|
|
|
|
this->SearchPaths.begin();
|
|
|
|
di != this->SearchPaths.end(); ++di) {
|
2012-09-24 18:17:45 +04:00
|
|
|
fwPath = *di;
|
|
|
|
fwPath += *ni;
|
|
|
|
fwPath += ".framework";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(fwPath)) {
|
2014-10-15 16:54:05 +04:00
|
|
|
return cmSystemTools::CollapseFullPath(fwPath);
|
2008-06-09 19:58:29 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-06-09 19:58:29 +04:00
|
|
|
|
|
|
|
// No framework found.
|
|
|
|
return "";
|
|
|
|
}
|