cmFindCommon.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <map>
  6. #include <set>
  7. #include <string>
  8. #include <vector>
  9. #include "cmPathLabel.h"
  10. #include "cmSearchPath.h"
  11. #include "cmWindowsRegistry.h"
  12. class cmExecutionStatus;
  13. class cmMakefile;
  14. /** \class cmFindCommon
  15. * \brief Base class for FIND_XXX implementations.
  16. *
  17. * cmFindCommon is a parent class for cmFindBase,
  18. * cmFindProgramCommand, cmFindPathCommand, cmFindLibraryCommand,
  19. * cmFindFileCommand, and cmFindPackageCommand.
  20. */
  21. class cmFindCommon
  22. {
  23. public:
  24. cmFindCommon(cmExecutionStatus& status);
  25. void SetError(std::string const& e);
  26. bool DebugModeEnabled() const { return this->DebugMode; }
  27. protected:
  28. friend class cmSearchPath;
  29. friend class cmFindBaseDebugState;
  30. /** Used to define groups of path labels */
  31. class PathGroup : public cmPathLabel
  32. {
  33. protected:
  34. PathGroup();
  35. public:
  36. PathGroup(const std::string& label)
  37. : cmPathLabel(label)
  38. {
  39. }
  40. static PathGroup All;
  41. };
  42. /* Individual path types */
  43. class PathLabel : public cmPathLabel
  44. {
  45. protected:
  46. PathLabel();
  47. public:
  48. PathLabel(const std::string& label)
  49. : cmPathLabel(label)
  50. {
  51. }
  52. static PathLabel PackageRoot;
  53. static PathLabel CMake;
  54. static PathLabel CMakeEnvironment;
  55. static PathLabel Hints;
  56. static PathLabel SystemEnvironment;
  57. static PathLabel CMakeSystem;
  58. static PathLabel Guess;
  59. };
  60. enum RootPathMode
  61. {
  62. RootPathModeNever,
  63. RootPathModeOnly,
  64. RootPathModeBoth
  65. };
  66. /** Construct the various path groups and labels */
  67. void InitializeSearchPathGroups();
  68. /** Place a set of search paths under the search roots. */
  69. void RerootPaths(std::vector<std::string>& paths,
  70. std::string* debugBuffer = nullptr);
  71. /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PATH variables. */
  72. void GetIgnoredPaths(std::vector<std::string>& ignore);
  73. void GetIgnoredPaths(std::set<std::string>& ignore);
  74. /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PREFIX_PATH variables. */
  75. void GetIgnoredPrefixPaths(std::vector<std::string>& ignore);
  76. void GetIgnoredPrefixPaths(std::set<std::string>& ignore);
  77. /** Compute final search path list (reroot + trailing slash). */
  78. enum class IgnorePaths
  79. {
  80. No,
  81. Yes,
  82. };
  83. void ComputeFinalPaths(IgnorePaths ignorePaths,
  84. std::string* debugBuffer = nullptr);
  85. /** Compute the current default root path mode. */
  86. void SelectDefaultRootPathMode();
  87. /** Compute the current default bundle/framework search policy. */
  88. void SelectDefaultMacMode();
  89. /** Compute the current default search modes based on global variables. */
  90. void SelectDefaultSearchModes();
  91. /** The `InitialPass` functions of the child classes should set
  92. this->DebugMode to the result of these. */
  93. bool ComputeIfDebugModeWanted();
  94. bool ComputeIfDebugModeWanted(std::string const& var);
  95. // Path arguments prior to path manipulation routines
  96. std::vector<std::string> UserHintsArgs;
  97. std::vector<std::string> UserGuessArgs;
  98. std::string CMakePathName;
  99. RootPathMode FindRootPathMode;
  100. bool CheckCommonArgument(std::string const& arg);
  101. void AddPathSuffix(std::string const& arg);
  102. void DebugMessage(std::string const& msg) const;
  103. bool DebugMode;
  104. bool NoDefaultPath;
  105. bool NoPackageRootPath;
  106. bool NoCMakePath;
  107. bool NoCMakeEnvironmentPath;
  108. bool NoSystemEnvironmentPath;
  109. bool NoCMakeSystemPath;
  110. bool NoCMakeInstallPath;
  111. cmWindowsRegistry::View RegistryView = cmWindowsRegistry::View::Target;
  112. std::vector<std::string> SearchPathSuffixes;
  113. std::map<PathGroup, std::vector<PathLabel>> PathGroupLabelMap;
  114. std::vector<PathGroup> PathGroupOrder;
  115. std::map<std::string, PathLabel> PathLabelStringMap;
  116. std::map<PathLabel, cmSearchPath> LabeledPaths;
  117. std::vector<std::string> SearchPaths;
  118. std::set<cmSearchPath::PathWithPrefix> SearchPathsEmitted;
  119. bool SearchFrameworkFirst;
  120. bool SearchFrameworkOnly;
  121. bool SearchFrameworkLast;
  122. bool SearchAppBundleFirst;
  123. bool SearchAppBundleOnly;
  124. bool SearchAppBundleLast;
  125. cmMakefile* Makefile;
  126. cmExecutionStatus& Status;
  127. };