summaryrefslogtreecommitdiffstats
path: root/Source/CPack/WiX/cmCPackWIXGenerator.h
blob: 84f68b6239999b161efbccefe88bcceb2711e7ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2012 Kitware, Inc.

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/

#ifndef cmCPackWIXGenerator_h
#define cmCPackWIXGenerator_h

#include <CPack/cmCPackGenerator.h>

#include <string>
#include <map>

struct cmWIXShortcut
{
  std::string textLabel;
  std::string workingDirectoryId;
};

class cmWIXSourceWriter;

/** \class cmCPackWIXGenerator
 * \brief A generator for WIX files
 */
class cmCPackWIXGenerator : public cmCPackGenerator
{
public:
  cmCPackTypeMacro(cmCPackWIXGenerator, cmCPackGenerator);

protected:
  virtual int InitializeInternal();

  virtual int PackageFiles();

  virtual const char* GetOutputExtension()
    {
    return ".msi";
    }

  virtual enum CPackSetDestdirSupport SupportsSetDestdir() const
    {
    return SETDESTDIR_UNSUPPORTED;
    }

  virtual bool SupportsAbsoluteDestination() const
    {
    return false;
    }

  virtual bool SupportsComponentInstallation() const
    {
    return true;
    }

private:
  typedef std::map<std::string, std::string> id_map_t;
  typedef std::map<std::string, size_t> ambiguity_map_t;
  typedef std::map<std::string, cmWIXShortcut> shortcut_map_t;
  typedef std::set<std::string> extension_set_t;

  bool InitializeWiXConfiguration();

  bool PackageFilesImpl();

  bool CreateWiXVariablesIncludeFile();

  void CopyDefinition(
    cmWIXSourceWriter &source, const std::string &name);

  void AddDefinition(cmWIXSourceWriter& source,
    const std::string& name, const std::string& value);

  bool CreateWiXSourceFiles();

  bool CreateFeatureHierarchy(
    cmWIXSourceWriter& featureDefinitions);

  bool EmitFeatureForComponentGroup(
    cmWIXSourceWriter& featureDefinitions,
    cmCPackComponentGroup const& group);

  bool EmitFeatureForComponent(
    cmWIXSourceWriter& featureDefinitions,
    cmCPackComponent const& component);

  bool AddComponentsToFeature(
    std::string const& rootPath,
    std::string const& featureId,
    cmWIXSourceWriter& directoryDefinitions,
    cmWIXSourceWriter& fileDefinitions,
    cmWIXSourceWriter& featureDefinitions,
    shortcut_map_t& shortcutMap);

  bool CreateStartMenuShortcuts(
    std::string const& cpackComponentName,
    std::string const& featureId,
    shortcut_map_t& shortcutMap,
    cmWIXSourceWriter& fileDefinitions,
    cmWIXSourceWriter& featureDefinitions);

  void CreateUninstallShortcut(
    std::string const& packageName,
    cmWIXSourceWriter& fileDefinitions);

  void AppendUserSuppliedExtraSources();

  void AppendUserSuppliedExtraObjects(std::ostream& stream);

  bool CreateLicenseFile();

  bool RunWiXCommand(const std::string& command);

  bool RunCandleCommand(
    const std::string& sourceFile, const std::string& objectFile);

  bool RunLightCommand(const std::string& objectFiles);

  void AddDirectoryAndFileDefinitons(const std::string& topdir,
    const std::string& directoryId,
    cmWIXSourceWriter& directoryDefinitions,
    cmWIXSourceWriter& fileDefinitions,
    cmWIXSourceWriter& featureDefinitions,
    const std::vector<std::string>& pkgExecutables,
    shortcut_map_t& shortcutMap);

  bool RequireOption(const std::string& name, std::string& value) const;

  std::string GetArchitecture() const;

  static std::string GenerateGUID();

  static std::string QuotePath(const std::string& path);

  static std::string GetRightmostExtension(const std::string& filename);

  std::string PathToId(const std::string& path);

  std::string CreateNewIdForPath(const std::string& path);

  static std::string CreateHashedId(
    const std::string& path, const std::string& normalizedFilename);

  std::string NormalizeComponentForId(
    const std::string& component, size_t& replacementCount);

  static bool IsLegalIdCharacter(char c);

  void CollectExtensions(
       const std::string& variableName, extension_set_t& extensions);

  void AddCustomFlags(
    const std::string& variableName, std::ostream& stream);

  void CreateStartMenuFolder(cmWIXSourceWriter& directoryDefinitions);

  std::vector<std::string> wixSources;
  id_map_t pathToIdMap;
  ambiguity_map_t idAmbiguityCounter;

  extension_set_t candleExtensions;
  extension_set_t lightExtensions;
};

#endif