cmCPackGenerator.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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_IN_ONE_PACKAGE
  102. * CPACK_COMPONENTS_IGNORE_GROUPS
  103. * or
  104. * CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP
  105. * @return 1 on success 0 on failure.
  106. */
  107. virtual int PrepareGroupingKind();
  108. /**
  109. * Some CPack generators may prefer to have
  110. * CPack install all components belonging to the same
  111. * [component] group to be install in the same directory.
  112. * The default behavior is to install each component in
  113. * a separate directory.
  114. * @param[in] componentName the name of the component to be installed
  115. * @return the name suffix the generator wants for the specified component
  116. * default is "componentName"
  117. */
  118. virtual std::string GetComponentInstallDirNameSuffix(
  119. const std::string& componentName);
  120. /**
  121. * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME
  122. * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if
  123. * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON.
  124. * @param[in] initialPackageFileName
  125. * @param[in] groupOrComponentName
  126. * @param[in] isGroupName
  127. */
  128. virtual std::string GetComponentPackageFileName(
  129. const std::string& initialPackageFileName,
  130. const std::string& groupOrComponentName,
  131. bool isGroupName);
  132. /**
  133. * Package the list of files and/or components which
  134. * has been prepared by the beginning of DoPackage.
  135. * @pre @ref toplevel has been filled-in
  136. * @pre the list of file @ref files has been populated
  137. * @pre packageFileNames contains at least 1 entry
  138. * @post packageFileNames may have been updated and contains
  139. * the list of packages generated by the specific generator.
  140. */
  141. virtual int PackageFiles();
  142. virtual const char* GetInstallPath();
  143. virtual const char* GetPackagingInstallPrefix();
  144. virtual std::string FindTemplate(const char* name);
  145. virtual bool ConfigureFile(const char* inName, const char* outName,
  146. bool copyOnly = false);
  147. virtual bool ConfigureString(const std::string& input, std::string& output);
  148. virtual int InitializeInternal();
  149. //! Run install commands if specified
  150. virtual int InstallProjectViaInstallCommands(
  151. bool setDestDir, const char* tempInstallDirectory);
  152. virtual int InstallProjectViaInstallScript(
  153. bool setDestDir, const char* tempInstallDirectory);
  154. virtual int InstallProjectViaInstalledDirectories(
  155. bool setDestDir, const char* tempInstallDirectory);
  156. virtual int InstallProjectViaInstallCMakeProjects(
  157. bool setDestDir, const char* tempInstallDirectory);
  158. virtual bool SupportsComponentInstallation() const;
  159. virtual cmCPackInstallationType* GetInstallationType(const char *projectName,
  160. const char* name);
  161. virtual cmCPackComponent* GetComponent(const char *projectName,
  162. const char* name);
  163. virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName,
  164. const char* name);
  165. bool GeneratorVerbose;
  166. std::string Name;
  167. std::string InstallPath;
  168. /**
  169. * The list of package file names.
  170. * At beginning of DoPackage the (generic) generator will populate
  171. * the list of desired package file names then it will
  172. * call the redefined method PackageFiles which is may
  173. * either use this set of names (usually on entry there should be
  174. * only a single name) or update the vector with the list
  175. * of created package file names.
  176. */
  177. std::vector<std::string> packageFileNames;
  178. /**
  179. * The directory where all the files to be packaged reside.
  180. * If the installer support components there will be one
  181. * sub-directory for each component. In those directories
  182. * one will find the file belonging to the specified component.
  183. */
  184. std::string toplevel;
  185. /**
  186. * The complete list of files to be packaged.
  187. * This list will be populated by DoPackage before
  188. * PackageFiles is called.
  189. */
  190. std::vector<std::string> files;
  191. std::string CPackSelf;
  192. std::string CMakeSelf;
  193. std::string CMakeRoot;
  194. std::map<std::string, cmCPackInstallationType> InstallationTypes;
  195. /**
  196. * The set of components.
  197. * If component installation is supported then this map
  198. * contains the component specified in CPACK_COMPONENTS_ALL
  199. */
  200. std::map<std::string, cmCPackComponent> Components;
  201. std::map<std::string, cmCPackComponentGroup> ComponentGroups;
  202. /**
  203. * If components are enabled, this enum represents the different
  204. * ways of mapping components to package files.
  205. */
  206. enum ComponentPackageMethod
  207. {
  208. /* one package for all components */
  209. ONE_PACKAGE,
  210. /* one package for each component */
  211. ONE_PACKAGE_PER_COMPONENT,
  212. /* one package for each group, with left over components in their own package */
  213. ONE_PACKAGE_PER_GROUP,
  214. UNKNOWN_COMPONENT_PACKAGE_METHOD
  215. };
  216. /**
  217. * The component package method
  218. * The default is ONE_PACKAGE_PER_GROUP, and generators may override the default
  219. * before PrepareGroupingKind() is called.
  220. */
  221. ComponentPackageMethod componentPackageMethod;
  222. cmCPackLog* Logger;
  223. private:
  224. cmMakefile* MakefileMap;
  225. };
  226. #endif