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 <cstddef>
  7. #include <functional>
  8. #include <map>
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. #include "cm_kwiml.h"
  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 UseLib32Paths;
  156. bool UseLib64Paths;
  157. bool UseLibx32Paths;
  158. bool UseRealPath;
  159. bool PolicyScope;
  160. std::string LibraryArchitecture;
  161. std::vector<std::string> Names;
  162. std::vector<std::string> Configs;
  163. std::set<std::string> IgnoredPaths;
  164. /*! the selected sortOrder (None by default)*/
  165. SortOrderType SortOrder;
  166. /*! the selected sortDirection (Asc by default)*/
  167. SortDirectionType SortDirection;
  168. struct ConfigFileInfo
  169. {
  170. std::string filename;
  171. std::string version;
  172. bool operator<(ConfigFileInfo const& rhs) const
  173. {
  174. return this->filename < rhs.filename;
  175. }
  176. bool operator==(ConfigFileInfo const& rhs) const
  177. {
  178. return this->filename == rhs.filename;
  179. }
  180. bool operator!=(ConfigFileInfo const& rhs) const
  181. {
  182. return !(*this == rhs);
  183. }
  184. };
  185. std::vector<ConfigFileInfo> ConsideredConfigs;
  186. friend struct std::hash<ConfigFileInfo>;
  187. };
  188. namespace std {
  189. template <>
  190. struct hash<cmFindPackageCommand::ConfigFileInfo>
  191. {
  192. using argument_type = cmFindPackageCommand::ConfigFileInfo;
  193. using result_type = size_t;
  194. result_type operator()(argument_type const& s) const noexcept
  195. {
  196. result_type const h(std::hash<std::string>{}(s.filename));
  197. return h;
  198. }
  199. };
  200. }
  201. bool cmFindPackage(std::vector<std::string> const& args,
  202. cmExecutionStatus& status);
  203. #endif