cmFindBase.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. 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. void NormalizeFindResult();
  35. void StoreFindResult(const std::string& value);
  36. // actual find command name
  37. std::string FindCommandName;
  38. // use by command during find
  39. std::string VariableDocumentation;
  40. cmStateEnums::CacheEntryType VariableType = cmStateEnums::UNINITIALIZED;
  41. std::string VariableName;
  42. std::vector<std::string> Names;
  43. bool NamesPerDir = false;
  44. bool NamesPerDirAllowed = false;
  45. // CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
  46. std::string EnvironmentPath; // LIB,INCLUDE
  47. bool AlreadyInCache = false;
  48. bool AlreadyInCacheWithoutMetaInfo = false;
  49. bool Required = false;
  50. private:
  51. // Add pieces of the search.
  52. void FillPackageRootPath();
  53. void FillCMakeVariablePath();
  54. void FillCMakeEnvironmentPath();
  55. void FillUserHintsPath();
  56. void FillSystemEnvironmentPath();
  57. void FillCMakeSystemVariablePath();
  58. void FillUserGuessPath();
  59. };
  60. class cmFindBaseDebugState
  61. {
  62. public:
  63. explicit cmFindBaseDebugState(std::string name, cmFindBase const* findBase);
  64. ~cmFindBaseDebugState();
  65. void FoundAt(std::string const& path, std::string regexName = std::string());
  66. void FailedAt(std::string const& path,
  67. std::string regexName = std::string());
  68. private:
  69. struct DebugLibState
  70. {
  71. DebugLibState() = default;
  72. DebugLibState(std::string&& n, std::string p)
  73. : regexName(n)
  74. , path(std::move(p))
  75. {
  76. }
  77. std::string regexName;
  78. std::string path;
  79. };
  80. cmFindBase const* FindCommand;
  81. std::string CommandName;
  82. std::vector<DebugLibState> FailedSearchLocations;
  83. DebugLibState FoundSearchLocation;
  84. };