summaryrefslogtreecommitdiffstats
path: root/Source/cmSearchPath.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-02-18 15:54:45 (GMT)
committerBrad King <brad.king@kitware.com>2015-02-19 15:03:17 (GMT)
commitffc06c12397e7cda7307afcfc8a79ebda4a786a6 (patch)
tree865c2be9956c6de122269ec4989102863c9e67b9 /Source/cmSearchPath.cxx
parent4fb9e847c0c757ff6e1ee430bbb9fc2b6b4e2ae6 (diff)
downloadCMake-ffc06c12397e7cda7307afcfc8a79ebda4a786a6.zip
CMake-ffc06c12397e7cda7307afcfc8a79ebda4a786a6.tar.gz
CMake-ffc06c12397e7cda7307afcfc8a79ebda4a786a6.tar.bz2
Teach find_(library|file|path) to get prefixes from PATH (#15370)
The find_package command already knows how to compute installation prefixes from PATH. Use the same approach to establish prefixes for find_library, find_file, and find_path to use to look in directories like "<prefix>/lib[/<arch>]" and "<prefix>/include" for libraries and headers. This will reduce the amount of configuration end users need to do to establish a work environment rooted under a specific prefix.
Diffstat (limited to 'Source/cmSearchPath.cxx')
-rw-r--r--Source/cmSearchPath.cxx22
1 files changed, 21 insertions, 1 deletions
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);
}