/src/CMake/Source/cmFindBase.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <string> |
8 | | #include <utility> |
9 | | #include <vector> |
10 | | |
11 | | #include "cmFindCommon.h" |
12 | | #include "cmStateTypes.h" |
13 | | |
14 | | class cmExecutionStatus; |
15 | | |
16 | | /** \class cmFindBase |
17 | | * \brief Base class for most FIND_XXX commands. |
18 | | * |
19 | | * cmFindBase is a parent class for cmFindProgramCommand, cmFindPathCommand, |
20 | | * and cmFindLibraryCommand, cmFindFileCommand |
21 | | */ |
22 | | class cmFindBase : public cmFindCommon |
23 | | { |
24 | | public: |
25 | | cmFindBase(std::string findCommandName, cmExecutionStatus& status); |
26 | | ~cmFindBase() override; |
27 | | |
28 | | /** |
29 | | * This is called when the command is first encountered in |
30 | | * the CMakeLists.txt file. |
31 | | */ |
32 | | virtual bool ParseArguments(std::vector<std::string> const& args); |
33 | | |
34 | | /** |
35 | | * To check validity of a found path using user's validator, if any |
36 | | */ |
37 | | bool Validate(std::string const& path) const; |
38 | | |
39 | | protected: |
40 | | friend class cmFindBaseDebugState; |
41 | | void ExpandPaths(); |
42 | | |
43 | | bool IsFound() const override; |
44 | | bool IsDefined() const override; |
45 | | |
46 | | void NormalizeFindResult(); |
47 | | void StoreFindResult(std::string const& value); |
48 | | |
49 | | // actual find command name |
50 | | std::string FindCommandName; |
51 | | |
52 | | // use by command during find |
53 | | std::string VariableDocumentation; |
54 | | cmStateEnums::CacheEntryType VariableType = cmStateEnums::UNINITIALIZED; |
55 | | std::string VariableName; |
56 | | std::vector<std::string> Names; |
57 | | bool NamesPerDir = false; |
58 | | bool NamesPerDirAllowed = false; |
59 | | |
60 | | // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM |
61 | | std::string EnvironmentPath; // LIB,INCLUDE |
62 | | |
63 | | bool AlreadyInCacheWithoutMetaInfo = false; |
64 | | bool StoreResultInCache = true; |
65 | | |
66 | | bool Required = false; |
67 | | |
68 | | std::string ValidatorName; |
69 | | |
70 | | private: |
71 | | enum class FindState |
72 | | { |
73 | | Undefined, |
74 | | Found, |
75 | | NotFound, |
76 | | }; |
77 | | // see if the VariableName is already set, |
78 | | // also copy the documentation from the cache to VariableDocumentation |
79 | | // if it has documentation in the cache |
80 | | FindState GetInitialState(); |
81 | | FindState InitialState = FindState::Undefined; |
82 | | |
83 | | // Add pieces of the search. |
84 | | void FillPackageRootPath(); |
85 | | void FillCMakeVariablePath(); |
86 | | void FillCMakeEnvironmentPath(); |
87 | | void FillUserHintsPath(); |
88 | | void FillSystemEnvironmentPath(); |
89 | | void FillCMakeSystemVariablePath(); |
90 | | void FillUserGuessPath(); |
91 | | }; |
92 | | |
93 | | class cmFindBaseDebugState : public cmFindCommonDebugState |
94 | | { |
95 | | public: |
96 | | explicit cmFindBaseDebugState(cmFindBase const* findBase); |
97 | | ~cmFindBaseDebugState() override; |
98 | | |
99 | | private: |
100 | | void FoundAtImpl(std::string const& path, std::string regexName) override; |
101 | | void FailedAtImpl(std::string const& path, std::string regexName) override; |
102 | | |
103 | | struct DebugLibState |
104 | | { |
105 | 0 | DebugLibState() = default; |
106 | | DebugLibState(std::string&& n, std::string p) |
107 | 0 | : regexName(n) |
108 | 0 | , path(std::move(p)) |
109 | 0 | { |
110 | 0 | } |
111 | | std::string regexName; |
112 | | std::string path; |
113 | | }; |
114 | | |
115 | | void WriteDebug() const override; |
116 | | #ifndef CMAKE_BOOTSTRAP |
117 | | void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const override; |
118 | | std::vector<std::pair<VariableSource, std::string>> ExtraSearchVariables() |
119 | | const override; |
120 | | #endif |
121 | | |
122 | | cmFindBase const* const FindBaseCommand; |
123 | | std::vector<DebugLibState> FailedSearchLocations; |
124 | | DebugLibState FoundSearchLocation; |
125 | | }; |