resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmFindBase.h
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
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   virtual ~cmFindBase() = default;
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(const std::string& path) const;
38
39 protected:
40   friend class cmFindBaseDebugState;
41   void ExpandPaths();
42
43   // see if the VariableName is already set,
44   // also copy the documentation from the cache to VariableDocumentation
45   // if it has documentation in the cache
46   bool CheckForVariableDefined();
47
48   void NormalizeFindResult();
49   void StoreFindResult(const std::string& value);
50
51   // actual find command name
52   std::string FindCommandName;
53
54   // use by command during find
55   std::string VariableDocumentation;
56   cmStateEnums::CacheEntryType VariableType = cmStateEnums::UNINITIALIZED;
57   std::string VariableName;
58   std::vector<std::string> Names;
59   bool NamesPerDir = false;
60   bool NamesPerDirAllowed = false;
61
62   // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
63   std::string EnvironmentPath; // LIB,INCLUDE
64
65   bool AlreadyDefined = false;
66   bool AlreadyInCacheWithoutMetaInfo = false;
67   bool StoreResultInCache = true;
68
69   bool Required = false;
70
71   std::string ValidatorName;
72
73 private:
74   // Add pieces of the search.
75   void FillPackageRootPath();
76   void FillCMakeVariablePath();
77   void FillCMakeEnvironmentPath();
78   void FillUserHintsPath();
79   void FillSystemEnvironmentPath();
80   void FillCMakeSystemVariablePath();
81   void FillUserGuessPath();
82 };
83
84 class cmFindBaseDebugState
85 {
86 public:
87   explicit cmFindBaseDebugState(std::string name, cmFindBase const* findBase);
88   ~cmFindBaseDebugState();
89
90   void FoundAt(std::string const& path, std::string regexName = std::string());
91   void FailedAt(std::string const& path,
92                 std::string regexName = std::string());
93
94 private:
95   struct DebugLibState
96   {
97     DebugLibState() = default;
98     DebugLibState(std::string&& n, std::string p)
99       : regexName(n)
100       , path(std::move(p))
101     {
102     }
103     std::string regexName;
104     std::string path;
105   };
106
107   cmFindBase const* FindCommand;
108   std::string CommandName;
109   std::vector<DebugLibState> FailedSearchLocations;
110   DebugLibState FoundSearchLocation;
111 };