CMake/Source/cmSearchPath.h
Brad King eb35d8884b find_package: Use PackageName_ROOT variables as search prefixes
This feature was originally added by commit v3.9.0-rc1~71^2~2 (find_*:
Add a new PackageRoot search path group, 2017-05-03) and documented by
commit v3.9.0-rc1~71^2 (find_*: Add docs for PackageRoot search path
group, 2017-05-03).  However, we had to disable the feature and remove
the documentation in commit v3.9.1~2^2 (find_*: Disable the PACKAGE_ROOT
search path group for CMake 3.9, 2017-08-08) due to breaking projects
that used `PackageName_ROOT` variables themselves.

Add policy `CMP0074` to restore the `PackageName_ROOT` variable behavior
in a compatible way.  Also revise the stack of root paths to store the
paths themselves rather than the package names.  This way the policy can
be considered at the `find_package` call site instead of individual
`find_` calls inside a find module.

Co-Author: Chuck Atkins <chuck.atkins@kitware.com>
Issue: #17144
2018-03-16 09:19:28 -04:00

53 lines
1.7 KiB
C++

/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmSearchPath_h
#define cmSearchPath_h
#include "cmConfigure.h" // IWYU pragma: keep
#include <set>
#include <string>
#include <vector>
class cmFindCommon;
/** \class cmSearchPath
* \brief Container for encapsulating a set of search paths
*
* cmSearchPath is a container that encapsulates search path construction and
* management
*/
class cmSearchPath
{
public:
// cmSearchPath must be initialized from a valid pointer. The only reason
// for the default is to allow it to be easily used in stl containers.
// Attempting to initialize with a NULL value will fail an assertion
cmSearchPath(cmFindCommon* findCmd = nullptr);
~cmSearchPath();
const std::vector<std::string>& GetPaths() const { return this->Paths; }
void ExtractWithout(const std::set<std::string>& ignore,
std::vector<std::string>& outPaths,
bool clear = false) const;
void AddPath(const std::string& path);
void AddUserPath(const std::string& path);
void AddCMakePath(const std::string& variable);
void AddEnvPath(const std::string& variable);
void AddCMakePrefixPath(const std::string& variable);
void AddEnvPrefixPath(const std::string& variable, bool stripBin = false);
void AddSuffixes(const std::vector<std::string>& suffixes);
void AddPrefixPaths(const std::vector<std::string>& paths,
const char* base = nullptr);
protected:
void AddPathInternal(const std::string& path, const char* base = nullptr);
cmFindCommon* FC;
std::vector<std::string> Paths;
};
#endif