summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-20 13:10:50 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-02-20 13:10:50 (GMT)
commitc4c570f9cc7a7c5f22670793af887dfa5a6dd7de (patch)
treeb0a30a923a61649f06212320de0929bb5803d3ae /Source
parentb7351d8e14ea7cc05b0c5d45dae48a21aef298c1 (diff)
parentffc06c12397e7cda7307afcfc8a79ebda4a786a6 (diff)
downloadCMake-c4c570f9cc7a7c5f22670793af887dfa5a6dd7de.zip
CMake-c4c570f9cc7a7c5f22670793af887dfa5a6dd7de.tar.gz
CMake-c4c570f9cc7a7c5f22670793af887dfa5a6dd7de.tar.bz2
Merge topic 'find-command-prefix-from-PATH'
ffc06c12 Teach find_(library|file|path) to get prefixes from PATH (#15370)
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFindBase.cxx1
-rw-r--r--Source/cmSearchPath.cxx22
-rw-r--r--Source/cmSearchPath.h2
3 files changed, 23 insertions, 2 deletions
diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx
index 6e55533..4336e1c 100644
--- a/Source/cmFindBase.cxx
+++ b/Source/cmFindBase.cxx
@@ -275,6 +275,7 @@ void cmFindBase::FillSystemEnvironmentPath()
if(!this->EnvironmentPath.empty())
{
paths.AddEnvPath(this->EnvironmentPath);
+ paths.AddEnvPrefixPath("PATH", true);
}
// Add PATH
paths.AddEnvPath("PATH");
diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx
index 861dbf1..1e777ab 100644
--- a/Source/cmSearchPath.cxx
+++ b/Source/cmSearchPath.cxx
@@ -136,10 +136,30 @@ void cmSearchPath::AddCMakePrefixPath(const std::string& variable)
}
//----------------------------------------------------------------------------
-void cmSearchPath::AddEnvPrefixPath(const std::string& variable)
+static std::string cmSearchPathStripBin(std::string const& s)
+{
+ // If the path is a PREFIX/bin case then add its parent instead.
+ if((cmHasLiteralSuffix(s, "/bin")) ||
+ (cmHasLiteralSuffix(s, "/sbin")))
+ {
+ return cmSystemTools::GetFilenamePath(s);
+ }
+ else
+ {
+ return s;
+ }
+}
+
+//----------------------------------------------------------------------------
+void cmSearchPath::AddEnvPrefixPath(const std::string& variable, bool stripBin)
{
std::vector<std::string> expanded;
cmSystemTools::GetPath(expanded, variable.c_str());
+ if (stripBin)
+ {
+ std::transform(expanded.begin(), expanded.end(), expanded.begin(),
+ cmSearchPathStripBin);
+ }
this->AddPrefixPaths(expanded);
}
diff --git a/Source/cmSearchPath.h b/Source/cmSearchPath.h
index 51a6149..41c680d 100644
--- a/Source/cmSearchPath.h
+++ b/Source/cmSearchPath.h
@@ -42,7 +42,7 @@ public:
void AddCMakePath(const std::string& variable);
void AddEnvPath(const std::string& variable);
void AddCMakePrefixPath(const std::string& variable);
- void AddEnvPrefixPath(const std::string& variable);
+ void AddEnvPrefixPath(const std::string& variable, bool stripBin = false);
void AddSuffixes(const std::vector<std::string>& suffixes);
protected: