cmFindPackageCommand.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * This determines if the command is invoked when in script mode.
  55. */
  56. bool IsScriptable() const CM_OVERRIDE { return true; }
  57. /**
  58. * The name of the command as specified in CMakeList.txt.
  59. */
  60. std::string GetName() const CM_OVERRIDE { return "find_package"; }
  61. private:
  62. class PathLabel : public cmFindCommon::PathLabel
  63. {
  64. protected:
  65. PathLabel();
  66. public:
  67. PathLabel(const std::string& label)
  68. : cmFindCommon::PathLabel(label)
  69. {
  70. }
  71. static PathLabel UserRegistry;
  72. static PathLabel Builds;
  73. static PathLabel SystemRegistry;
  74. };
  75. // Add additional search path labels and groups not present in the
  76. // parent class
  77. void AppendSearchPathGroups();
  78. void AppendSuccessInformation();
  79. void AppendToFoundProperty(bool found);
  80. void SetModuleVariables(const std::string& components);
  81. bool FindModule(bool& found);
  82. void AddFindDefinition(const std::string& var, const char* val);
  83. void RestoreFindDefinitions();
  84. bool HandlePackageMode();
  85. bool FindConfig();
  86. bool FindPrefixedConfig();
  87. bool FindFrameworkConfig();
  88. bool FindAppBundleConfig();
  89. enum PolicyScopeRule
  90. {
  91. NoPolicyScope,
  92. DoPolicyScope
  93. };
  94. bool ReadListFile(const char* f, PolicyScopeRule psr);
  95. void StoreVersionFound();
  96. void ComputePrefixes();
  97. void FillPrefixesCMakeEnvironment();
  98. void FillPrefixesCMakeVariable();
  99. void FillPrefixesSystemEnvironment();
  100. void FillPrefixesUserRegistry();
  101. void FillPrefixesSystemRegistry();
  102. void FillPrefixesCMakeSystemVariable();
  103. void FillPrefixesUserGuess();
  104. void FillPrefixesUserHints();
  105. void LoadPackageRegistryDir(std::string const& dir, cmSearchPath& outPaths);
  106. void LoadPackageRegistryWinUser();
  107. void LoadPackageRegistryWinSystem();
  108. void LoadPackageRegistryWin(bool user, unsigned int view,
  109. cmSearchPath& outPaths);
  110. bool CheckPackageRegistryEntry(const std::string& fname,
  111. cmSearchPath& outPaths);
  112. bool SearchDirectory(std::string const& dir);
  113. bool CheckDirectory(std::string const& dir);
  114. bool FindConfigFile(std::string const& dir, std::string& file);
  115. bool CheckVersion(std::string const& config_file);
  116. bool CheckVersionFile(std::string const& version_file,
  117. std::string& result_version);
  118. bool SearchPrefix(std::string const& prefix);
  119. bool SearchFrameworkPrefix(std::string const& prefix_in);
  120. bool SearchAppBundlePrefix(std::string const& prefix_in);
  121. friend class cmFindPackageFileList;
  122. struct OriginalDef
  123. {
  124. bool exists;
  125. std::string value;
  126. };
  127. std::map<std::string, OriginalDef> OriginalDefs;
  128. std::string Name;
  129. std::string Variable;
  130. std::string Version;
  131. unsigned int VersionMajor;
  132. unsigned int VersionMinor;
  133. unsigned int VersionPatch;
  134. unsigned int VersionTweak;
  135. unsigned int VersionCount;
  136. bool VersionExact;
  137. std::string FileFound;
  138. std::string VersionFound;
  139. unsigned int VersionFoundMajor;
  140. unsigned int VersionFoundMinor;
  141. unsigned int VersionFoundPatch;
  142. unsigned int VersionFoundTweak;
  143. unsigned int VersionFoundCount;
  144. KWIML_INT_uint64_t RequiredCMakeVersion;
  145. bool Quiet;
  146. bool Required;
  147. bool UseConfigFiles;
  148. bool UseFindModules;
  149. bool NoUserRegistry;
  150. bool NoSystemRegistry;
  151. bool DebugMode;
  152. bool UseLib32Paths;
  153. bool UseLib64Paths;
  154. bool PolicyScope;
  155. std::string LibraryArchitecture;
  156. std::vector<std::string> Names;
  157. std::vector<std::string> Configs;
  158. std::set<std::string> IgnoredPaths;
  159. /*! the selected sortOrder (None by default)*/
  160. SortOrderType SortOrder;
  161. /*! the selected sortDirection (Asc by default)*/
  162. SortDirectionType SortDirection;
  163. struct ConfigFileInfo
  164. {
  165. std::string filename;
  166. std::string version;
  167. bool operator<(ConfigFileInfo const& rhs) const
  168. {
  169. return this->filename < rhs.filename;
  170. }
  171. bool operator==(ConfigFileInfo const& rhs) const
  172. {
  173. return this->filename == rhs.filename;
  174. }
  175. bool operator!=(ConfigFileInfo const& rhs) const
  176. {
  177. return !(*this == rhs);
  178. }
  179. };
  180. std::vector<ConfigFileInfo> ConsideredConfigs;
  181. };
  182. #endif