cmFindPackageCommand.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 <cstddef>
  8. #include <functional>
  9. #include <map>
  10. #include <set>
  11. #include <string>
  12. #include <vector>
  13. #include "cmFindCommon.h"
  14. #include "cmPolicies.h"
  15. // IWYU insists we should forward-declare instead of including <functional>,
  16. // but we cannot forward-declare reliably because some C++ standard libraries
  17. // put the template in an inline namespace.
  18. #ifdef CMAKE_IWYU_FORWARD_STD_HASH
  19. /* clang-format off */
  20. namespace std {
  21. template <class T> struct hash;
  22. }
  23. /* clang-format on */
  24. #endif
  25. class cmExecutionStatus;
  26. class cmSearchPath;
  27. /** \class cmFindPackageCommand
  28. * \brief Load settings from an external project.
  29. *
  30. * cmFindPackageCommand
  31. */
  32. class cmFindPackageCommand : public cmFindCommon
  33. {
  34. public:
  35. /*! A sorting order strategy to be applied to recovered package folders (see
  36. * FIND_PACKAGE_SORT_ORDER)*/
  37. enum /*class*/ SortOrderType
  38. {
  39. None,
  40. Name_order,
  41. Natural
  42. };
  43. /*! A sorting direction to be applied to recovered package folders (see
  44. * FIND_PACKAGE_SORT_DIRECTION)*/
  45. enum /*class*/ SortDirectionType
  46. {
  47. Asc,
  48. Dec
  49. };
  50. /*! sorts a given list of string based on the input sort parameters */
  51. static void Sort(std::vector<std::string>::iterator begin,
  52. std::vector<std::string>::iterator end, SortOrderType order,
  53. SortDirectionType dir);
  54. cmFindPackageCommand(cmExecutionStatus& status);
  55. bool InitialPass(std::vector<std::string> const& args);
  56. private:
  57. class PathLabel : public cmFindCommon::PathLabel
  58. {
  59. protected:
  60. PathLabel();
  61. public:
  62. PathLabel(const std::string& label)
  63. : cmFindCommon::PathLabel(label)
  64. {
  65. }
  66. static PathLabel UserRegistry;
  67. static PathLabel Builds;
  68. static PathLabel SystemRegistry;
  69. };
  70. bool FindPackageUsingModuleMode();
  71. bool FindPackageUsingConfigMode();
  72. // Add additional search path labels and groups not present in the
  73. // parent class
  74. void AppendSearchPathGroups();
  75. void AppendSuccessInformation();
  76. void AppendToFoundProperty(bool found);
  77. void SetModuleVariables(const std::string& components);
  78. bool FindModule(bool& found);
  79. void AddFindDefinition(const std::string& var, const char* val);
  80. void RestoreFindDefinitions();
  81. enum /*class*/ HandlePackageModeType
  82. {
  83. Module,
  84. Config
  85. };
  86. bool HandlePackageMode(HandlePackageModeType type);
  87. bool FindConfig();
  88. bool FindPrefixedConfig();
  89. bool FindFrameworkConfig();
  90. bool FindAppBundleConfig();
  91. enum PolicyScopeRule
  92. {
  93. NoPolicyScope,
  94. DoPolicyScope
  95. };
  96. bool ReadListFile(const std::string& f, PolicyScopeRule psr);
  97. void StoreVersionFound();
  98. void ComputePrefixes();
  99. void FillPrefixesPackageRoot();
  100. void FillPrefixesCMakeEnvironment();
  101. void FillPrefixesCMakeVariable();
  102. void FillPrefixesSystemEnvironment();
  103. void FillPrefixesUserRegistry();
  104. void FillPrefixesSystemRegistry();
  105. void FillPrefixesCMakeSystemVariable();
  106. void FillPrefixesUserGuess();
  107. void FillPrefixesUserHints();
  108. void LoadPackageRegistryDir(std::string const& dir, cmSearchPath& outPaths);
  109. void LoadPackageRegistryWinUser();
  110. void LoadPackageRegistryWinSystem();
  111. void LoadPackageRegistryWin(bool user, unsigned int view,
  112. cmSearchPath& outPaths);
  113. bool CheckPackageRegistryEntry(const std::string& fname,
  114. cmSearchPath& outPaths);
  115. bool SearchDirectory(std::string const& dir);
  116. bool CheckDirectory(std::string const& dir);
  117. bool FindConfigFile(std::string const& dir, std::string& file);
  118. bool CheckVersion(std::string const& config_file);
  119. bool CheckVersionFile(std::string const& version_file,
  120. std::string& result_version);
  121. bool SearchPrefix(std::string const& prefix);
  122. bool SearchFrameworkPrefix(std::string const& prefix_in);
  123. bool SearchAppBundlePrefix(std::string const& prefix_in);
  124. friend class cmFindPackageFileList;
  125. struct OriginalDef
  126. {
  127. bool exists;
  128. std::string value;
  129. };
  130. std::map<std::string, OriginalDef> OriginalDefs;
  131. std::map<std::string, cmPolicies::PolicyID> DeprecatedFindModules;
  132. std::string Name;
  133. std::string Variable;
  134. std::string Version;
  135. unsigned int VersionMajor;
  136. unsigned int VersionMinor;
  137. unsigned int VersionPatch;
  138. unsigned int VersionTweak;
  139. unsigned int VersionCount;
  140. bool VersionExact;
  141. std::string FileFound;
  142. std::string VersionFound;
  143. unsigned int VersionFoundMajor;
  144. unsigned int VersionFoundMinor;
  145. unsigned int VersionFoundPatch;
  146. unsigned int VersionFoundTweak;
  147. unsigned int VersionFoundCount;
  148. KWIML_INT_uint64_t RequiredCMakeVersion;
  149. bool Quiet;
  150. bool Required;
  151. bool UseConfigFiles;
  152. bool UseFindModules;
  153. bool NoUserRegistry;
  154. bool NoSystemRegistry;
  155. bool DebugMode;
  156. bool UseLib32Paths;
  157. bool UseLib64Paths;
  158. bool UseLibx32Paths;
  159. bool UseRealPath;
  160. bool PolicyScope;
  161. std::string LibraryArchitecture;
  162. std::vector<std::string> Names;
  163. std::vector<std::string> Configs;
  164. std::set<std::string> IgnoredPaths;
  165. /*! the selected sortOrder (None by default)*/
  166. SortOrderType SortOrder;
  167. /*! the selected sortDirection (Asc by default)*/
  168. SortDirectionType SortDirection;
  169. struct ConfigFileInfo
  170. {
  171. std::string filename;
  172. std::string version;
  173. bool operator<(ConfigFileInfo const& rhs) const
  174. {
  175. return this->filename < rhs.filename;
  176. }
  177. bool operator==(ConfigFileInfo const& rhs) const
  178. {
  179. return this->filename == rhs.filename;
  180. }
  181. bool operator!=(ConfigFileInfo const& rhs) const
  182. {
  183. return !(*this == rhs);
  184. }
  185. };
  186. std::vector<ConfigFileInfo> ConsideredConfigs;
  187. friend struct std::hash<ConfigFileInfo>;
  188. };
  189. namespace std {
  190. template <>
  191. struct hash<cmFindPackageCommand::ConfigFileInfo>
  192. {
  193. using argument_type = cmFindPackageCommand::ConfigFileInfo;
  194. using result_type = size_t;
  195. result_type operator()(argument_type const& s) const noexcept
  196. {
  197. result_type const h(std::hash<std::string>{}(s.filename));
  198. return h;
  199. }
  200. };
  201. }
  202. bool cmFindPackage(std::vector<std::string> const& args,
  203. cmExecutionStatus& status);
  204. #endif