cmFindCommon.h 3.7 KB

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