cmCPackGenerator.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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);
  77. bool IsSet(const char* name) const;
  78. //! Set all the variables
  79. int SetCMakeRoot();
  80. //! Set the logger
  81. void SetLogger(cmCPackLog* log) { this->Logger = log; }
  82. //! Display verbose information via logger
  83. void DisplayVerboseOutput(const char* msg, float progress);
  84. bool ReadListFile(const char* moduleName);
  85. protected:
  86. /**
  87. * Prepare common used names by inspecting
  88. * several CPACK_xxx var values.
  89. */
  90. int PrepareNames();
  91. /**
  92. * Install the project using appropriate method.
  93. */
  94. int InstallProject();
  95. int CleanTemporaryDirectory();
  96. virtual const char* GetOutputExtension() { return ".cpack"; }
  97. virtual const char* GetOutputPostfix() { return 0; }
  98. /**
  99. * Package the list of files and/or components which
  100. * has been prepared by the beginning of DoPackage.
  101. * @pre @ref toplevel has been filled-in
  102. * @pre the list of file @ref files has been populated
  103. * @pre packageFileNames contains at least 1 entry
  104. * @post packageFileNames may have been updated and contains
  105. * the list of packages generated by the specific generator.
  106. */
  107. virtual int PackageFiles();
  108. virtual const char* GetInstallPath();
  109. virtual const char* GetPackagingInstallPrefix();
  110. virtual std::string FindTemplate(const char* name);
  111. virtual bool ConfigureFile(const char* inName, const char* outName,
  112. bool copyOnly = false);
  113. virtual bool ConfigureString(const std::string& input, std::string& output);
  114. virtual int InitializeInternal();
  115. //! Run install commands if specified
  116. virtual int InstallProjectViaInstallCommands(
  117. bool setDestDir, const char* tempInstallDirectory);
  118. virtual int InstallProjectViaInstallScript(
  119. bool setDestDir, const char* tempInstallDirectory);
  120. virtual int InstallProjectViaInstalledDirectories(
  121. bool setDestDir, const char* tempInstallDirectory);
  122. virtual int InstallProjectViaInstallCMakeProjects(
  123. bool setDestDir, const char* tempInstallDirectory);
  124. virtual bool SupportsComponentInstallation() const;
  125. virtual cmCPackInstallationType* GetInstallationType(const char *projectName,
  126. const char* name);
  127. virtual cmCPackComponent* GetComponent(const char *projectName,
  128. const char* name);
  129. virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName,
  130. const char* name);
  131. bool GeneratorVerbose;
  132. std::string Name;
  133. std::string InstallPath;
  134. /**
  135. * The list of package file names.
  136. * At beginning of DoPackage the (generic) generator will populate
  137. * the list of desired package file names then it will
  138. * call the redefined method PackageFiles which is may
  139. * either use this set of names (usually on entry there should be
  140. * only a single name) or update the vector with the list
  141. * of created package file names.
  142. */
  143. std::vector<std::string> packageFileNames;
  144. /**
  145. * The directory where all the files to be packaged reside.
  146. * If the installer support components there will be one
  147. * sub-directory for each component. In those directories
  148. * one will find the file belonging to the specified component.
  149. */
  150. std::string toplevel;
  151. /**
  152. * The complete list of files to be packaged.
  153. * This list will be populated by DoPackage before
  154. * PackageFiles is called.
  155. */
  156. std::vector<std::string> files;
  157. std::string CPackSelf;
  158. std::string CMakeSelf;
  159. std::string CMakeRoot;
  160. std::map<std::string, cmCPackInstallationType> InstallationTypes;
  161. /**
  162. * The set of components.
  163. * If component installation is supported then this map
  164. * contains the component specified in CPACK_COMPONENTS_ALL
  165. */
  166. std::map<std::string, cmCPackComponent> Components;
  167. std::map<std::string, cmCPackComponentGroup> ComponentGroups;
  168. cmCPackLog* Logger;
  169. private:
  170. cmMakefile* MakefileMap;
  171. };
  172. #endif