CPackWIX: Fix incomplete CPACK_WIX_SKIP_PROGRAM_FOLDER implementation

Commit 17bbf6af (CPackWIX: Implement new CPACK_WIX_SKIP_PROGRAM_FOLDER
feature) generates GUIDs for most but not all components
when the feature is active.

Generate the remaining GUIDs as well.

Co-Author: Nils Gladitz <nilsgladitz@gmail.com>
This commit is contained in:
Michael Stürmer 2016-09-06 12:11:00 +02:00 committed by Nils Gladitz
parent 8317ea01aa
commit 1bc33257d4
10 changed files with 79 additions and 38 deletions

View File

@ -35,6 +35,7 @@
cmCPackWIXGenerator::cmCPackWIXGenerator() cmCPackWIXGenerator::cmCPackWIXGenerator()
: Patch(0) : Patch(0)
, ComponentGuidType(cmWIXSourceWriter::WIX_GENERATED_GUID)
{ {
} }
@ -234,6 +235,12 @@ bool cmCPackWIXGenerator::InitializeWiXConfiguration()
} }
} }
// if install folder is supposed to be set absolutely, the default
// component guid "*" cannot be used
if (cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"))) {
this->ComponentGuidType = cmWIXSourceWriter::CMAKE_GENERATED_GUID;
}
return true; return true;
} }
@ -317,7 +324,9 @@ void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile()
{ {
std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi"; std::string includeFilename = this->CPackTopLevel + "/cpack_variables.wxi";
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); cmWIXSourceWriter includeFile(this->Logger, includeFilename,
this->ComponentGuidType,
cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT);
CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID"); CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID");
CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID"); CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID");
@ -338,7 +347,9 @@ void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
{ {
std::string includeFilename = this->CPackTopLevel + "/properties.wxi"; std::string includeFilename = this->CPackTopLevel + "/properties.wxi";
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); cmWIXSourceWriter includeFile(this->Logger, includeFilename,
this->ComponentGuidType,
cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT);
std::string prefix = "CPACK_WIX_PROPERTY_"; std::string prefix = "CPACK_WIX_PROPERTY_";
std::vector<std::string> options = GetOptions(); std::vector<std::string> options = GetOptions();
@ -386,7 +397,9 @@ void cmCPackWIXGenerator::CreateWiXProductFragmentIncludeFile()
{ {
std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi"; std::string includeFilename = this->CPackTopLevel + "/product_fragment.wxi";
cmWIXSourceWriter includeFile(this->Logger, includeFilename, true); cmWIXSourceWriter includeFile(this->Logger, includeFilename,
this->ComponentGuidType,
cmWIXSourceWriter::INCLUDE_ELEMENT_ROOT);
this->Patch->ApplyFragment("#PRODUCT", includeFile); this->Patch->ApplyFragment("#PRODUCT", includeFile);
} }
@ -413,13 +426,15 @@ void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source,
bool cmCPackWIXGenerator::CreateWiXSourceFiles() bool cmCPackWIXGenerator::CreateWiXSourceFiles()
{ {
// if install folder is supposed to be set absolutely, the default
// component guid "*" cannot be used
std::string directoryDefinitionsFilename = std::string directoryDefinitionsFilename =
this->CPackTopLevel + "/directories.wxs"; this->CPackTopLevel + "/directories.wxs";
this->WixSources.push_back(directoryDefinitionsFilename); this->WixSources.push_back(directoryDefinitionsFilename);
cmWIXDirectoriesSourceWriter directoryDefinitions( cmWIXDirectoriesSourceWriter directoryDefinitions(
this->Logger, directoryDefinitionsFilename); this->Logger, directoryDefinitionsFilename, this->ComponentGuidType);
directoryDefinitions.BeginElement("Fragment"); directoryDefinitions.BeginElement("Fragment");
std::string installRoot; std::string installRoot;
@ -439,13 +454,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
this->WixSources.push_back(fileDefinitionsFilename); this->WixSources.push_back(fileDefinitionsFilename);
cmWIXFilesSourceWriter fileDefinitions(this->Logger, cmWIXFilesSourceWriter fileDefinitions(this->Logger, fileDefinitionsFilename,
fileDefinitionsFilename); this->ComponentGuidType);
// if install folder is supposed to be set absolutely, the default
// component guid "*" cannot be used
fileDefinitions.GenerateComponentGuids =
cmSystemTools::IsOn(GetOption("CPACK_WIX_SKIP_PROGRAM_FOLDER"));
fileDefinitions.BeginElement("Fragment"); fileDefinitions.BeginElement("Fragment");
@ -454,8 +464,8 @@ bool cmCPackWIXGenerator::CreateWiXSourceFiles()
this->WixSources.push_back(featureDefinitionsFilename); this->WixSources.push_back(featureDefinitionsFilename);
cmWIXFeaturesSourceWriter featureDefinitions(this->Logger, cmWIXFeaturesSourceWriter featureDefinitions(
featureDefinitionsFilename); this->Logger, featureDefinitionsFilename, this->ComponentGuidType);
featureDefinitions.BeginElement("Fragment"); featureDefinitions.BeginElement("Fragment");
@ -764,7 +774,8 @@ bool cmCPackWIXGenerator::CreateShortcutsOfSpecificType(
fileDefinitions.BeginElement("Component"); fileDefinitions.BeginElement("Component");
fileDefinitions.AddAttribute("Id", componentId); fileDefinitions.AddAttribute("Id", componentId);
fileDefinitions.AddAttribute("Guid", "*"); fileDefinitions.AddAttribute(
"Guid", fileDefinitions.CreateGuidFromComponentId(componentId));
this->Patch->ApplyFragment(componentId, fileDefinitions); this->Patch->ApplyFragment(componentId, fileDefinitions);

View File

@ -162,6 +162,8 @@ private:
std::string CPackTopLevel; std::string CPackTopLevel;
cmWIXPatch* Patch; cmWIXPatch* Patch;
cmWIXSourceWriter::GuidType ComponentGuidType;
}; };
#endif #endif

View File

@ -13,8 +13,8 @@
#include "cmWIXDirectoriesSourceWriter.h" #include "cmWIXDirectoriesSourceWriter.h"
cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter( cmWIXDirectoriesSourceWriter::cmWIXDirectoriesSourceWriter(
cmCPackLog* logger, std::string const& filename) cmCPackLog* logger, std::string const& filename, GuidType componentGuidType)
: cmWIXSourceWriter(logger, filename) : cmWIXSourceWriter(logger, filename, componentGuidType)
{ {
} }

View File

@ -25,8 +25,8 @@
class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter class cmWIXDirectoriesSourceWriter : public cmWIXSourceWriter
{ {
public: public:
cmWIXDirectoriesSourceWriter(cmCPackLog* logger, cmWIXDirectoriesSourceWriter(cmCPackLog* logger, std::string const& filename,
std::string const& filename); GuidType componentGuidType);
void EmitStartMenuFolder(std::string const& startMenuFolder); void EmitStartMenuFolder(std::string const& startMenuFolder);

View File

@ -13,8 +13,8 @@
#include "cmWIXFeaturesSourceWriter.h" #include "cmWIXFeaturesSourceWriter.h"
cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter( cmWIXFeaturesSourceWriter::cmWIXFeaturesSourceWriter(
cmCPackLog* logger, std::string const& filename) cmCPackLog* logger, std::string const& filename, GuidType componentGuidType)
: cmWIXSourceWriter(logger, filename) : cmWIXSourceWriter(logger, filename, componentGuidType)
{ {
} }
@ -24,7 +24,7 @@ void cmWIXFeaturesSourceWriter::CreateCMakePackageRegistryEntry(
BeginElement("Component"); BeginElement("Component");
AddAttribute("Id", "CM_PACKAGE_REGISTRY"); AddAttribute("Id", "CM_PACKAGE_REGISTRY");
AddAttribute("Directory", "TARGETDIR"); AddAttribute("Directory", "TARGETDIR");
AddAttribute("Guid", "*"); AddAttribute("Guid", CreateGuidFromComponentId("CM_PACKAGE_REGISTRY"));
std::string registryKey = std::string registryKey =
std::string("Software\\Kitware\\CMake\\Packages\\") + package; std::string("Software\\Kitware\\CMake\\Packages\\") + package;

View File

@ -23,7 +23,8 @@
class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter class cmWIXFeaturesSourceWriter : public cmWIXSourceWriter
{ {
public: public:
cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename); cmWIXFeaturesSourceWriter(cmCPackLog* logger, std::string const& filename,
GuidType componentGuidType);
void CreateCMakePackageRegistryEntry(std::string const& package, void CreateCMakePackageRegistryEntry(std::string const& package,
std::string const& upgradeGuid); std::string const& upgradeGuid);

View File

@ -24,9 +24,9 @@
#include <sys/stat.h> #include <sys/stat.h>
cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger, cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
std::string const& filename) std::string const& filename,
: cmWIXSourceWriter(logger, filename) GuidType componentGuidType)
, GenerateComponentGuids(false) : cmWIXSourceWriter(logger, filename, componentGuidType)
{ {
} }
@ -130,13 +130,7 @@ std::string cmWIXFilesSourceWriter::EmitComponentFile(
std::string componentId = std::string("CM_C") + id; std::string componentId = std::string("CM_C") + id;
std::string fileId = std::string("CM_F") + id; std::string fileId = std::string("CM_F") + id;
std::string guid = "*"; std::string guid = CreateGuidFromComponentId(componentId);
if (this->GenerateComponentGuids) {
std::string md5 = cmSystemTools::ComputeStringMD5(componentId);
cmUuid uuid;
std::vector<unsigned char> ns;
guid = uuid.FromMd5(ns, md5);
}
BeginElement("DirectoryRef"); BeginElement("DirectoryRef");
AddAttribute("Id", directoryId); AddAttribute("Id", directoryId);

View File

@ -26,7 +26,8 @@
class cmWIXFilesSourceWriter : public cmWIXSourceWriter class cmWIXFilesSourceWriter : public cmWIXSourceWriter
{ {
public: public:
cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename); cmWIXFilesSourceWriter(cmCPackLog* logger, std::string const& filename,
GuidType componentGuidType);
void EmitShortcut(std::string const& id, cmWIXShortcut const& shortcut, void EmitShortcut(std::string const& id, cmWIXShortcut const& shortcut,
std::string const& shortcutPrefix, size_t shortcutIndex); std::string const& shortcutPrefix, size_t shortcutIndex);
@ -47,8 +48,6 @@ public:
std::string const& id, std::string const& id,
std::string const& filePath, cmWIXPatch& patch, std::string const& filePath, cmWIXPatch& patch,
cmInstalledFile const* installedFile); cmInstalledFile const* installedFile);
bool GenerateComponentGuids;
}; };
#endif #endif

View File

@ -14,19 +14,23 @@
#include <CPack/cmCPackGenerator.h> #include <CPack/cmCPackGenerator.h>
#include <cmUuid.h>
#include <windows.h> #include <windows.h>
cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger, cmWIXSourceWriter::cmWIXSourceWriter(cmCPackLog* logger,
std::string const& filename, std::string const& filename,
bool isIncludeFile) GuidType componentGuidType,
RootElementType rootElementType)
: Logger(logger) : Logger(logger)
, File(filename.c_str()) , File(filename.c_str())
, State(DEFAULT) , State(DEFAULT)
, SourceFilename(filename) , SourceFilename(filename)
, ComponentGuidType(componentGuidType)
{ {
WriteXMLDeclaration(); WriteXMLDeclaration();
if (isIncludeFile) { if (rootElementType == INCLUDE_ELEMENT_ROOT) {
BeginElement("Include"); BeginElement("Include");
} else { } else {
BeginElement("Wix"); BeginElement("Wix");
@ -173,6 +177,19 @@ std::string cmWIXSourceWriter::CMakeEncodingToUtf8(std::string const& value)
#endif #endif
} }
std::string cmWIXSourceWriter::CreateGuidFromComponentId(
std::string const& componentId)
{
std::string guid = "*";
if (this->ComponentGuidType == CMAKE_GENERATED_GUID) {
std::string md5 = cmSystemTools::ComputeStringMD5(componentId);
cmUuid uuid;
std::vector<unsigned char> ns;
guid = uuid.FromMd5(ns, md5);
}
return guid;
}
void cmWIXSourceWriter::WriteXMLDeclaration() void cmWIXSourceWriter::WriteXMLDeclaration()
{ {
File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; File << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;

View File

@ -26,8 +26,21 @@
class cmWIXSourceWriter class cmWIXSourceWriter
{ {
public: public:
enum GuidType
{
WIX_GENERATED_GUID,
CMAKE_GENERATED_GUID
};
enum RootElementType
{
WIX_ELEMENT_ROOT,
INCLUDE_ELEMENT_ROOT
};
cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename, cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename,
bool isIncludeFile = false); GuidType componentGuidType,
RootElementType rootElementType = WIX_ELEMENT_ROOT);
~cmWIXSourceWriter(); ~cmWIXSourceWriter();
@ -45,6 +58,8 @@ public:
void AddAttributeUnlessEmpty(std::string const& key, void AddAttributeUnlessEmpty(std::string const& key,
std::string const& value); std::string const& value);
std::string CreateGuidFromComponentId(std::string const& componentId);
static std::string CMakeEncodingToUtf8(std::string const& value); static std::string CMakeEncodingToUtf8(std::string const& value);
protected: protected:
@ -70,6 +85,8 @@ private:
std::vector<std::string> Elements; std::vector<std::string> Elements;
std::string SourceFilename; std::string SourceFilename;
GuidType ComponentGuidType;
}; };
#endif #endif