mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-23 15:38:52 -06:00
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:
@@ -275,6 +275,7 @@ void cmFindBase::FillSystemEnvironmentPath()
|
||||
if(!this->EnvironmentPath.empty())
|
||||
{
|
||||
paths.AddEnvPath(this->EnvironmentPath);
|
||||
paths.AddEnvPrefixPath("PATH", true);
|
||||
}
|
||||
// Add PATH
|
||||
paths.AddEnvPath("PATH");
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user