cmFindBase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include "cmFindCommon.h"
  9. #include "cmStateTypes.h"
  10. class cmConfigureLog;
  11. class cmExecutionStatus;
  12. class cmMakefile;
  13. /** \class cmFindBase
  14. * \brief Base class for most FIND_XXX commands.
  15. *
  16. * cmFindBase is a parent class for cmFindProgramCommand, cmFindPathCommand,
  17. * and cmFindLibraryCommand, cmFindFileCommand
  18. */
  19. class cmFindBase : public cmFindCommon
  20. {
  21. public:
  22. cmFindBase(std::string findCommandName, cmExecutionStatus& status);
  23. virtual ~cmFindBase() = default;
  24. /**
  25. * This is called when the command is first encountered in
  26. * the CMakeLists.txt file.
  27. */
  28. virtual bool ParseArguments(std::vector<std::string> const& args);
  29. /**
  30. * To check validity of a found path using user's validator, if any
  31. */
  32. bool Validate(std::string const& path) const;
  33. protected:
  34. friend class cmFindBaseDebugState;
  35. void ExpandPaths();
  36. bool IsFound() const;
  37. bool IsDefined() const;
  38. void NormalizeFindResult();
  39. void StoreFindResult(std::string const& value);
  40. // actual find command name
  41. std::string FindCommandName;
  42. // use by command during find
  43. std::string VariableDocumentation;
  44. cmStateEnums::CacheEntryType VariableType = cmStateEnums::UNINITIALIZED;
  45. std::string VariableName;
  46. std::vector<std::string> Names;
  47. bool NamesPerDir = false;
  48. bool NamesPerDirAllowed = false;
  49. // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
  50. std::string EnvironmentPath; // LIB,INCLUDE
  51. bool AlreadyInCacheWithoutMetaInfo = false;
  52. bool StoreResultInCache = true;
  53. bool Required = false;
  54. std::string ValidatorName;
  55. private:
  56. enum class FindState
  57. {
  58. Undefined,
  59. Found,
  60. NotFound,
  61. };
  62. // see if the VariableName is already set,
  63. // also copy the documentation from the cache to VariableDocumentation
  64. // if it has documentation in the cache
  65. FindState GetInitialState();
  66. FindState InitialState = FindState::Undefined;
  67. // Add pieces of the search.
  68. void FillPackageRootPath();
  69. void FillCMakeVariablePath();
  70. void FillCMakeEnvironmentPath();
  71. void FillUserHintsPath();
  72. void FillSystemEnvironmentPath();
  73. void FillCMakeSystemVariablePath();
  74. void FillUserGuessPath();
  75. };
  76. class cmFindBaseDebugState
  77. {
  78. public:
  79. explicit cmFindBaseDebugState(cmFindBase const* findBase);
  80. ~cmFindBaseDebugState();
  81. void FoundAt(std::string const& path, std::string regexName = std::string());
  82. void FailedAt(std::string const& path,
  83. std::string regexName = std::string());
  84. private:
  85. struct DebugLibState
  86. {
  87. DebugLibState() = default;
  88. DebugLibState(std::string&& n, std::string p)
  89. : regexName(n)
  90. , path(std::move(p))
  91. {
  92. }
  93. std::string regexName;
  94. std::string path;
  95. };
  96. #ifndef CMAKE_BOOTSTRAP
  97. void WriteFindEvent(cmConfigureLog& log, cmMakefile const& mf) const;
  98. #endif
  99. cmFindBase const* FindCommand;
  100. std::string CommandName;
  101. bool TrackSearchProgress() const;
  102. std::vector<DebugLibState> FailedSearchLocations;
  103. DebugLibState FoundSearchLocation;
  104. };