2012-10-03 18:08:49 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
2014-02-25 02:21:12 +04:00
|
|
|
Copyright 2000-2014 Kitware, Inc., Insight Software Consortium
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
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.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmCPackWIXGenerator.h"
|
|
|
|
|
|
|
|
#include <cmSystemTools.h>
|
|
|
|
#include <cmGeneratedFileStream.h>
|
2013-10-11 00:49:33 +04:00
|
|
|
#include <cmCryptoHash.h>
|
2012-10-03 18:08:49 +04:00
|
|
|
#include <CPack/cmCPackLog.h>
|
|
|
|
#include <CPack/cmCPackComponentGroup.h>
|
|
|
|
|
|
|
|
#include "cmWIXSourceWriter.h"
|
2014-02-25 02:21:12 +04:00
|
|
|
#include "cmWIXDirectoriesSourceWriter.h"
|
|
|
|
#include "cmWIXFeaturesSourceWriter.h"
|
|
|
|
#include "cmWIXFilesSourceWriter.h"
|
2012-10-03 18:08:49 +04:00
|
|
|
#include "cmWIXRichTextFormatWriter.h"
|
|
|
|
|
|
|
|
#include <cmsys/SystemTools.hxx>
|
|
|
|
#include <cmsys/Directory.hxx>
|
2013-12-05 09:17:24 +04:00
|
|
|
#include <cmsys/Encoding.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
#include <rpc.h> // for GUID generation
|
|
|
|
|
2014-02-04 21:40:45 +04:00
|
|
|
cmCPackWIXGenerator::cmCPackWIXGenerator():
|
2014-02-25 02:21:12 +04:00
|
|
|
HasDesktopShortcuts(false),
|
2014-04-19 00:45:30 +04:00
|
|
|
Patch(0)
|
2014-02-04 21:40:45 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
cmCPackWIXGenerator::~cmCPackWIXGenerator()
|
|
|
|
{
|
|
|
|
if(this->Patch)
|
|
|
|
{
|
|
|
|
delete this->Patch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
int cmCPackWIXGenerator::InitializeInternal()
|
|
|
|
{
|
|
|
|
componentPackageMethod = ONE_PACKAGE;
|
2014-04-19 00:45:30 +04:00
|
|
|
this->Patch = new cmWIXPatch(this->Logger);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return this->Superclass::InitializeInternal();
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
bool cmCPackWIXGenerator::RunWiXCommand(std::string const& command)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string logFileName = this->CPackTopLevel + "/wix.log";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_DEBUG,
|
|
|
|
"Running WiX command: " << command << std::endl);
|
|
|
|
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
int returnValue = 0;
|
|
|
|
bool status = cmSystemTools::RunSingleCommand(command.c_str(), &output,
|
|
|
|
&returnValue, 0, cmSystemTools::OUTPUT_NONE);
|
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream logFile(logFileName.c_str(), std::ios::app);
|
2012-10-03 18:08:49 +04:00
|
|
|
logFile << command << std::endl;
|
|
|
|
logFile << output;
|
|
|
|
logFile.close();
|
|
|
|
|
|
|
|
if(!status || returnValue)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Problem running WiX candle. "
|
|
|
|
"Please check '" << logFileName << "' for errors." << std::endl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::RunCandleCommand(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& sourceFile, std::string const& objectFile)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string executable;
|
|
|
|
if(!RequireOption("CPACK_WIX_CANDLE_EXECUTABLE", executable))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream command;
|
|
|
|
command << QuotePath(executable);
|
|
|
|
command << " -nologo";
|
|
|
|
command << " -arch " << GetArchitecture();
|
|
|
|
command << " -out " << QuotePath(objectFile);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
for(extension_set_t::const_iterator i = CandleExtensions.begin();
|
|
|
|
i != CandleExtensions.end(); ++i)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
|
|
|
command << " -ext " << QuotePath(*i);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddCustomFlags("CPACK_WIX_CANDLE_EXTRA_FLAGS", command);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
command << " " << QuotePath(sourceFile);
|
|
|
|
|
|
|
|
return RunWiXCommand(command.str());
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
bool cmCPackWIXGenerator::RunLightCommand(std::string const& objectFiles)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string executable;
|
|
|
|
if(!RequireOption("CPACK_WIX_LIGHT_EXECUTABLE", executable))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream command;
|
|
|
|
command << QuotePath(executable);
|
|
|
|
command << " -nologo";
|
|
|
|
command << " -out " << QuotePath(packageFileNames.at(0));
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
for(extension_set_t::const_iterator i = this->LightExtensions.begin();
|
|
|
|
i != this->LightExtensions.end(); ++i)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
|
|
|
command << " -ext " << QuotePath(*i);
|
|
|
|
}
|
|
|
|
|
2013-05-06 19:21:42 +04:00
|
|
|
const char* const cultures = GetOption("CPACK_WIX_CULTURES");
|
|
|
|
if(cultures)
|
|
|
|
{
|
|
|
|
command << " -cultures:" << cultures;
|
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
AddCustomFlags("CPACK_WIX_LIGHT_EXTRA_FLAGS", command);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
command << " " << objectFiles;
|
|
|
|
|
|
|
|
return RunWiXCommand(command.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmCPackWIXGenerator::PackageFiles()
|
|
|
|
{
|
|
|
|
if(!PackageFilesImpl() || cmSystemTools::GetErrorOccuredFlag())
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Fatal WiX Generator Error" << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::InitializeWiXConfiguration()
|
|
|
|
{
|
|
|
|
if(!ReadListFile("CPackWIX.cmake"))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while executing CPackWIX.cmake" << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GetOption("CPACK_WIX_PRODUCT_GUID") == 0)
|
|
|
|
{
|
|
|
|
std::string guid = GenerateGUID();
|
|
|
|
SetOption("CPACK_WIX_PRODUCT_GUID", guid.c_str());
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
|
|
|
"CPACK_WIX_PRODUCT_GUID implicitly set to " << guid << " . "
|
|
|
|
<< std::endl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GetOption("CPACK_WIX_UPGRADE_GUID") == 0)
|
|
|
|
{
|
|
|
|
std::string guid = GenerateGUID();
|
|
|
|
SetOption("CPACK_WIX_UPGRADE_GUID", guid.c_str());
|
|
|
|
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_WARNING,
|
|
|
|
"CPACK_WIX_UPGRADE_GUID implicitly set to " << guid << " . "
|
|
|
|
"Please refer to the documentation on how and why "
|
|
|
|
"you might want to set this explicitly." << std::endl);
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
if(!RequireOption("CPACK_TOPLEVEL_DIRECTORY", this->CPackTopLevel))
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(GetOption("CPACK_WIX_LICENSE_RTF") == 0)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string licenseFilename = this->CPackTopLevel + "/License.rtf";
|
2012-10-03 18:08:49 +04:00
|
|
|
SetOption("CPACK_WIX_LICENSE_RTF", licenseFilename.c_str());
|
|
|
|
|
|
|
|
if(!CreateLicenseFile())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
if(GetOption("CPACK_PACKAGE_VENDOR") == 0)
|
|
|
|
{
|
2013-11-10 22:48:29 +04:00
|
|
|
std::string defaultVendor = "Humanity";
|
|
|
|
SetOption("CPACK_PACKAGE_VENDOR", defaultVendor.c_str());
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2013-11-10 22:48:29 +04:00
|
|
|
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
|
|
|
|
"CPACK_PACKAGE_VENDOR implicitly set to " << defaultVendor << " . "
|
|
|
|
<< std::endl);
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
if(GetOption("CPACK_WIX_UI_REF") == 0)
|
|
|
|
{
|
|
|
|
std::string defaultRef = "WixUI_InstallDir";
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
if(this->Components.size())
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
|
|
|
defaultRef = "WixUI_FeatureTree";
|
|
|
|
}
|
|
|
|
|
|
|
|
SetOption("CPACK_WIX_UI_REF", defaultRef.c_str());
|
|
|
|
}
|
|
|
|
|
2014-03-02 02:13:35 +04:00
|
|
|
const char* packageContact = GetOption("CPACK_PACKAGE_CONTACT");
|
|
|
|
if(packageContact != 0 &&
|
|
|
|
GetOption("CPACK_WIX_PROPERTY_ARPCONTACT") == 0)
|
|
|
|
{
|
|
|
|
SetOption("CPACK_WIX_PROPERTY_ARPCONTACT", packageContact);
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
CollectExtensions("CPACK_WIX_EXTENSIONS", this->CandleExtensions);
|
|
|
|
CollectExtensions("CPACK_WIX_CANDLE_EXTENSIONS", this->CandleExtensions);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->LightExtensions.insert("WixUIExtension");
|
|
|
|
CollectExtensions("CPACK_WIX_EXTENSIONS", this->LightExtensions);
|
|
|
|
CollectExtensions("CPACK_WIX_LIGHT_EXTENSIONS", this->LightExtensions);
|
2013-11-10 22:48:29 +04:00
|
|
|
|
2013-12-17 01:30:11 +04:00
|
|
|
const char* patchFilePath = GetOption("CPACK_WIX_PATCH_FILE");
|
|
|
|
if(patchFilePath)
|
|
|
|
{
|
2014-04-19 00:45:30 +04:00
|
|
|
this->Patch->LoadFragments(patchFilePath);
|
2013-12-17 01:30:11 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::PackageFilesImpl()
|
|
|
|
{
|
|
|
|
if(!InitializeWiXConfiguration())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
CreateWiXVariablesIncludeFile();
|
2014-03-02 02:13:35 +04:00
|
|
|
CreateWiXPropertiesIncludeFile();
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
if(!CreateWiXSourceFiles())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
AppendUserSuppliedExtraSources();
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
std::stringstream objectFiles;
|
2014-02-25 02:21:12 +04:00
|
|
|
for(size_t i = 0; i < this->WixSources.size(); ++i)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& sourceFilename = this->WixSources[i];
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string objectFilename =
|
|
|
|
cmSystemTools::GetFilenameWithoutExtension(sourceFilename) + ".wixobj";
|
|
|
|
|
|
|
|
if(!RunCandleCommand(sourceFilename, objectFilename))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
objectFiles << " " << QuotePath(objectFilename);
|
|
|
|
}
|
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
AppendUserSuppliedExtraObjects(objectFiles);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
return RunLightCommand(objectFiles.str());
|
|
|
|
}
|
|
|
|
|
2013-10-13 15:16:54 +04:00
|
|
|
void cmCPackWIXGenerator::AppendUserSuppliedExtraSources()
|
|
|
|
{
|
|
|
|
const char *cpackWixExtraSources = GetOption("CPACK_WIX_EXTRA_SOURCES");
|
|
|
|
if(!cpackWixExtraSources) return;
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
cmSystemTools::ExpandListArgument(cpackWixExtraSources, this->WixSources);
|
2013-10-13 15:16:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AppendUserSuppliedExtraObjects(std::ostream& stream)
|
|
|
|
{
|
|
|
|
const char *cpackWixExtraObjects = GetOption("CPACK_WIX_EXTRA_OBJECTS");
|
|
|
|
if(!cpackWixExtraObjects) return;
|
|
|
|
|
|
|
|
std::vector<std::string> expandedExtraObjects;
|
|
|
|
|
|
|
|
cmSystemTools::ExpandListArgument(
|
|
|
|
cpackWixExtraObjects, expandedExtraObjects);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < expandedExtraObjects.size(); ++i)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
stream << " " << QuotePath(expandedExtraObjects[i]);
|
2013-10-13 15:16:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
void cmCPackWIXGenerator::CreateWiXVariablesIncludeFile()
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string includeFilename =
|
2014-02-25 02:21:12 +04:00
|
|
|
this->CPackTopLevel + "/cpack_variables.wxi";
|
|
|
|
|
|
|
|
cmWIXSourceWriter includeFile(
|
|
|
|
this->Logger, includeFilename, true);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_GUID");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UPGRADE_GUID");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_VENDOR");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_NAME");
|
|
|
|
CopyDefinition(includeFile, "CPACK_PACKAGE_VERSION");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_LICENSE_RTF");
|
2012-12-15 00:50:18 +04:00
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PRODUCT_ICON");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_BANNER");
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_DIALOG");
|
2013-03-01 06:09:58 +04:00
|
|
|
SetOptionIfNotSet("CPACK_WIX_PROGRAM_MENU_FOLDER",
|
|
|
|
GetOption("CPACK_PACKAGE_NAME"));
|
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_PROGRAM_MENU_FOLDER");
|
2013-11-20 00:38:09 +04:00
|
|
|
CopyDefinition(includeFile, "CPACK_WIX_UI_REF");
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
|
2014-03-02 02:13:35 +04:00
|
|
|
void cmCPackWIXGenerator::CreateWiXPropertiesIncludeFile()
|
|
|
|
{
|
|
|
|
std::string includeFilename =
|
|
|
|
this->CPackTopLevel + "/properties.wxi";
|
|
|
|
|
|
|
|
cmWIXSourceWriter includeFile(
|
|
|
|
this->Logger, includeFilename, true);
|
|
|
|
|
|
|
|
std::string prefix = "CPACK_WIX_PROPERTY_";
|
|
|
|
std::vector<std::string> options = GetOptions();
|
|
|
|
|
|
|
|
for(size_t i = 0; i < options.size(); ++i)
|
|
|
|
{
|
|
|
|
std::string const& name = options[i];
|
|
|
|
|
|
|
|
if(name.length() > prefix.length() &&
|
|
|
|
name.substr(0, prefix.length()) == prefix)
|
|
|
|
{
|
|
|
|
std::string id = name.substr(prefix.length());
|
|
|
|
std::string value = GetOption(name.c_str());
|
|
|
|
|
|
|
|
includeFile.BeginElement("Property");
|
|
|
|
includeFile.AddAttribute("Id", id);
|
|
|
|
includeFile.AddAttribute("Value", value);
|
|
|
|
includeFile.EndElement("Property");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
void cmCPackWIXGenerator::CopyDefinition(
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXSourceWriter &source, std::string const& name)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
const char* value = GetOption(name.c_str());
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
AddDefinition(source, name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AddDefinition(cmWIXSourceWriter& source,
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& name, std::string const& value)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << name << "=\"" << value << '"';
|
|
|
|
|
|
|
|
source.AddProcessingInstruction("define",
|
|
|
|
cmWIXSourceWriter::WindowsCodepageToUtf8(tmp.str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::CreateWiXSourceFiles()
|
|
|
|
{
|
|
|
|
std::string directoryDefinitionsFilename =
|
2014-02-25 02:21:12 +04:00
|
|
|
this->CPackTopLevel + "/directories.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(directoryDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXDirectoriesSourceWriter directoryDefinitions(
|
|
|
|
this->Logger, directoryDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
directoryDefinitions.BeginElement("Fragment");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string installRoot;
|
|
|
|
if(!RequireOption("CPACK_PACKAGE_INSTALL_DIRECTORY", installRoot))
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.BeginElement("Directory");
|
|
|
|
directoryDefinitions.AddAttribute("Id", "TARGETDIR");
|
|
|
|
directoryDefinitions.AddAttribute("Name", "SourceDir");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
size_t installRootSize =
|
|
|
|
directoryDefinitions.BeginInstallationPrefixDirectory(
|
|
|
|
GetProgramFilesFolderId(), installRoot);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string fileDefinitionsFilename =
|
2014-02-25 02:21:12 +04:00
|
|
|
this->CPackTopLevel + "/files.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(fileDefinitionsFilename);
|
|
|
|
|
|
|
|
cmWIXFilesSourceWriter fileDefinitions(
|
|
|
|
this->Logger, fileDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
fileDefinitions.BeginElement("Fragment");
|
|
|
|
|
|
|
|
std::string featureDefinitionsFilename =
|
2014-02-25 02:21:12 +04:00
|
|
|
this->CPackTopLevel +"/features.wxs";
|
|
|
|
|
|
|
|
this->WixSources.push_back(featureDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXFeaturesSourceWriter featureDefinitions(
|
|
|
|
this->Logger, featureDefinitionsFilename);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
featureDefinitions.BeginElement("Fragment");
|
|
|
|
|
|
|
|
featureDefinitions.BeginElement("Feature");
|
|
|
|
featureDefinitions.AddAttribute("Id", "ProductFeature");
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.AddAttribute("Display", "expand");
|
|
|
|
featureDefinitions.AddAttribute("ConfigurableDirectory", "INSTALL_ROOT");
|
|
|
|
|
|
|
|
std::string cpackPackageName;
|
|
|
|
if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.AddAttribute("Title", cpackPackageName);
|
2012-10-03 18:08:49 +04:00
|
|
|
featureDefinitions.AddAttribute("Level", "1");
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
const char* package = GetOption("CPACK_WIX_CMAKE_PACKAGE_REGISTRY");
|
|
|
|
if(package)
|
2014-01-08 04:28:24 +04:00
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.CreateCMakePackageRegistryEntry(
|
|
|
|
package, GetOption("CPACK_WIX_UPGRADE_GUID"));
|
2014-01-08 04:28:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!CreateFeatureHierarchy(featureDefinitions))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-20 00:38:09 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
featureDefinitions.EndElement("Feature");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
bool hasShortcuts = false;
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
shortcut_map_t globalShortcuts;
|
|
|
|
if(Components.empty())
|
2013-03-01 06:09:58 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
AddComponentsToFeature(toplevel, "ProductFeature",
|
|
|
|
directoryDefinitions, fileDefinitions, featureDefinitions,
|
|
|
|
globalShortcuts);
|
|
|
|
if(globalShortcuts.size())
|
|
|
|
{
|
|
|
|
hasShortcuts = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(std::map<std::string, cmCPackComponent>::const_iterator
|
2014-02-25 02:21:12 +04:00
|
|
|
i = this->Components.begin(); i != this->Components.end(); ++i)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
|
|
|
cmCPackComponent const& component = i->second;
|
|
|
|
|
|
|
|
std::string componentPath = toplevel;
|
|
|
|
componentPath += "/";
|
|
|
|
componentPath += component.Name;
|
|
|
|
|
|
|
|
std::string componentFeatureId = "CM_C_" + component.Name;
|
|
|
|
|
|
|
|
shortcut_map_t featureShortcuts;
|
|
|
|
AddComponentsToFeature(componentPath, componentFeatureId,
|
|
|
|
directoryDefinitions, fileDefinitions,
|
|
|
|
featureDefinitions, featureShortcuts);
|
|
|
|
if(featureShortcuts.size())
|
2013-10-23 14:14:39 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
hasShortcuts = true;
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
if(featureShortcuts.size())
|
|
|
|
{
|
|
|
|
if(!CreateStartMenuShortcuts(component.Name, componentFeatureId,
|
|
|
|
featureShortcuts, fileDefinitions, featureDefinitions))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
if(hasShortcuts)
|
2013-05-08 18:39:32 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
if(!CreateStartMenuShortcuts(std::string(), "ProductFeature",
|
|
|
|
globalShortcuts, fileDefinitions, featureDefinitions))
|
|
|
|
{
|
2013-10-23 14:14:39 +04:00
|
|
|
return false;
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
2013-05-08 18:39:32 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
featureDefinitions.EndElement("Fragment");
|
|
|
|
fileDefinitions.EndElement("Fragment");
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.EndInstallationPrefixDirectory(
|
|
|
|
installRootSize);
|
2013-11-20 00:38:09 +04:00
|
|
|
|
|
|
|
if(hasShortcuts)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.EmitStartMenuFolder(
|
|
|
|
GetOption("CPACK_WIX_PROGRAM_MENU_FOLDER"));
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
|
|
|
|
2014-02-04 21:40:45 +04:00
|
|
|
if(this->HasDesktopShortcuts)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
directoryDefinitions.EmitDesktopFolder();
|
2014-02-04 21:40:45 +04:00
|
|
|
}
|
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
directoryDefinitions.EndElement("Directory");
|
|
|
|
directoryDefinitions.EndElement("Fragment");
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
if(!GenerateMainSourceFileFromTemplate())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
return this->Patch->CheckForUnappliedFragments();
|
2014-02-25 02:21:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetProgramFilesFolderId() const
|
|
|
|
{
|
|
|
|
if(GetArchitecture() == "x86")
|
|
|
|
{
|
|
|
|
return "ProgramFilesFolder";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "ProgramFiles64Folder";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::GenerateMainSourceFileFromTemplate()
|
|
|
|
{
|
2012-10-03 18:08:49 +04:00
|
|
|
std::string wixTemplate = FindTemplate("WIX.template.in");
|
2013-07-03 02:19:31 +04:00
|
|
|
if(GetOption("CPACK_WIX_TEMPLATE") != 0)
|
|
|
|
{
|
|
|
|
wixTemplate = GetOption("CPACK_WIX_TEMPLATE");
|
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
if(wixTemplate.empty())
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Could not find CPack WiX template file WIX.template.in" << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string mainSourceFilePath = this->CPackTopLevel + "/main.wxs";
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
if(!ConfigureFile(wixTemplate.c_str(), mainSourceFilePath .c_str()))
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Failed creating '" << mainSourceFilePath <<
|
|
|
|
"'' from template." << std::endl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
this->WixSources.push_back(mainSourceFilePath);
|
2014-01-08 04:28:24 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
bool cmCPackWIXGenerator::CreateFeatureHierarchy(
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
|
|
|
for(std::map<std::string, cmCPackComponentGroup>::const_iterator
|
|
|
|
i = ComponentGroups.begin(); i != ComponentGroups.end(); ++i)
|
|
|
|
{
|
|
|
|
cmCPackComponentGroup const& group = i->second;
|
|
|
|
if(group.ParentGroup == 0)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitFeatureForComponentGroup(group);
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(std::map<std::string, cmCPackComponent>::const_iterator
|
2014-02-25 02:21:12 +04:00
|
|
|
i = this->Components.begin(); i != this->Components.end(); ++i)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
|
|
|
cmCPackComponent const& component = i->second;
|
|
|
|
|
|
|
|
if(!component.Group)
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitFeatureForComponent(component);
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::AddComponentsToFeature(
|
|
|
|
std::string const& rootPath,
|
|
|
|
std::string const& featureId,
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXDirectoriesSourceWriter& directoryDefinitions,
|
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions,
|
2013-11-20 00:38:09 +04:00
|
|
|
shortcut_map_t& shortcutMap)
|
2013-10-23 14:14:39 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.BeginElement("FeatureRef");
|
|
|
|
featureDefinitions.AddAttribute("Id", featureId);
|
|
|
|
|
|
|
|
std::vector<std::string> cpackPackageExecutablesList;
|
|
|
|
const char *cpackPackageExecutables = GetOption("CPACK_PACKAGE_EXECUTABLES");
|
|
|
|
if(cpackPackageExecutables)
|
2013-10-23 14:14:39 +04:00
|
|
|
{
|
2013-11-20 00:38:09 +04:00
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageExecutables,
|
|
|
|
cpackPackageExecutablesList);
|
|
|
|
if(cpackPackageExecutablesList.size() % 2 != 0 )
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"CPACK_PACKAGE_EXECUTABLES should contain pairs of <executable> and "
|
|
|
|
"<text label>." << std::endl);
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
|
|
|
|
2014-02-04 21:40:45 +04:00
|
|
|
std::vector<std::string> cpackPackageDesktopLinksList;
|
|
|
|
const char *cpackPackageDesktopLinks =
|
|
|
|
GetOption("CPACK_CREATE_DESKTOP_LINKS");
|
|
|
|
if(cpackPackageDesktopLinks)
|
|
|
|
{
|
|
|
|
cmSystemTools::ExpandListArgument(cpackPackageDesktopLinks,
|
|
|
|
cpackPackageDesktopLinksList);
|
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
AddDirectoryAndFileDefinitons(
|
|
|
|
rootPath, "INSTALL_ROOT",
|
|
|
|
directoryDefinitions, fileDefinitions, featureDefinitions,
|
2014-02-04 21:40:45 +04:00
|
|
|
cpackPackageExecutablesList, cpackPackageDesktopLinksList,
|
|
|
|
shortcutMap);
|
2013-11-20 00:38:09 +04:00
|
|
|
|
|
|
|
featureDefinitions.EndElement("FeatureRef");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::CreateStartMenuShortcuts(
|
|
|
|
std::string const& cpackComponentName,
|
|
|
|
std::string const& featureId,
|
|
|
|
shortcut_map_t& shortcutMap,
|
2014-02-25 02:21:12 +04:00
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions)
|
2013-11-20 00:38:09 +04:00
|
|
|
{
|
2014-02-04 21:40:45 +04:00
|
|
|
bool thisHasDesktopShortcuts = false;
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.BeginElement("FeatureRef");
|
|
|
|
featureDefinitions.AddAttribute("Id", featureId);
|
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
std::string cpackVendor;
|
|
|
|
if(!RequireOption("CPACK_PACKAGE_VENDOR", cpackVendor))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cpackPackageName;
|
|
|
|
if(!RequireOption("CPACK_PACKAGE_NAME", cpackPackageName))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
std::string idSuffix;
|
|
|
|
if(!cpackComponentName.empty())
|
|
|
|
{
|
|
|
|
idSuffix += "_";
|
|
|
|
idSuffix += cpackComponentName;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string componentId = "CM_SHORTCUT" + idSuffix;
|
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.BeginElement("DirectoryRef");
|
|
|
|
fileDefinitions.AddAttribute("Id", "PROGRAM_MENU_FOLDER");
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.BeginElement("Component");
|
2013-11-20 00:38:09 +04:00
|
|
|
fileDefinitions.AddAttribute("Id", componentId);
|
2013-10-23 14:14:39 +04:00
|
|
|
fileDefinitions.AddAttribute("Guid", "*");
|
|
|
|
|
|
|
|
for(shortcut_map_t::const_iterator
|
|
|
|
i = shortcutMap.begin(); i != shortcutMap.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string const& id = i->first;
|
|
|
|
cmWIXShortcut const& shortcut = i->second;
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitShortcut(id, shortcut, false);
|
2014-02-04 21:40:45 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
if(shortcut.desktop)
|
2014-02-04 21:40:45 +04:00
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
thisHasDesktopShortcuts = true;
|
2014-02-04 21:40:45 +04:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
if(cpackComponentName.empty())
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitUninstallShortcut(cpackPackageName);
|
2013-11-20 00:38:09 +04:00
|
|
|
}
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitRemoveFolder(
|
2014-02-04 21:40:45 +04:00
|
|
|
"CM_REMOVE_PROGRAM_MENU_FOLDER" + idSuffix);
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
std::string registryKey =
|
2013-12-20 15:01:28 +04:00
|
|
|
std::string("Software\\") + cpackVendor + "\\" + cpackPackageName;
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitStartMenuShortcutRegistryValue(
|
|
|
|
registryKey, cpackComponentName);
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
fileDefinitions.EndElement("Component");
|
|
|
|
fileDefinitions.EndElement("DirectoryRef");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
if(thisHasDesktopShortcuts)
|
2014-02-04 21:40:45 +04:00
|
|
|
{
|
|
|
|
this->HasDesktopShortcuts = true;
|
|
|
|
componentId = "CM_DESKTOP_SHORTCUT" + idSuffix;
|
|
|
|
|
|
|
|
fileDefinitions.BeginElement("DirectoryRef");
|
|
|
|
fileDefinitions.AddAttribute("Id", "DesktopFolder");
|
|
|
|
fileDefinitions.BeginElement("Component");
|
|
|
|
fileDefinitions.AddAttribute("Id", componentId);
|
|
|
|
fileDefinitions.AddAttribute("Guid", "*");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
for(shortcut_map_t::const_iterator
|
2014-02-04 21:40:45 +04:00
|
|
|
i = shortcutMap.begin(); i != shortcutMap.end(); ++i)
|
|
|
|
{
|
|
|
|
std::string const& id = i->first;
|
|
|
|
cmWIXShortcut const& shortcut = i->second;
|
|
|
|
|
|
|
|
if (!shortcut.desktop)
|
|
|
|
continue;
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitShortcut(id, shortcut, true);
|
2014-02-04 21:40:45 +04:00
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
fileDefinitions.EmitDesktopShortcutRegistryValue(
|
|
|
|
registryKey, cpackComponentName);
|
2014-02-04 21:40:45 +04:00
|
|
|
|
|
|
|
fileDefinitions.EndElement("Component");
|
|
|
|
fileDefinitions.EndElement("DirectoryRef");
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2014-02-04 21:40:45 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:38:09 +04:00
|
|
|
featureDefinitions.EndElement("FeatureRef");
|
2013-10-23 14:14:39 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
bool cmCPackWIXGenerator::CreateLicenseFile()
|
|
|
|
{
|
|
|
|
std::string licenseSourceFilename;
|
|
|
|
if(!RequireOption("CPACK_RESOURCE_FILE_LICENSE", licenseSourceFilename))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string licenseDestinationFilename;
|
|
|
|
if(!RequireOption("CPACK_WIX_LICENSE_RTF", licenseDestinationFilename))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string extension = GetRightmostExtension(licenseSourceFilename);
|
|
|
|
|
|
|
|
if(extension == ".rtf")
|
|
|
|
{
|
|
|
|
cmSystemTools::CopyAFile(
|
|
|
|
licenseSourceFilename.c_str(),
|
|
|
|
licenseDestinationFilename.c_str());
|
|
|
|
}
|
|
|
|
else if(extension == ".txt")
|
|
|
|
{
|
|
|
|
cmWIXRichTextFormatWriter rtfWriter(licenseDestinationFilename);
|
|
|
|
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream licenseSource(licenseSourceFilename.c_str());
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
std::string line;
|
|
|
|
while(std::getline(licenseSource, line))
|
|
|
|
{
|
|
|
|
rtfWriter.AddText(line);
|
|
|
|
rtfWriter.AddText("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"unsupported WiX License file extension '" <<
|
|
|
|
extension << "'" << std::endl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AddDirectoryAndFileDefinitons(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& topdir,
|
|
|
|
std::string const& directoryId,
|
|
|
|
cmWIXDirectoriesSourceWriter& directoryDefinitions,
|
|
|
|
cmWIXFilesSourceWriter& fileDefinitions,
|
|
|
|
cmWIXFeaturesSourceWriter& featureDefinitions,
|
2013-11-20 00:38:09 +04:00
|
|
|
const std::vector<std::string>& packageExecutables,
|
2014-02-04 21:40:45 +04:00
|
|
|
const std::vector<std::string>& desktopExecutables,
|
2013-11-20 00:38:09 +04:00
|
|
|
shortcut_map_t& shortcutMap)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
cmsys::Directory dir;
|
|
|
|
dir.Load(topdir.c_str());
|
|
|
|
|
2014-03-02 03:51:42 +04:00
|
|
|
if(dir.GetNumberOfFiles() == 2)
|
|
|
|
{
|
|
|
|
std::string componentId = fileDefinitions.EmitComponentCreateFolder(
|
|
|
|
directoryId, GenerateGUID());
|
|
|
|
|
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-04 23:37:41 +04:00
|
|
|
for(size_t i = 0; i < dir.GetNumberOfFiles(); ++i)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string fileName = dir.GetFile(static_cast<unsigned long>(i));
|
|
|
|
|
|
|
|
if(fileName == "." || fileName == "..")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fullPath = topdir + "/" + fileName;
|
|
|
|
|
2013-10-11 00:49:33 +04:00
|
|
|
std::string relativePath = cmSystemTools::RelativePath(
|
|
|
|
toplevel.c_str(), fullPath.c_str());
|
|
|
|
|
|
|
|
std::string id = PathToId(relativePath);
|
|
|
|
|
2012-10-03 18:08:49 +04:00
|
|
|
if(cmSystemTools::FileIsDirectory(fullPath.c_str()))
|
|
|
|
{
|
2013-10-11 00:49:33 +04:00
|
|
|
std::string subDirectoryId = std::string("CM_D") + id;
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
directoryDefinitions.BeginElement("Directory");
|
|
|
|
directoryDefinitions.AddAttribute("Id", subDirectoryId);
|
|
|
|
directoryDefinitions.AddAttribute("Name", fileName);
|
|
|
|
|
|
|
|
AddDirectoryAndFileDefinitons(
|
|
|
|
fullPath, subDirectoryId,
|
|
|
|
directoryDefinitions,
|
|
|
|
fileDefinitions,
|
|
|
|
featureDefinitions,
|
2013-11-20 00:38:09 +04:00
|
|
|
packageExecutables,
|
2014-02-04 21:40:45 +04:00
|
|
|
desktopExecutables,
|
2013-11-20 00:38:09 +04:00
|
|
|
shortcutMap);
|
2013-10-23 14:14:39 +04:00
|
|
|
|
2014-04-19 00:45:30 +04:00
|
|
|
this->Patch->ApplyFragment(subDirectoryId, directoryDefinitions);
|
2013-10-23 14:14:39 +04:00
|
|
|
directoryDefinitions.EndElement("Directory");
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string componentId = fileDefinitions.EmitComponentFile(
|
2014-04-19 00:45:30 +04:00
|
|
|
directoryId, id, fullPath, *(this->Patch));
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
featureDefinitions.EmitComponentRef(componentId);
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
for(size_t j = 0; j < packageExecutables.size(); ++j)
|
2013-03-01 06:09:58 +04:00
|
|
|
{
|
2013-10-23 14:14:39 +04:00
|
|
|
std::string const& executableName = packageExecutables[j++];
|
|
|
|
std::string const& textLabel = packageExecutables[j];
|
2013-03-01 06:09:58 +04:00
|
|
|
|
2013-10-23 14:14:39 +04:00
|
|
|
if(cmSystemTools::LowerCase(fileName) ==
|
|
|
|
cmSystemTools::LowerCase(executableName) + ".exe")
|
2013-03-01 06:09:58 +04:00
|
|
|
{
|
2013-10-23 14:14:39 +04:00
|
|
|
cmWIXShortcut &shortcut = shortcutMap[id];
|
|
|
|
shortcut.textLabel= textLabel;
|
|
|
|
shortcut.workingDirectoryId = directoryId;
|
2014-02-04 21:40:45 +04:00
|
|
|
|
|
|
|
if(desktopExecutables.size() &&
|
|
|
|
std::find(desktopExecutables.begin(),
|
|
|
|
desktopExecutables.end(),
|
|
|
|
executableName)
|
|
|
|
!= desktopExecutables.end())
|
|
|
|
{
|
|
|
|
shortcut.desktop = true;
|
|
|
|
}
|
2013-03-01 06:09:58 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-03 18:08:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::RequireOption(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& name, std::string &value) const
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
const char* tmp = GetOption(name.c_str());
|
|
|
|
if(tmp)
|
|
|
|
{
|
|
|
|
value = tmp;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Required variable " << name << " not set" << std::endl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetArchitecture() const
|
|
|
|
{
|
|
|
|
std::string void_p_size;
|
|
|
|
RequireOption("CPACK_WIX_SIZEOF_VOID_P", void_p_size);
|
|
|
|
|
|
|
|
if(void_p_size == "8")
|
|
|
|
{
|
|
|
|
return "x64";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "x86";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GenerateGUID()
|
|
|
|
{
|
|
|
|
UUID guid;
|
|
|
|
UuidCreate(&guid);
|
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
unsigned short *tmp = 0;
|
|
|
|
UuidToStringW(&guid, &tmp);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
2013-12-05 09:17:24 +04:00
|
|
|
std::string result =
|
|
|
|
cmsys::Encoding::ToNarrow(reinterpret_cast<wchar_t*>(tmp));
|
|
|
|
RpcStringFreeW(&tmp);
|
2012-10-03 18:08:49 +04:00
|
|
|
|
|
|
|
return cmSystemTools::UpperCase(result);
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::QuotePath(std::string const& path)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
return std::string("\"") + path + '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::GetRightmostExtension(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& filename)
|
2012-10-03 18:08:49 +04:00
|
|
|
{
|
|
|
|
std::string extension;
|
|
|
|
|
|
|
|
std::string::size_type i = filename.rfind(".");
|
|
|
|
if(i != std::string::npos)
|
|
|
|
{
|
|
|
|
extension = filename.substr(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmSystemTools::LowerCase(extension);
|
|
|
|
}
|
2013-10-11 00:49:33 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::PathToId(std::string const& path)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
2013-12-20 21:12:01 +04:00
|
|
|
id_map_t::const_iterator i = PathToIdMap.find(path);
|
|
|
|
if(i != PathToIdMap.end()) return i->second;
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
std::string id = CreateNewIdForPath(path);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmCPackWIXGenerator::CreateNewIdForPath(std::string const& path)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
std::vector<std::string> components;
|
|
|
|
cmSystemTools::SplitPath(path.c_str(), components, false);
|
|
|
|
|
|
|
|
size_t replacementCount = 0;
|
|
|
|
|
|
|
|
std::string identifier;
|
|
|
|
std::string currentComponent;
|
|
|
|
|
|
|
|
for(size_t i = 1; i < components.size(); ++i)
|
|
|
|
{
|
|
|
|
if(i != 1) identifier += '.';
|
|
|
|
|
|
|
|
currentComponent = NormalizeComponentForId(
|
|
|
|
components[i], replacementCount);
|
|
|
|
|
|
|
|
identifier += currentComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string idPrefix = "P";
|
|
|
|
size_t replacementPercent = replacementCount * 100 / identifier.size();
|
|
|
|
if(replacementPercent > 33 || identifier.size() > 60)
|
|
|
|
{
|
|
|
|
identifier = CreateHashedId(path, currentComponent);
|
|
|
|
idPrefix = "H";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream result;
|
|
|
|
result << idPrefix << "_" << identifier;
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
size_t ambiguityCount = ++IdAmbiguityCounter[identifier];
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
if(ambiguityCount > 999)
|
|
|
|
{
|
|
|
|
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
|
|
|
"Error while trying to generate a unique Id for '" <<
|
|
|
|
path << "'" << std::endl);
|
|
|
|
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
else if(ambiguityCount > 1)
|
|
|
|
{
|
|
|
|
result << "_" << ambiguityCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string resultString = result.str();
|
|
|
|
|
2013-12-20 21:12:01 +04:00
|
|
|
PathToIdMap[path] = resultString;
|
2013-10-11 00:49:33 +04:00
|
|
|
|
|
|
|
return resultString;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::CreateHashedId(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& path, std::string const& normalizedFilename)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
cmsys::auto_ptr<cmCryptoHash> sha1 = cmCryptoHash::New("SHA1");
|
|
|
|
std::string hash = sha1->HashString(path.c_str());
|
|
|
|
|
|
|
|
std::string identifier;
|
|
|
|
identifier += hash.substr(0, 7) + "_";
|
|
|
|
|
|
|
|
const size_t maxFileNameLength = 52;
|
|
|
|
if(normalizedFilename.length() > maxFileNameLength)
|
|
|
|
{
|
|
|
|
identifier += normalizedFilename.substr(0, maxFileNameLength - 3);
|
|
|
|
identifier += "...";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
identifier += normalizedFilename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCPackWIXGenerator::NormalizeComponentForId(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& component, size_t& replacementCount)
|
2013-10-11 00:49:33 +04:00
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
result.resize(component.size());
|
|
|
|
|
|
|
|
for(size_t i = 0; i < component.size(); ++i)
|
|
|
|
{
|
|
|
|
char c = component[i];
|
|
|
|
if(IsLegalIdCharacter(c))
|
|
|
|
{
|
|
|
|
result[i] = c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result[i] = '_';
|
|
|
|
++ replacementCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCPackWIXGenerator::IsLegalIdCharacter(char c)
|
|
|
|
{
|
|
|
|
return (c >= '0' && c <= '9') ||
|
|
|
|
(c >= 'a' && c <= 'z') ||
|
|
|
|
(c >= 'A' && c <= 'Z') ||
|
|
|
|
c == '_' || c == '.';
|
|
|
|
}
|
2013-11-10 22:48:29 +04:00
|
|
|
|
|
|
|
void cmCPackWIXGenerator::CollectExtensions(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& variableName, extension_set_t& extensions)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
|
|
|
const char *variableContent = GetOption(variableName.c_str());
|
|
|
|
if(!variableContent) return;
|
|
|
|
|
|
|
|
std::vector<std::string> list;
|
|
|
|
cmSystemTools::ExpandListArgument(variableContent, list);
|
|
|
|
|
|
|
|
for(std::vector<std::string>::const_iterator i = list.begin();
|
|
|
|
i != list.end(); ++i)
|
|
|
|
{
|
|
|
|
extensions.insert(*i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmCPackWIXGenerator::AddCustomFlags(
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& variableName, std::ostream& stream)
|
2013-11-10 22:48:29 +04:00
|
|
|
{
|
|
|
|
const char *variableContent = GetOption(variableName.c_str());
|
|
|
|
if(!variableContent) return;
|
|
|
|
|
|
|
|
std::vector<std::string> list;
|
|
|
|
cmSystemTools::ExpandListArgument(variableContent, list);
|
|
|
|
|
|
|
|
for(std::vector<std::string>::const_iterator i = list.begin();
|
|
|
|
i != list.end(); ++i)
|
|
|
|
{
|
|
|
|
stream << " " << QuotePath(*i);
|
|
|
|
}
|
|
|
|
}
|