Merge branch 'release-3.29'
[kiteware-cmake.git] / Source / cmSearchPath.h
blob4c0cabbf3f9ba51a0e08ed14bd5cbbd13f3916ac
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <cstddef>
8 #include <set>
9 #include <string>
10 #include <vector>
12 class cmFindCommon;
14 /** \class cmSearchPath
15 * \brief Container for encapsulating a set of search paths
17 * cmSearchPath is a container that encapsulates search path construction and
18 * management
20 class cmSearchPath
22 public:
23 // cmSearchPath must be initialized from a valid pointer. The only reason
24 // for the default is to allow it to be easily used in stl containers.
25 // Attempting to initialize with a NULL value will fail an assertion
26 cmSearchPath(cmFindCommon* findCmd = nullptr);
27 ~cmSearchPath();
29 cmSearchPath(const cmSearchPath&) = default;
30 cmSearchPath& operator=(const cmSearchPath&) = default;
32 struct PathWithPrefix
34 std::string Path;
35 std::string Prefix;
37 bool operator<(const PathWithPrefix& other) const
39 return this->Path < other.Path ||
40 (this->Path == other.Path && this->Prefix < other.Prefix);
43 const std::vector<PathWithPrefix>& GetPaths() const { return this->Paths; }
44 std::size_t size() const { return this->Paths.size(); }
46 void ExtractWithout(const std::set<std::string>& ignorePaths,
47 const std::set<std::string>& ignorePrefixes,
48 std::vector<std::string>& outPaths,
49 bool clear = false) const;
51 void AddPath(const std::string& path);
52 void AddUserPath(const std::string& path);
53 void AddCMakePath(const std::string& variable);
54 void AddEnvPath(const std::string& variable);
55 void AddCMakePrefixPath(const std::string& variable);
56 void AddEnvPrefixPath(const std::string& variable, bool stripBin = false);
57 void AddSuffixes(const std::vector<std::string>& suffixes);
58 void AddPrefixPaths(const std::vector<std::string>& paths,
59 const char* base = nullptr);
61 protected:
62 void AddPathInternal(const std::string& path, const std::string& prefix,
63 const char* base = nullptr);
65 cmFindCommon* FC;
66 std::vector<PathWithPrefix> Paths;