cmFindPackageCommand.h 5.4 KB

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