cmFindCommon.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PATH variables. */
  71. void GetIgnoredPaths(std::vector<std::string>& ignore);
  72. void GetIgnoredPaths(std::set<std::string>& ignore);
  73. /** Get ignored paths from CMAKE_[SYSTEM_]IGNORE_PREFIX_PATH variables. */
  74. void GetIgnoredPrefixPaths(std::vector<std::string>& ignore);
  75. void GetIgnoredPrefixPaths(std::set<std::string>& ignore);
  76. /** Compute final search path list (reroot + trailing slash). */
  77. enum class IgnorePaths
  78. {
  79. No,
  80. Yes,
  81. };
  82. void ComputeFinalPaths(IgnorePaths ignorePaths);
  83. /** Compute the current default root path mode. */
  84. void SelectDefaultRootPathMode();
  85. /** Compute the current default bundle/framework search policy. */
  86. void SelectDefaultMacMode();
  87. /** Compute the current default search modes based on global variables. */
  88. void SelectDefaultSearchModes();
  89. /** The `InitialPass` functions of the child classes should set
  90. this->DebugMode to the result of these. */
  91. bool ComputeIfDebugModeWanted();
  92. bool ComputeIfDebugModeWanted(std::string const& var);
  93. // Path arguments prior to path manipulation routines
  94. std::vector<std::string> UserHintsArgs;
  95. std::vector<std::string> UserGuessArgs;
  96. std::string CMakePathName;
  97. RootPathMode FindRootPathMode;
  98. bool CheckCommonArgument(std::string const& arg);
  99. void AddPathSuffix(std::string const& arg);
  100. void DebugMessage(std::string const& msg) const;
  101. bool DebugMode;
  102. bool NoDefaultPath;
  103. bool NoPackageRootPath;
  104. bool NoCMakePath;
  105. bool NoCMakeEnvironmentPath;
  106. bool NoSystemEnvironmentPath;
  107. bool NoCMakeSystemPath;
  108. bool NoCMakeInstallPath;
  109. cmWindowsRegistry::View RegistryView = cmWindowsRegistry::View::Target;
  110. std::vector<std::string> SearchPathSuffixes;
  111. std::map<PathGroup, std::vector<PathLabel>> PathGroupLabelMap;
  112. std::vector<PathGroup> PathGroupOrder;
  113. std::map<std::string, PathLabel> PathLabelStringMap;
  114. std::map<PathLabel, cmSearchPath> LabeledPaths;
  115. std::vector<std::string> SearchPaths;
  116. std::set<cmSearchPath::PathWithPrefix> SearchPathsEmitted;
  117. bool SearchFrameworkFirst;
  118. bool SearchFrameworkOnly;
  119. bool SearchFrameworkLast;
  120. bool SearchAppBundleFirst;
  121. bool SearchAppBundleOnly;
  122. bool SearchAppBundleLast;
  123. cmMakefile* Makefile;
  124. cmExecutionStatus& Status;
  125. };