cmFindBase.h 3.2 KB

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