cmCPackGenerator.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmCPackGenerator_h
  11. #define cmCPackGenerator_h
  12. #include "cmObject.h"
  13. #include <map>
  14. #include <vector>
  15. #include "cmCPackComponentGroup.h" // cmCPackComponent and friends
  16. // Forward declarations are insufficient since we use them in
  17. // std::map data members below...
  18. #define cmCPackTypeMacro(class, superclass) \
  19. cmTypeMacro(class, superclass); \
  20. static cmCPackGenerator* CreateGenerator() { return new class; }
  21. #define cmCPackLogger(logType, msg) \
  22. do { \
  23. cmOStringStream cmCPackLog_msg; \
  24. cmCPackLog_msg << msg; \
  25. this->Logger->Log(logType, __FILE__, __LINE__,\
  26. cmCPackLog_msg.str().c_str());\
  27. } while ( 0 )
  28. #ifdef cerr
  29. # undef cerr
  30. #endif
  31. #define cerr no_cerr_use_cmCPack_Log
  32. #ifdef cout
  33. # undef cout
  34. #endif
  35. #define cout no_cout_use_cmCPack_Log
  36. class cmMakefile;
  37. class cmCPackLog;
  38. /** \class cmCPackGenerator
  39. * \brief A superclass of all CPack Generators
  40. *
  41. */
  42. class cmCPackGenerator : public cmObject
  43. {
  44. public:
  45. cmTypeMacro(cmCPackGenerator, cmObject);
  46. /**
  47. * If verbose then more information is printed out
  48. */
  49. void SetVerbose(bool val) { this->GeneratorVerbose = val; }
  50. /**
  51. * Do the actual whole package processing.
  52. * Subclass may redefine it but its usually enough
  53. * to redefine @ref PackageFiles, because in fact
  54. * this method do call:
  55. * - PrepareName
  56. * - clean-up temp dirs
  57. * - InstallProject (with the appropriate method)
  58. * - prepare list of files and/or components to be package
  59. * - PackageFiles
  60. * - Copy produced packages at the expected place
  61. * @return 0 if error.
  62. */
  63. virtual int DoPackage();
  64. /**
  65. * Initialize generator
  66. */
  67. int Initialize(const char* name, cmMakefile* mf);
  68. /**
  69. * Construct generator
  70. */
  71. cmCPackGenerator();
  72. virtual ~cmCPackGenerator();
  73. //! Set and get the options
  74. void SetOption(const char* op, const char* value);
  75. void SetOptionIfNotSet(const char* op, const char* value);
  76. const char* GetOption(const char* op) const;
  77. bool IsSet(const char* name) const;
  78. bool IsOn(const char* name) const;
  79. //! Set all the variables
  80. int SetCMakeRoot();
  81. //! Set the logger
  82. void SetLogger(cmCPackLog* log) { this->Logger = log; }
  83. //! Display verbose information via logger
  84. void DisplayVerboseOutput(const char* msg, float progress);
  85. bool ReadListFile(const char* moduleName);
  86. protected:
  87. /**
  88. * Prepare common used names by inspecting
  89. * several CPACK_xxx var values.
  90. */
  91. int PrepareNames();
  92. /**
  93. * Install the project using appropriate method.
  94. */
  95. int InstallProject();
  96. int CleanTemporaryDirectory();
  97. virtual const char* GetOutputExtension() { return ".cpack"; }
  98. virtual const char* GetOutputPostfix() { return 0; }
  99. /**
  100. * Prepare requested grouping kind from CPACK_xxx vars
  101. * CPACK_COMPONENTS_ALL_GROUPS_IN_ONE_PACKAGE
  102. * CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE
  103. * CPACK_COMPONENTS_IGNORE_GROUPS
  104. * or
  105. * CPACK_COMPONENTS_GROUPING
  106. * @return 1 on success 0 on failure.
  107. */
  108. virtual int PrepareGroupingKind();
  109. /**
  110. * Package the list of files and/or components which
  111. * has been prepared by the beginning of DoPackage.
  112. * @pre @ref toplevel has been filled-in
  113. * @pre the list of file @ref files has been populated
  114. * @pre packageFileNames contains at least 1 entry
  115. * @post packageFileNames may have been updated and contains
  116. * the list of packages generated by the specific generator.
  117. */
  118. virtual int PackageFiles();
  119. virtual const char* GetInstallPath();
  120. virtual const char* GetPackagingInstallPrefix();
  121. virtual std::string FindTemplate(const char* name);
  122. virtual bool ConfigureFile(const char* inName, const char* outName,
  123. bool copyOnly = false);
  124. virtual bool ConfigureString(const std::string& input, std::string& output);
  125. virtual int InitializeInternal();
  126. //! Run install commands if specified
  127. virtual int InstallProjectViaInstallCommands(
  128. bool setDestDir, const char* tempInstallDirectory);
  129. virtual int InstallProjectViaInstallScript(
  130. bool setDestDir, const char* tempInstallDirectory);
  131. virtual int InstallProjectViaInstalledDirectories(
  132. bool setDestDir, const char* tempInstallDirectory);
  133. virtual int InstallProjectViaInstallCMakeProjects(
  134. bool setDestDir, const char* tempInstallDirectory);
  135. virtual bool SupportsComponentInstallation() const;
  136. virtual cmCPackInstallationType* GetInstallationType(const char *projectName,
  137. const char* name);
  138. virtual cmCPackComponent* GetComponent(const char *projectName,
  139. const char* name);
  140. virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName,
  141. const char* name);
  142. bool GeneratorVerbose;
  143. std::string Name;
  144. std::string InstallPath;
  145. /**
  146. * The list of package file names.
  147. * At beginning of DoPackage the (generic) generator will populate
  148. * the list of desired package file names then it will
  149. * call the redefined method PackageFiles which is may
  150. * either use this set of names (usually on entry there should be
  151. * only a single name) or update the vector with the list
  152. * of created package file names.
  153. */
  154. std::vector<std::string> packageFileNames;
  155. /**
  156. * The directory where all the files to be packaged reside.
  157. * If the installer support components there will be one
  158. * sub-directory for each component. In those directories
  159. * one will find the file belonging to the specified component.
  160. */
  161. std::string toplevel;
  162. /**
  163. * The complete list of files to be packaged.
  164. * This list will be populated by DoPackage before
  165. * PackageFiles is called.
  166. */
  167. std::vector<std::string> files;
  168. std::string CPackSelf;
  169. std::string CMakeSelf;
  170. std::string CMakeRoot;
  171. std::map<std::string, cmCPackInstallationType> InstallationTypes;
  172. /**
  173. * The set of components.
  174. * If component installation is supported then this map
  175. * contains the component specified in CPACK_COMPONENTS_ALL
  176. */
  177. std::map<std::string, cmCPackComponent> Components;
  178. std::map<std::string, cmCPackComponentGroup> ComponentGroups;
  179. /**
  180. * If true All component groups will be put in a single package.
  181. */
  182. bool allGroupInOne;
  183. /**
  184. * If true All component will be put in a single package.
  185. */
  186. bool allComponentInOne;
  187. /**
  188. * If true component grouping will be ignored.
  189. * You will still get 1 package for each component unless
  190. * allComponentInOne is true.
  191. */
  192. bool ignoreComponentGroup;
  193. cmCPackLog* Logger;
  194. private:
  195. cmMakefile* MakefileMap;
  196. };
  197. #endif