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.
This commit is contained in:
Brad King
2015-02-18 10:54:45 -05:00
parent 4fb9e847c0
commit ffc06c1239
23 changed files with 99 additions and 5 deletions

View File

@@ -275,6 +275,7 @@ void cmFindBase::FillSystemEnvironmentPath()
if(!this->EnvironmentPath.empty())
{
paths.AddEnvPath(this->EnvironmentPath);
paths.AddEnvPrefixPath("PATH", true);
}
// Add PATH
paths.AddEnvPath("PATH");

View File

@@ -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);
}

View File

@@ -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: