2014-10-16 00:36:42 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmSearchPath.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2015-03-08 15:51:20 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmFindCommon.h"
|
2014-10-16 00:36:42 +04:00
|
|
|
|
2014-10-17 21:07:26 +04:00
|
|
|
cmSearchPath::cmSearchPath(cmFindCommon* findCmd)
|
2016-05-16 17:34:04 +03:00
|
|
|
: FC(findCmd)
|
2014-10-16 00:36:42 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cmSearchPath::~cmSearchPath()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::ExtractWithout(const std::set<std::string>& ignore,
|
|
|
|
std::vector<std::string>& outPaths,
|
|
|
|
bool clear) const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (clear) {
|
2014-10-16 00:36:42 +04:00
|
|
|
outPaths.clear();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
for (std::vector<std::string>::const_iterator p = this->Paths.begin();
|
|
|
|
p != this->Paths.end(); ++p) {
|
|
|
|
if (ignore.count(*p) == 0) {
|
2014-10-16 00:36:42 +04:00
|
|
|
outPaths.push_back(*p);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddPath(const std::string& path)
|
|
|
|
{
|
|
|
|
this->AddPathInternal(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddUserPath(const std::string& path)
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
assert(this->FC != CM_NULLPTR);
|
2014-10-17 21:07:26 +04:00
|
|
|
|
2014-10-16 00:36:42 +04:00
|
|
|
std::vector<std::string> outPaths;
|
|
|
|
|
|
|
|
// We should view the registry as the target application would view
|
|
|
|
// it.
|
|
|
|
cmSystemTools::KeyWOW64 view = cmSystemTools::KeyWOW64_32;
|
|
|
|
cmSystemTools::KeyWOW64 other_view = cmSystemTools::KeyWOW64_64;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->FC->Makefile->PlatformIs64Bit()) {
|
2014-10-16 00:36:42 +04:00
|
|
|
view = cmSystemTools::KeyWOW64_64;
|
|
|
|
other_view = cmSystemTools::KeyWOW64_32;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
|
|
|
// Expand using the view of the target application.
|
|
|
|
std::string expanded = path;
|
|
|
|
cmSystemTools::ExpandRegistryValues(expanded, view);
|
|
|
|
cmSystemTools::GlobDirs(expanded, outPaths);
|
|
|
|
|
|
|
|
// Executables can be either 32-bit or 64-bit, so expand using the
|
|
|
|
// alternative view.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (expanded != path && this->FC->CMakePathName == "PROGRAM") {
|
2014-10-16 00:36:42 +04:00
|
|
|
expanded = path;
|
|
|
|
cmSystemTools::ExpandRegistryValues(expanded, other_view);
|
|
|
|
cmSystemTools::GlobDirs(expanded, outPaths);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
|
|
|
// Process them all from the current directory
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p = outPaths.begin();
|
|
|
|
p != outPaths.end(); ++p) {
|
2015-04-16 22:17:41 +03:00
|
|
|
this->AddPathInternal(*p, this->FC->Makefile->GetCurrentSourceDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddCMakePath(const std::string& variable)
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
assert(this->FC != CM_NULLPTR);
|
2014-10-17 21:07:26 +04:00
|
|
|
|
2014-10-16 00:36:42 +04:00
|
|
|
// Get a path from a CMake variable.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* value = this->FC->Makefile->GetDefinition(variable)) {
|
2014-10-16 00:36:42 +04:00
|
|
|
std::vector<std::string> expanded;
|
|
|
|
cmSystemTools::ExpandListArgument(value, expanded);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p = expanded.begin();
|
|
|
|
p != expanded.end(); ++p) {
|
2015-04-16 22:17:41 +03:00
|
|
|
this->AddPathInternal(*p,
|
|
|
|
this->FC->Makefile->GetCurrentSourceDirectory());
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddEnvPath(const std::string& variable)
|
|
|
|
{
|
|
|
|
std::vector<std::string> expanded;
|
|
|
|
cmSystemTools::GetPath(expanded, variable.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p = expanded.begin();
|
|
|
|
p != expanded.end(); ++p) {
|
2014-10-16 00:36:42 +04:00
|
|
|
this->AddPathInternal(*p);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddCMakePrefixPath(const std::string& variable)
|
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
assert(this->FC != CM_NULLPTR);
|
2014-10-17 21:07:26 +04:00
|
|
|
|
2014-10-16 00:36:42 +04:00
|
|
|
// Get a path from a CMake variable.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (const char* value = this->FC->Makefile->GetDefinition(variable)) {
|
2014-10-16 00:36:42 +04:00
|
|
|
std::vector<std::string> expanded;
|
|
|
|
cmSystemTools::ExpandListArgument(value, expanded);
|
|
|
|
|
2015-04-16 22:17:41 +03:00
|
|
|
this->AddPrefixPaths(expanded,
|
|
|
|
this->FC->Makefile->GetCurrentSourceDirectory());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
2015-02-18 18:54:45 +03:00
|
|
|
static std::string cmSearchPathStripBin(std::string const& s)
|
|
|
|
{
|
|
|
|
// If the path is a PREFIX/bin case then add its parent instead.
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((cmHasLiteralSuffix(s, "/bin")) || (cmHasLiteralSuffix(s, "/sbin"))) {
|
2015-02-18 18:54:45 +03:00
|
|
|
return cmSystemTools::GetFilenamePath(s);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-02-18 18:54:45 +03:00
|
|
|
return s;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-18 18:54:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddEnvPrefixPath(const std::string& variable, bool stripBin)
|
2014-10-16 00:36:42 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> expanded;
|
|
|
|
cmSystemTools::GetPath(expanded, variable.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (stripBin) {
|
2015-02-18 18:54:45 +03:00
|
|
|
std::transform(expanded.begin(), expanded.end(), expanded.begin(),
|
|
|
|
cmSearchPathStripBin);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
this->AddPrefixPaths(expanded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddSuffixes(const std::vector<std::string>& suffixes)
|
|
|
|
{
|
|
|
|
std::vector<std::string> inPaths;
|
|
|
|
inPaths.swap(this->Paths);
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Paths.reserve(inPaths.size() * (suffixes.size() + 1));
|
2014-10-16 00:36:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator ip = inPaths.begin();
|
|
|
|
ip != inPaths.end(); ++ip) {
|
2014-10-16 00:36:42 +04:00
|
|
|
cmSystemTools::ConvertToUnixSlashes(*ip);
|
|
|
|
|
|
|
|
// if *i is only / then do not add a //
|
|
|
|
// this will get incorrectly considered a network
|
|
|
|
// path on windows and cause huge delays.
|
|
|
|
std::string p = *ip;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!p.empty() && *p.rbegin() != '/') {
|
2014-10-16 00:36:42 +04:00
|
|
|
p += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
|
|
|
// Combine with all the suffixes
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator s = suffixes.begin();
|
|
|
|
s != suffixes.end(); ++s) {
|
|
|
|
this->Paths.push_back(p + *s);
|
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
|
|
|
// And now the original w/o any suffix
|
|
|
|
this->Paths.push_back(*ip);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmSearchPath::AddPrefixPaths(const std::vector<std::string>& paths,
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* base)
|
2014-10-16 00:36:42 +04:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
assert(this->FC != CM_NULLPTR);
|
2014-10-17 21:07:26 +04:00
|
|
|
|
2014-10-16 00:36:42 +04:00
|
|
|
// default for programs
|
|
|
|
std::string subdir = "bin";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->FC->CMakePathName == "INCLUDE") {
|
2014-10-16 00:36:42 +04:00
|
|
|
subdir = "include";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->FC->CMakePathName == "LIBRARY") {
|
2014-10-16 00:36:42 +04:00
|
|
|
subdir = "lib";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->FC->CMakePathName == "FRAMEWORK") {
|
|
|
|
subdir = ""; // ? what to do for frameworks ?
|
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::const_iterator p = paths.begin();
|
|
|
|
p != paths.end(); ++p) {
|
2014-10-16 00:36:42 +04:00
|
|
|
std::string dir = *p;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!subdir.empty() && !dir.empty() && *dir.rbegin() != '/') {
|
2014-10-16 00:36:42 +04:00
|
|
|
dir += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (subdir == "include" || subdir == "lib") {
|
2014-10-16 00:36:42 +04:00
|
|
|
const char* arch =
|
2014-10-17 21:07:26 +04:00
|
|
|
this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arch && *arch) {
|
|
|
|
this->AddPathInternal(dir + subdir + "/" + arch, base);
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
std::string add = dir + subdir;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (add != "/") {
|
2014-10-16 00:36:42 +04:00
|
|
|
this->AddPathInternal(add, base);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (subdir == "bin") {
|
|
|
|
this->AddPathInternal(dir + "sbin", base);
|
|
|
|
}
|
|
|
|
if (!subdir.empty() && *p != "/") {
|
2014-10-16 00:36:42 +04:00
|
|
|
this->AddPathInternal(*p, base);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmSearchPath::AddPathInternal(const std::string& path, const char* base)
|
2014-10-16 00:36:42 +04:00
|
|
|
{
|
2016-06-27 23:44:16 +03:00
|
|
|
assert(this->FC != CM_NULLPTR);
|
2014-10-17 21:07:26 +04:00
|
|
|
|
2014-10-16 00:36:42 +04:00
|
|
|
std::string collapsed = cmSystemTools::CollapseFullPath(path, base);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (collapsed.empty()) {
|
2014-10-16 00:36:42 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
|
|
|
|
// Insert the path if has not already been emitted.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->FC->SearchPathsEmitted.insert(collapsed).second) {
|
2014-10-16 00:36:42 +04:00
|
|
|
this->Paths.push_back(collapsed);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-10-16 00:36:42 +04:00
|
|
|
}
|