cmCPackGenerator.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 std::string& op, const char* value);
  87. void SetOptionIfNotSet(const std::string& op, const char* value);
  88. const char* GetOption(const std::string& op) const;
  89. std::vector<std::string> GetOptions() const;
  90. bool IsSet(const std::string& name) const;
  91. bool IsOn(const std::string& name) const;
  92. //! Set the logger
  93. void SetLogger(cmCPackLog* log) { this->Logger = log; }
  94. //! Display verbose information via logger
  95. void DisplayVerboseOutput(const char* msg, float progress);
  96. bool ReadListFile(const char* moduleName);
  97. protected:
  98. /**
  99. * Prepare common used names by inspecting
  100. * several CPACK_xxx var values.
  101. */
  102. int PrepareNames();
  103. /**
  104. * Install the project using appropriate method.
  105. */
  106. int InstallProject();
  107. int CleanTemporaryDirectory();
  108. virtual const char* GetOutputExtension() { return ".cpack"; }
  109. virtual const char* GetOutputPostfix() { return 0; }
  110. /**
  111. * Prepare requested grouping kind from CPACK_xxx vars
  112. * CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE
  113. * CPACK_COMPONENTS_IGNORE_GROUPS
  114. * or
  115. * CPACK_COMPONENTS_ONE_PACKAGE_PER_GROUP
  116. * @return 1 on success 0 on failure.
  117. */
  118. virtual int PrepareGroupingKind();
  119. /**
  120. * Some CPack generators may prefer to have
  121. * CPack install all components belonging to the same
  122. * [component] group to be install in the same directory.
  123. * The default behavior is to install each component in
  124. * a separate directory.
  125. * @param[in] componentName the name of the component to be installed
  126. * @return the name suffix the generator wants for the specified component
  127. * default is "componentName"
  128. */
  129. virtual std::string GetComponentInstallDirNameSuffix(
  130. const std::string& componentName);
  131. /**
  132. * CPack specific generator may mangle CPACK_PACKAGE_FILE_NAME
  133. * with CPACK_COMPONENT_xxxx_<NAME>_DISPLAY_NAME if
  134. * CPACK_<GEN>_USE_DISPLAY_NAME_IN_FILENAME is ON.
  135. * @param[in] initialPackageFileName the initial package name to be mangled
  136. * @param[in] groupOrComponentName the name of the group/component
  137. * @param[in] isGroupName true if previous name refers to a group,
  138. * false otherwise
  139. */
  140. virtual std::string GetComponentPackageFileName(
  141. const std::string& initialPackageFileName,
  142. const std::string& groupOrComponentName,
  143. bool isGroupName);
  144. /**
  145. * Package the list of files and/or components which
  146. * has been prepared by the beginning of DoPackage.
  147. * @pre the @ref toplevel has been filled-in
  148. * @pre the list of file @ref files has been populated
  149. * @pre packageFileNames contains at least 1 entry
  150. * @post packageFileNames may have been updated and contains
  151. * the list of packages generated by the specific generator.
  152. */
  153. virtual int PackageFiles();
  154. virtual const char* GetInstallPath();
  155. virtual const char* GetPackagingInstallPrefix();
  156. virtual std::string FindTemplate(const char* name);
  157. virtual bool ConfigureFile(const char* inName, const char* outName,
  158. bool copyOnly = false);
  159. virtual bool ConfigureString(const std::string& input, std::string& output);
  160. virtual int InitializeInternal();
  161. //! Run install commands if specified
  162. virtual int InstallProjectViaInstallCommands(
  163. bool setDestDir, const std::string& tempInstallDirectory);
  164. virtual int InstallProjectViaInstallScript(
  165. bool setDestDir, const std::string& tempInstallDirectory);
  166. virtual int InstallProjectViaInstalledDirectories(
  167. bool setDestDir, const std::string& tempInstallDirectory);
  168. virtual int InstallProjectViaInstallCMakeProjects(
  169. bool setDestDir, const std::string& tempInstallDirectory);
  170. /**
  171. * The various level of support of
  172. * CPACK_SET_DESTDIR used by the generator.
  173. */
  174. enum CPackSetDestdirSupport {
  175. /* the generator works with or without it */
  176. SETDESTDIR_SUPPORTED,
  177. /* the generator works best if automatically handled */
  178. SETDESTDIR_INTERNALLY_SUPPORTED,
  179. /* no official support, use at your own risk */
  180. SETDESTDIR_SHOULD_NOT_BE_USED,
  181. /* officially NOT supported */
  182. SETDESTDIR_UNSUPPORTED
  183. };
  184. /**
  185. * Does the CPack generator support CPACK_SET_DESTDIR?
  186. * The default legacy value is 'SETDESTDIR_SUPPORTED' generator
  187. * have to override it in order change this.
  188. * @return CPackSetDestdirSupport
  189. */
  190. virtual enum CPackSetDestdirSupport SupportsSetDestdir() const;
  191. /**
  192. * Does the CPack generator support absolute path
  193. * in INSTALL DESTINATION?
  194. * The default legacy value is 'true' generator
  195. * have to override it in order change this.
  196. * @return true if supported false otherwise
  197. */
  198. virtual bool SupportsAbsoluteDestination() const;
  199. /**
  200. * Does the CPack generator support component installation?.
  201. * Some Generators requires the user to set
  202. * CPACK_<GENNAME>_COMPONENT_INSTALL in order to make this
  203. * method return true.
  204. * @return true if supported, false otherwise
  205. */
  206. virtual bool SupportsComponentInstallation() const;
  207. /**
  208. * Does the currently running generator want a component installation.
  209. * The generator may support component installation but he may
  210. * be requiring monolithic install using CPACK_MONOLITHIC_INSTALL.
  211. * @return true if component installation is supported and wanted.
  212. */
  213. virtual bool WantsComponentInstallation() const;
  214. virtual cmCPackInstallationType* GetInstallationType(
  215. const std::string& projectName,
  216. const std::string& name);
  217. virtual cmCPackComponent* GetComponent(const std::string& projectName,
  218. const std::string& name);
  219. virtual cmCPackComponentGroup* GetComponentGroup(
  220. const std::string& projectName,
  221. const std::string& name);
  222. cmSystemTools::OutputOption GeneratorVerbose;
  223. std::string Name;
  224. std::string InstallPath;
  225. /**
  226. * The list of package file names.
  227. * At beginning of DoPackage the (generic) generator will populate
  228. * the list of desired package file names then it will
  229. * call the redefined method PackageFiles which is may
  230. * either use this set of names (usually on entry there should be
  231. * only a single name) or update the vector with the list
  232. * of created package file names.
  233. */
  234. std::vector<std::string> packageFileNames;
  235. /**
  236. * The directory where all the files to be packaged reside.
  237. * If the installer support components there will be one
  238. * sub-directory for each component. In those directories
  239. * one will find the file belonging to the specified component.
  240. */
  241. std::string toplevel;
  242. /**
  243. * The complete list of files to be packaged.
  244. * This list will be populated by DoPackage before
  245. * PackageFiles is called.
  246. */
  247. std::vector<std::string> files;
  248. std::map<std::string, cmCPackInstallationType> InstallationTypes;
  249. /**
  250. * The set of components.
  251. * If component installation is supported then this map
  252. * contains the component specified in CPACK_COMPONENTS_ALL
  253. */
  254. std::map<std::string, cmCPackComponent> Components;
  255. std::map<std::string, cmCPackComponentGroup> ComponentGroups;
  256. /**
  257. * If components are enabled, this enum represents the different
  258. * ways of mapping components to package files.
  259. */
  260. enum ComponentPackageMethod
  261. {
  262. /* one package for all components */
  263. ONE_PACKAGE,
  264. /* one package for each component */
  265. ONE_PACKAGE_PER_COMPONENT,
  266. /* one package for each group,
  267. * with left over components in their own package */
  268. ONE_PACKAGE_PER_GROUP,
  269. UNKNOWN_COMPONENT_PACKAGE_METHOD
  270. };
  271. /**
  272. * The component package method
  273. * The default is ONE_PACKAGE_PER_GROUP,
  274. * and generators may override the default
  275. * before PrepareGroupingKind() is called.
  276. */
  277. ComponentPackageMethod componentPackageMethod;
  278. cmCPackLog* Logger;
  279. private:
  280. cmMakefile* MakefileMap;
  281. };
  282. #endif