cmCPackWIXGenerator.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2012-2015 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 cmCPackWIXGenerator_h
  11. #define cmCPackWIXGenerator_h
  12. #include "cmWIXPatch.h"
  13. #include "cmWIXShortcut.h"
  14. #include <CPack/cmCPackGenerator.h>
  15. #include <string>
  16. #include <map>
  17. class cmWIXSourceWriter;
  18. class cmWIXDirectoriesSourceWriter;
  19. class cmWIXFilesSourceWriter;
  20. class cmWIXFeaturesSourceWriter;
  21. /** \class cmCPackWIXGenerator
  22. * \brief A generator for WIX files
  23. */
  24. class cmCPackWIXGenerator : public cmCPackGenerator
  25. {
  26. public:
  27. cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator);
  28. cmCPackWIXGenerator();
  29. ~cmCPackWIXGenerator();
  30. protected:
  31. virtual int InitializeInternal();
  32. virtual int PackageFiles();
  33. virtual const char* GetOutputExtension()
  34. {
  35. return ".msi";
  36. }
  37. virtual enum CPackSetDestdirSupport SupportsSetDestdir() const
  38. {
  39. return SETDESTDIR_UNSUPPORTED;
  40. }
  41. virtual bool SupportsAbsoluteDestination() const
  42. {
  43. return false;
  44. }
  45. virtual bool SupportsComponentInstallation() const
  46. {
  47. return true;
  48. }
  49. private:
  50. typedef std::map<std::string, std::string> id_map_t;
  51. typedef std::map<std::string, size_t> ambiguity_map_t;
  52. typedef std::set<std::string> extension_set_t;
  53. bool InitializeWiXConfiguration();
  54. bool PackageFilesImpl();
  55. void CreateWiXVariablesIncludeFile();
  56. void CreateWiXPropertiesIncludeFile();
  57. void CreateWiXProductFragmentIncludeFile();
  58. void CopyDefinition(
  59. cmWIXSourceWriter &source, std::string const& name);
  60. void AddDefinition(cmWIXSourceWriter& source,
  61. std::string const& name, std::string const& value);
  62. bool CreateWiXSourceFiles();
  63. std::string GetProgramFilesFolderId() const;
  64. bool GenerateMainSourceFileFromTemplate();
  65. bool CreateFeatureHierarchy(
  66. cmWIXFeaturesSourceWriter& featureDefinitions);
  67. bool AddComponentsToFeature(
  68. std::string const& rootPath,
  69. std::string const& featureId,
  70. cmWIXDirectoriesSourceWriter& directoryDefinitions,
  71. cmWIXFilesSourceWriter& fileDefinitions,
  72. cmWIXFeaturesSourceWriter& featureDefinitions,
  73. cmWIXShortcuts& shortcuts);
  74. bool CreateShortcuts(
  75. std::string const& cpackComponentName,
  76. std::string const& featureId,
  77. cmWIXShortcuts const& shortcuts,
  78. bool emitUninstallShortcut,
  79. cmWIXFilesSourceWriter& fileDefinitions,
  80. cmWIXFeaturesSourceWriter& featureDefinitions);
  81. bool CreateShortcutsOfSpecificType(
  82. cmWIXShortcuts::Type type,
  83. std::string const& cpackComponentName,
  84. std::string const& featureId,
  85. std::string const& idPrefix,
  86. cmWIXShortcuts const& shortcuts,
  87. bool emitUninstallShortcut,
  88. cmWIXFilesSourceWriter& fileDefinitions,
  89. cmWIXFeaturesSourceWriter& featureDefinitions);
  90. void AppendUserSuppliedExtraSources();
  91. void AppendUserSuppliedExtraObjects(std::ostream& stream);
  92. bool CreateLicenseFile();
  93. bool RunWiXCommand(std::string const& command);
  94. bool RunCandleCommand(
  95. std::string const& sourceFile, std::string const& objectFile);
  96. bool RunLightCommand(std::string const& objectFiles);
  97. void AddDirectoryAndFileDefinitons(std::string const& topdir,
  98. std::string const& directoryId,
  99. cmWIXDirectoriesSourceWriter& directoryDefinitions,
  100. cmWIXFilesSourceWriter& fileDefinitions,
  101. cmWIXFeaturesSourceWriter& featureDefinitions,
  102. std::vector<std::string> const& packageExecutables,
  103. std::vector<std::string> const& desktopExecutables,
  104. cmWIXShortcuts& shortcuts);
  105. bool RequireOption(std::string const& name, std::string& value) const;
  106. std::string GetArchitecture() const;
  107. static std::string GenerateGUID();
  108. static std::string QuotePath(std::string const& path);
  109. static std::string GetRightmostExtension(std::string const& filename);
  110. std::string PathToId(std::string const& path);
  111. std::string CreateNewIdForPath(std::string const& path);
  112. static std::string CreateHashedId(
  113. std::string const& path, std::string const& normalizedFilename);
  114. std::string NormalizeComponentForId(
  115. std::string const& component, size_t& replacementCount);
  116. static bool IsLegalIdCharacter(char c);
  117. void CollectExtensions(
  118. std::string const& variableName, extension_set_t& extensions);
  119. void AddCustomFlags(
  120. std::string const& variableName, std::ostream& stream);
  121. std::vector<std::string> WixSources;
  122. id_map_t PathToIdMap;
  123. ambiguity_map_t IdAmbiguityCounter;
  124. extension_set_t CandleExtensions;
  125. extension_set_t LightExtensions;
  126. std::string CPackTopLevel;
  127. cmWIXPatch* Patch;
  128. };
  129. #endif