cmCPackGenerator.h 11 KB

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