Merge branch 'release-3.29'
[kiteware-cmake.git] / Source / cmFindBase.h
blob75d9a6d25311ec3d06a4ad2db3015f9c2e043614
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 <string>
8 #include <utility>
9 #include <vector>
11 #include "cmFindCommon.h"
12 #include "cmStateTypes.h"
14 class cmExecutionStatus;
16 /** \class cmFindBase
17 * \brief Base class for most FIND_XXX commands.
19 * cmFindBase is a parent class for cmFindProgramCommand, cmFindPathCommand,
20 * and cmFindLibraryCommand, cmFindFileCommand
22 class cmFindBase : public cmFindCommon
24 public:
25 cmFindBase(std::string findCommandName, cmExecutionStatus& status);
26 virtual ~cmFindBase() = default;
28 /**
29 * This is called when the command is first encountered in
30 * the CMakeLists.txt file.
32 virtual bool ParseArguments(std::vector<std::string> const& args);
34 /**
35 * To check validity of a found path using user's validator, if any
37 bool Validate(const std::string& path) const;
39 protected:
40 friend class cmFindBaseDebugState;
41 void ExpandPaths();
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();
48 void NormalizeFindResult();
49 void StoreFindResult(const std::string& value);
51 // actual find command name
52 std::string FindCommandName;
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;
62 // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
63 std::string EnvironmentPath; // LIB,INCLUDE
65 bool AlreadyDefined = false;
66 bool AlreadyInCacheWithoutMetaInfo = false;
67 bool StoreResultInCache = true;
69 bool Required = false;
71 std::string ValidatorName;
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();
84 class cmFindBaseDebugState
86 public:
87 explicit cmFindBaseDebugState(std::string name, cmFindBase const* findBase);
88 ~cmFindBaseDebugState();
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());
94 private:
95 struct DebugLibState
97 DebugLibState() = default;
98 DebugLibState(std::string&& n, std::string p)
99 : regexName(n)
100 , path(std::move(p))
103 std::string regexName;
104 std::string path;
107 cmFindBase const* FindCommand;
108 std::string CommandName;
109 std::vector<DebugLibState> FailedSearchLocations;
110 DebugLibState FoundSearchLocation;