cmFindPackageCommand.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. bool FindPackageUsingModuleMode();
  81. bool FindPackageUsingConfigMode();
  82. // Add additional search path labels and groups not present in the
  83. // parent class
  84. void AppendSearchPathGroups();
  85. void AppendSuccessInformation();
  86. void AppendToFoundProperty(bool found);
  87. void SetModuleVariables(const std::string& components);
  88. bool FindModule(bool& found);
  89. void AddFindDefinition(const std::string& var, const char* val);
  90. void RestoreFindDefinitions();
  91. enum /*class*/ HandlePackageModeType
  92. {
  93. Module,
  94. Config
  95. };
  96. bool HandlePackageMode(HandlePackageModeType type);
  97. bool FindConfig();
  98. bool FindPrefixedConfig();
  99. bool FindFrameworkConfig();
  100. bool FindAppBundleConfig();
  101. enum PolicyScopeRule
  102. {
  103. NoPolicyScope,
  104. DoPolicyScope
  105. };
  106. bool ReadListFile(const std::string& f, PolicyScopeRule psr);
  107. void StoreVersionFound();
  108. void ComputePrefixes();
  109. void FillPrefixesPackageRoot();
  110. void FillPrefixesCMakeEnvironment();
  111. void FillPrefixesCMakeVariable();
  112. void FillPrefixesSystemEnvironment();
  113. void FillPrefixesUserRegistry();
  114. void FillPrefixesSystemRegistry();
  115. void FillPrefixesCMakeSystemVariable();
  116. void FillPrefixesUserGuess();
  117. void FillPrefixesUserHints();
  118. void LoadPackageRegistryDir(std::string const& dir, cmSearchPath& outPaths);
  119. void LoadPackageRegistryWinUser();
  120. void LoadPackageRegistryWinSystem();
  121. void LoadPackageRegistryWin(bool user, unsigned int view,
  122. cmSearchPath& outPaths);
  123. bool CheckPackageRegistryEntry(const std::string& fname,
  124. cmSearchPath& outPaths);
  125. bool SearchDirectory(std::string const& dir);
  126. bool CheckDirectory(std::string const& dir);
  127. bool FindConfigFile(std::string const& dir, std::string& file);
  128. bool CheckVersion(std::string const& config_file);
  129. bool CheckVersionFile(std::string const& version_file,
  130. std::string& result_version);
  131. bool SearchPrefix(std::string const& prefix);
  132. bool SearchFrameworkPrefix(std::string const& prefix_in);
  133. bool SearchAppBundlePrefix(std::string const& prefix_in);
  134. friend class cmFindPackageFileList;
  135. struct OriginalDef
  136. {
  137. bool exists;
  138. std::string value;
  139. };
  140. std::map<std::string, OriginalDef> OriginalDefs;
  141. std::map<std::string, cmPolicies::PolicyID> DeprecatedFindModules;
  142. std::string Name;
  143. std::string Variable;
  144. std::string Version;
  145. unsigned int VersionMajor;
  146. unsigned int VersionMinor;
  147. unsigned int VersionPatch;
  148. unsigned int VersionTweak;
  149. unsigned int VersionCount;
  150. bool VersionExact;
  151. std::string FileFound;
  152. std::string VersionFound;
  153. unsigned int VersionFoundMajor;
  154. unsigned int VersionFoundMinor;
  155. unsigned int VersionFoundPatch;
  156. unsigned int VersionFoundTweak;
  157. unsigned int VersionFoundCount;
  158. KWIML_INT_uint64_t RequiredCMakeVersion;
  159. bool Quiet;
  160. bool Required;
  161. bool UseConfigFiles;
  162. bool UseFindModules;
  163. bool NoUserRegistry;
  164. bool NoSystemRegistry;
  165. bool DebugMode;
  166. bool UseLib32Paths;
  167. bool UseLib64Paths;
  168. bool UseLibx32Paths;
  169. bool UseRealPath;
  170. bool PolicyScope;
  171. std::string LibraryArchitecture;
  172. std::vector<std::string> Names;
  173. std::vector<std::string> Configs;
  174. std::set<std::string> IgnoredPaths;
  175. /*! the selected sortOrder (None by default)*/
  176. SortOrderType SortOrder;
  177. /*! the selected sortDirection (Asc by default)*/
  178. SortDirectionType SortDirection;
  179. struct ConfigFileInfo
  180. {
  181. std::string filename;
  182. std::string version;
  183. bool operator<(ConfigFileInfo const& rhs) const
  184. {
  185. return this->filename < rhs.filename;
  186. }
  187. bool operator==(ConfigFileInfo const& rhs) const
  188. {
  189. return this->filename == rhs.filename;
  190. }
  191. bool operator!=(ConfigFileInfo const& rhs) const
  192. {
  193. return !(*this == rhs);
  194. }
  195. };
  196. std::vector<ConfigFileInfo> ConsideredConfigs;
  197. friend struct std::hash<ConfigFileInfo>;
  198. };
  199. namespace std {
  200. template <>
  201. struct hash<cmFindPackageCommand::ConfigFileInfo>
  202. {
  203. typedef cmFindPackageCommand::ConfigFileInfo argument_type;
  204. typedef size_t result_type;
  205. result_type operator()(argument_type const& s) const noexcept
  206. {
  207. result_type const h(std::hash<std::string>{}(s.filename));
  208. return h;
  209. }
  210. };
  211. }
  212. #endif