cmFindBase.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmFindBase_h
  4. #define cmFindBase_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "cmFindCommon.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(cmExecutionStatus& status);
  21. virtual ~cmFindBase() = default;
  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. protected:
  28. friend class cmFindBaseDebugState;
  29. void ExpandPaths();
  30. // see if the VariableName is already set in the cache,
  31. // also copy the documentation from the cache to VariableDocumentation
  32. // if it has documentation in the cache
  33. bool CheckForVariableInCache();
  34. // use by command during find
  35. std::string VariableDocumentation;
  36. std::string VariableName;
  37. std::vector<std::string> Names;
  38. bool NamesPerDir;
  39. bool NamesPerDirAllowed;
  40. // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
  41. std::string EnvironmentPath; // LIB,INCLUDE
  42. bool AlreadyInCache;
  43. bool AlreadyInCacheWithoutMetaInfo;
  44. private:
  45. // Add pieces of the search.
  46. void FillPackageRootPath();
  47. void FillCMakeVariablePath();
  48. void FillCMakeEnvironmentPath();
  49. void FillUserHintsPath();
  50. void FillSystemEnvironmentPath();
  51. void FillCMakeSystemVariablePath();
  52. void FillUserGuessPath();
  53. };
  54. class cmFindBaseDebugState
  55. {
  56. public:
  57. explicit cmFindBaseDebugState(std::string name, cmFindBase const* findBase);
  58. ~cmFindBaseDebugState();
  59. void FoundAt(std::string const& path, std::string regexName = std::string());
  60. void FailedAt(std::string const& path,
  61. std::string regexName = std::string());
  62. private:
  63. struct DebugLibState
  64. {
  65. DebugLibState() = default;
  66. DebugLibState(std::string&& n, std::string p)
  67. : regexName(n)
  68. , path(std::move(p))
  69. {
  70. }
  71. std::string regexName;
  72. std::string path;
  73. };
  74. cmFindBase const* FindCommand;
  75. std::string CommandName;
  76. std::vector<DebugLibState> FailedSearchLocations;
  77. DebugLibState FoundSearchLocation;
  78. };
  79. #endif