cmFindPackageCommand.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmFindPackageCommand_h
  4. #define cmFindPackageCommand_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cm_kwiml.h"
  7. #include <map>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include "cmFindCommon.h"
  12. class cmCommand;
  13. class cmExecutionStatus;
  14. class cmSearchPath;
  15. /** \class cmFindPackageCommand
  16. * \brief Load settings from an external project.
  17. *
  18. * cmFindPackageCommand
  19. */
  20. class cmFindPackageCommand : public cmFindCommon
  21. {
  22. public:
  23. /*! A sorting order strategy to be applied to recovered package folders (see
  24. * FIND_PACKAGE_SORT_ORDER)*/
  25. enum /*class*/ SortOrderType
  26. {
  27. None,
  28. Name_order,
  29. Natural
  30. };
  31. /*! A sorting direction to be applied to recovered package folders (see
  32. * FIND_PACKAGE_SORT_DIRECTION)*/
  33. enum /*class*/ SortDirectionType
  34. {
  35. Asc,
  36. Dec
  37. };
  38. /*! sorts a given list of string based on the input sort parameters */
  39. static void Sort(std::vector<std::string>::iterator begin,
  40. std::vector<std::string>::iterator end, SortOrderType order,
  41. SortDirectionType dir);
  42. cmFindPackageCommand();
  43. /**
  44. * This is a virtual constructor for the command.
  45. */
  46. cmCommand* Clone() override { return new cmFindPackageCommand; }
  47. /**
  48. * This is called when the command is first encountered in
  49. * the CMakeLists.txt file.
  50. */
  51. bool InitialPass(std::vector<std::string> const& args,
  52. cmExecutionStatus& status) override;
  53. private:
  54. class PathLabel : public cmFindCommon::PathLabel
  55. {
  56. protected:
  57. PathLabel();
  58. public:
  59. PathLabel(const std::string& label)
  60. : cmFindCommon::PathLabel(label)
  61. {
  62. }
  63. static PathLabel UserRegistry;
  64. static PathLabel Builds;
  65. static PathLabel SystemRegistry;
  66. };
  67. // Add additional search path labels and groups not present in the
  68. // parent class
  69. void AppendSearchPathGroups();
  70. void AppendSuccessInformation();
  71. void AppendToFoundProperty(bool found);
  72. void SetModuleVariables(const std::string& components);
  73. bool FindModule(bool& found);
  74. void AddFindDefinition(const std::string& var, const char* val);
  75. void RestoreFindDefinitions();
  76. bool HandlePackageMode();
  77. bool FindConfig();
  78. bool FindPrefixedConfig();
  79. bool FindFrameworkConfig();
  80. bool FindAppBundleConfig();
  81. enum PolicyScopeRule
  82. {
  83. NoPolicyScope,
  84. DoPolicyScope
  85. };
  86. bool ReadListFile(const char* f, PolicyScopeRule psr);
  87. void StoreVersionFound();
  88. void ComputePrefixes();
  89. void FillPrefixesPackageRoot();
  90. void FillPrefixesCMakeEnvironment();
  91. void FillPrefixesCMakeVariable();
  92. void FillPrefixesSystemEnvironment();
  93. void FillPrefixesUserRegistry();
  94. void FillPrefixesSystemRegistry();
  95. void FillPrefixesCMakeSystemVariable();
  96. void FillPrefixesUserGuess();
  97. void FillPrefixesUserHints();
  98. void LoadPackageRegistryDir(std::string const& dir, cmSearchPath& outPaths);
  99. void LoadPackageRegistryWinUser();
  100. void LoadPackageRegistryWinSystem();
  101. void LoadPackageRegistryWin(bool user, unsigned int view,
  102. cmSearchPath& outPaths);
  103. bool CheckPackageRegistryEntry(const std::string& fname,
  104. cmSearchPath& outPaths);
  105. bool SearchDirectory(std::string const& dir);
  106. bool CheckDirectory(std::string const& dir);
  107. bool FindConfigFile(std::string const& dir, std::string& file);
  108. bool CheckVersion(std::string const& config_file);
  109. bool CheckVersionFile(std::string const& version_file,
  110. std::string& result_version);
  111. bool SearchPrefix(std::string const& prefix);
  112. bool SearchFrameworkPrefix(std::string const& prefix_in);
  113. bool SearchAppBundlePrefix(std::string const& prefix_in);
  114. friend class cmFindPackageFileList;
  115. struct OriginalDef
  116. {
  117. bool exists;
  118. std::string value;
  119. };
  120. std::map<std::string, OriginalDef> OriginalDefs;
  121. std::string Name;
  122. std::string Variable;
  123. std::string Version;
  124. unsigned int VersionMajor;
  125. unsigned int VersionMinor;
  126. unsigned int VersionPatch;
  127. unsigned int VersionTweak;
  128. unsigned int VersionCount;
  129. bool VersionExact;
  130. std::string FileFound;
  131. std::string VersionFound;
  132. unsigned int VersionFoundMajor;
  133. unsigned int VersionFoundMinor;
  134. unsigned int VersionFoundPatch;
  135. unsigned int VersionFoundTweak;
  136. unsigned int VersionFoundCount;
  137. KWIML_INT_uint64_t RequiredCMakeVersion;
  138. bool Quiet;
  139. bool Required;
  140. bool UseConfigFiles;
  141. bool UseFindModules;
  142. bool NoUserRegistry;
  143. bool NoSystemRegistry;
  144. bool DebugMode;
  145. bool UseLib32Paths;
  146. bool UseLib64Paths;
  147. bool UseLibx32Paths;
  148. bool PolicyScope;
  149. std::string LibraryArchitecture;
  150. std::vector<std::string> Names;
  151. std::vector<std::string> Configs;
  152. std::set<std::string> IgnoredPaths;
  153. /*! the selected sortOrder (None by default)*/
  154. SortOrderType SortOrder;
  155. /*! the selected sortDirection (Asc by default)*/
  156. SortDirectionType SortDirection;
  157. struct ConfigFileInfo
  158. {
  159. std::string filename;
  160. std::string version;
  161. bool operator<(ConfigFileInfo const& rhs) const
  162. {
  163. return this->filename < rhs.filename;
  164. }
  165. bool operator==(ConfigFileInfo const& rhs) const
  166. {
  167. return this->filename == rhs.filename;
  168. }
  169. bool operator!=(ConfigFileInfo const& rhs) const
  170. {
  171. return !(*this == rhs);
  172. }
  173. };
  174. std::vector<ConfigFileInfo> ConsideredConfigs;
  175. };
  176. #endif