cmFindPackageCommand.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 <map>
  9. #include <set>
  10. #include <string>
  11. #include <vector>
  12. // IWYU insists we should forward-declare instead of including <functional>,
  13. // but we cannot forward-declare reliably because some C++ standard libraries
  14. // put the template in an inline namespace.
  15. #ifdef CMAKE_IWYU
  16. /* clang-format off */
  17. namespace std {
  18. template <class T> struct hash;
  19. }
  20. /* clang-format on */
  21. #else
  22. #include <functional>
  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::string Name;
  135. std::string Variable;
  136. std::string Version;
  137. unsigned int VersionMajor;
  138. unsigned int VersionMinor;
  139. unsigned int VersionPatch;
  140. unsigned int VersionTweak;
  141. unsigned int VersionCount;
  142. bool VersionExact;
  143. std::string FileFound;
  144. std::string VersionFound;
  145. unsigned int VersionFoundMajor;
  146. unsigned int VersionFoundMinor;
  147. unsigned int VersionFoundPatch;
  148. unsigned int VersionFoundTweak;
  149. unsigned int VersionFoundCount;
  150. KWIML_INT_uint64_t RequiredCMakeVersion;
  151. bool Quiet;
  152. bool Required;
  153. bool UseConfigFiles;
  154. bool UseFindModules;
  155. bool NoUserRegistry;
  156. bool NoSystemRegistry;
  157. bool DebugMode;
  158. bool UseLib32Paths;
  159. bool UseLib64Paths;
  160. bool UseLibx32Paths;
  161. bool PolicyScope;
  162. std::string LibraryArchitecture;
  163. std::vector<std::string> Names;
  164. std::vector<std::string> Configs;
  165. std::set<std::string> IgnoredPaths;
  166. /*! the selected sortOrder (None by default)*/
  167. SortOrderType SortOrder;
  168. /*! the selected sortDirection (Asc by default)*/
  169. SortDirectionType SortDirection;
  170. struct ConfigFileInfo
  171. {
  172. std::string filename;
  173. std::string version;
  174. bool operator<(ConfigFileInfo const& rhs) const
  175. {
  176. return this->filename < rhs.filename;
  177. }
  178. bool operator==(ConfigFileInfo const& rhs) const
  179. {
  180. return this->filename == rhs.filename;
  181. }
  182. bool operator!=(ConfigFileInfo const& rhs) const
  183. {
  184. return !(*this == rhs);
  185. }
  186. };
  187. std::vector<ConfigFileInfo> ConsideredConfigs;
  188. friend struct std::hash<ConfigFileInfo>;
  189. };
  190. namespace std {
  191. template <>
  192. struct hash<cmFindPackageCommand::ConfigFileInfo>
  193. {
  194. typedef cmFindPackageCommand::ConfigFileInfo argument_type;
  195. typedef size_t result_type;
  196. result_type operator()(argument_type const& s) const noexcept
  197. {
  198. result_type const h(std::hash<std::string>{}(s.filename));
  199. return h;
  200. }
  201. };
  202. }
  203. #endif