cmCPackGenerator.h 11 KB

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