cmFindPackageCommand.h 6.2 KB

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