cmCPackWIXGenerator.h 4.9 KB

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