cmCPackGenerator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 "cmSystemTools.h"
  14. #include <map>
  15. #include <vector>
  16. #include "cmCPackComponentGroup.h" // cmCPackComponent and friends
  17. // Forward declarations are insufficient since we use them in
  18. // std::map data members below...
  19. #define cmCPackTypeMacro(class, superclass) \
  20. cmTypeMacro(class, superclass); \
  21. static cmCPackGenerator* CreateGenerator() { return new class; }
  22. #define cmCPackLogger(logType, msg) \
  23. do { \
  24. cmOStringStream cmCPackLog_msg; \
  25. cmCPackLog_msg << msg; \
  26. this->Logger->Log(logType, __FILE__, __LINE__,\
  27. cmCPackLog_msg.str().c_str());\
  28. } while ( 0 )
  29. #ifdef cerr
  30. # undef cerr
  31. #endif
  32. #define cerr no_cerr_use_cmCPack_Log
  33. #ifdef cout
  34. # undef cout
  35. #endif
  36. #define cout no_cout_use_cmCPack_Log
  37. class cmMakefile;
  38. class cmCPackLog;
  39. /** \class cmCPackGenerator
  40. * \brief A superclass of all CPack Generators
  41. *
  42. */
  43. class cmCPackGenerator : public cmObject
  44. {
  45. public:
  46. cmTypeMacro(cmCPackGenerator, cmObject);
  47. /**
  48. * If verbose then more information is printed out
  49. */
  50. void SetVerbose(bool val)
  51. { this->GeneratorVerbose = val ?
  52. cmSystemTools::OUTPUT_MERGE : cmSystemTools::OUTPUT_NONE; }
  53. /**
  54. * Returns true if the generator may work on this system.
  55. * Rational:
  56. * Some CPack generator may run on some host and may not on others
  57. * (with the same system) because some tools are missing. If the tool
  58. * is missing then CPack won't activate (in the CPackGeneratorFactory)
  59. * this particular generator.
  60. */
  61. static bool CanGenerate() { return true; }
  62. /**
  63. * Do the actual whole package processing.
  64. * Subclass may redefine it but its usually enough
  65. * to redefine @ref PackageFiles, because in fact
  66. * this method do call:
  67. * - PrepareName
  68. * - clean-up temp dirs
  69. * - InstallProject (with the appropriate method)
  70. * - prepare list of files and/or components to be package
  71. * - PackageFiles
  72. * - Copy produced packages at the expected place
  73. * @return 0 if error.
  74. */
  75. virtual int DoPackage();
  76. /**
  77. * Initialize generator
  78. */
  79. int Initialize(const char* name, cmMakefile* mf);
  80. /**
  81. * Construct generator
  82. */
  83. cmCPackGenerator();
  84. virtual ~cmCPackGenerator();
  85. //! Set and get the options
  86. void SetOption(const char* op, const char* value);
  87. void SetOptionIfNotSet(const char* op, const char* value);
  88. const char* GetOption(const char* op) const;
  89. bool IsSet(const char* name) const;
  90. bool IsOn(const char* name) const;
  91. //! Set the logger
  92. void SetLogger(cmCPackLog* log) { this->Logger = log; }
  93. //! Display verbose information via logger
  94. void DisplayVerboseOutput(const char* msg, float progress);
  95. bool ReadListFile(const char* moduleName);
  96. protected:
  97. /**
  98. * Prepare common used names by inspecting
  99. * several CPACK_xxx var values.
  100. */
  101. int PrepareNames();
  102. /**
  103. * Install the project using appropriate method.
  104. */
  105. int InstallProject();
  106. int CleanTemporaryDirectory();
  107. virtual const char* GetOutputExtension() { return ".cpack"; }
  108. virtual const char* GetOutputPostfix() { return 0; }
  109. /**
  110. * Prepare requested grouping kind from CPACK_xxx vars
  111. * CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE
  112. * CPACK_COMPONENTS_IGNORE_GROUPS
  113. * or
  114. * CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP
  115. * @return 1 on success 0 on failure.
  116. */
  117. virtual int PrepareGroupingKind();
  118. /**
  119. * Some CPack generators may prefer to have
  120. * CPack install all components belonging to the same
  121. * [component] group to be install in the same directory.
  122. * The default behavior is to install each component in
  123. * a separate directory.
  124. * @param[in] componentName the name of the component to be installed
  125. * @return the name suffix the generator wants for the specified component
  126. * default is "componentName"
  127. */
  128. virtual std::string GetComponentInstallDirNameSuffix(
  129. const std::string& componentName);
  130. /**
  131. * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME
  132. * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if
  133. * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON.
  134. * @param[in] initialPackageFileName the initial package name to be mangled
  135. * @param[in] groupOrComponentName the name of the group/component
  136. * @param[in] isGroupName true if previous name refers to a group,
  137. * false otherwise
  138. */
  139. virtual std::string GetComponentPackageFileName(
  140. const std::string& initialPackageFileName,
  141. const std::string& groupOrComponentName,
  142. bool isGroupName);
  143. /**
  144. * Package the list of files and/or components which
  145. * has been prepared by the beginning of DoPackage.
  146. * @pre the @ref toplevel has been filled-in
  147. * @pre the list of file @ref files has been populated
  148. * @pre packageFileNames contains at least 1 entry
  149. * @post packageFileNames may have been updated and contains
  150. * the list of packages generated by the specific generator.
  151. */
  152. virtual int PackageFiles();
  153. virtual const char* GetInstallPath();
  154. virtual const char* GetPackagingInstallPrefix();
  155. virtual std::string FindTemplate(const char* name);
  156. virtual bool ConfigureFile(const char* inName, const char* outName,
  157. bool copyOnly = false);
  158. virtual bool ConfigureString(const std::string& input, std::string& output);
  159. virtual int InitializeInternal();
  160. //! Run install commands if specified
  161. virtual int InstallProjectViaInstallCommands(
  162. bool setDestDir, const char* tempInstallDirectory);
  163. virtual int InstallProjectViaInstallScript(
  164. bool setDestDir, const char* tempInstallDirectory);
  165. virtual int InstallProjectViaInstalledDirectories(
  166. bool setDestDir, const char* tempInstallDirectory);
  167. virtual int InstallProjectViaInstallCMakeProjects(
  168. bool setDestDir, const char* tempInstallDirectory);
  169. /**
  170. * The various level of support of
  171. * CPACK_SET_DESTDIR used by the generator.
  172. */
  173. enum CPackSetDestdirSupport {
  174. /* the generator works with or without it */
  175. SETDESTDIR_SUPPORTED,
  176. /* the generator works best if automatically handled */
  177. SETDESTDIR_INTERNALLY_SUPPORTED,
  178. /* no official support, use at your own risk */
  179. SETDESTDIR_SHOULD_NOT_BE_USED,
  180. /* officially NOT supported */
  181. SETDESTDIR_UNSUPPORTED
  182. };
  183. /**
  184. * Does the CPack generator support CPACK_SET_DESTDIR?
  185. * The default legacy value is 'SETDESTDIR_SUPPORTED' generator
  186. * have to override it in order change this.
  187. * @return CPackSetDestdirSupport
  188. */
  189. virtual enum CPackSetDestdirSupport SupportsSetDestdir() const;
  190. /**
  191. * Does the CPack generator support absolute path
  192. * in INSTALL DESTINATION?
  193. * The default legacy value is 'true' generator
  194. * have to override it in order change this.
  195. * @return true if supported false otherwise
  196. */
  197. virtual bool SupportsAbsoluteDestination() const;
  198. /**
  199. * Does the CPack generator support component installation?.
  200. * Some Generators requires the user to set
  201. * CPACK_<GENNAME>_COMPONENT_INSTALL in order to make this
  202. * method return true.
  203. * @return true if supported, false otherwise
  204. */
  205. virtual bool SupportsComponentInstallation() const;
  206. /**
  207. * Does the currently running generator want a component installation.
  208. * The generator may support component installation but he may
  209. * be requiring monolithic install using CPACK_MONOLITHIC_INSTALL.
  210. * @return true if component installation is supported and wanted.
  211. */
  212. virtual bool WantsComponentInstallation() const;
  213. virtual cmCPackInstallationType* GetInstallationType(const char *projectName,
  214. const char* name);
  215. virtual cmCPackComponent* GetComponent(const char *projectName,
  216. const char* name);
  217. virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName,
  218. const char* name);
  219. cmSystemTools::OutputOption GeneratorVerbose;
  220. std::string Name;
  221. std::string InstallPath;
  222. /**
  223. * The list of package file names.
  224. * At beginning of DoPackage the (generic) generator will populate
  225. * the list of desired package file names then it will
  226. * call the redefined method PackageFiles which is may
  227. * either use this set of names (usually on entry there should be
  228. * only a single name) or update the vector with the list
  229. * of created package file names.
  230. */
  231. std::vector<std::string> packageFileNames;
  232. /**
  233. * The directory where all the files to be packaged reside.
  234. * If the installer support components there will be one
  235. * sub-directory for each component. In those directories
  236. * one will find the file belonging to the specified component.
  237. */
  238. std::string toplevel;
  239. /**
  240. * The complete list of files to be packaged.
  241. * This list will be populated by DoPackage before
  242. * PackageFiles is called.
  243. */
  244. std::vector<std::string> files;
  245. std::map<std::string, cmCPackInstallationType> InstallationTypes;
  246. /**
  247. * The set of components.
  248. * If component installation is supported then this map
  249. * contains the component specified in CPACK_COMPONENTS_ALL
  250. */
  251. std::map<std::string, cmCPackComponent> Components;
  252. std::map<std::string, cmCPackComponentGroup> ComponentGroups;
  253. /**
  254. * If components are enabled, this enum represents the different
  255. * ways of mapping components to package files.
  256. */
  257. enum ComponentPackageMethod
  258. {
  259. /* one package for all components */
  260. ONE_PACKAGE,
  261. /* one package for each component */
  262. ONE_PACKAGE_PER_COMPONENT,
  263. /* one package for each group,
  264. * with left over components in their own package */
  265. ONE_PACKAGE_PER_GROUP,
  266. UNKNOWN_COMPONENT_PACKAGE_METHOD
  267. };
  268. /**
  269. * The component package method
  270. * The default is ONE_PACKAGE_PER_GROUP,
  271. * and generators may override the default
  272. * before PrepareGroupingKind() is called.
  273. */
  274. ComponentPackageMethod componentPackageMethod;
  275. cmCPackLog* Logger;
  276. private:
  277. cmMakefile* MakefileMap;
  278. };
  279. #endif