cmFindBase.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. #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. 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. /**
  28. * To check validity of a found path using user's validator, if any
  29. */
  30. bool Validate(const std::string& path) const;
  31. protected:
  32. friend class cmFindBaseDebugState;
  33. void ExpandPaths();
  34. // see if the VariableName is already set,
  35. // also copy the documentation from the cache to VariableDocumentation
  36. // if it has documentation in the cache
  37. bool CheckForVariableDefined();
  38. void NormalizeFindResult();
  39. void StoreFindResult(const std::string& 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 AlreadyDefined = false;
  52. bool AlreadyInCacheWithoutMetaInfo = false;
  53. bool StoreResultInCache = true;
  54. bool Required = false;
  55. std::string ValidatorName;
  56. private:
  57. // Add pieces of the search.
  58. void FillPackageRootPath();
  59. void FillCMakeVariablePath();
  60. void FillCMakeEnvironmentPath();
  61. void FillUserHintsPath();
  62. void FillSystemEnvironmentPath();
  63. void FillCMakeSystemVariablePath();
  64. void FillUserGuessPath();
  65. };
  66. class cmFindBaseDebugState
  67. {
  68. public:
  69. explicit cmFindBaseDebugState(std::string name, cmFindBase const* findBase);
  70. ~cmFindBaseDebugState();
  71. void FoundAt(std::string const& path, std::string regexName = std::string());
  72. void FailedAt(std::string const& path,
  73. std::string regexName = std::string());
  74. private:
  75. struct DebugLibState
  76. {
  77. DebugLibState() = default;
  78. DebugLibState(std::string&& n, std::string p)
  79. : regexName(n)
  80. , path(std::move(p))
  81. {
  82. }
  83. std::string regexName;
  84. std::string path;
  85. };
  86. cmFindBase const* FindCommand;
  87. std::string CommandName;
  88. std::vector<DebugLibState> FailedSearchLocations;
  89. DebugLibState FoundSearchLocation;
  90. };